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;
}