Airship\Engine\Gears::attach PHP Method

attach() public static method

Attach a plugin to overload the base class
public static attach ( string $index, string $new_type, string $namespace = '' ) : boolean
$index string Index
$new_type string New type
$namespace string Namespace
return boolean
    public static function attach(string $index, string $new_type, string $namespace = '') : bool
    {
        $state = State::instance();
        $gears = $state->gears;
        $type = empty($namespace) ? $new_type : $namespace . '\\' . $new_type;
        if (!\class_exists($type)) {
            throw new GearNotFound($new_type);
        }
        if (!isset($gears[$index])) {
            throw new GearNotFound($index);
        }
        $reflector = new \ReflectionClass($type);
        if (!$reflector->isSubclassOf($gears[$index])) {
            throw new GearWrongType(\__('%s does not inherit from %s', 'default', $type, $gears[$index]));
        }
        $gears[$index] = $type;
        $state->gears = $gears;
        return true;
    }