protected function register(ContainerInterface $container)
{
$config = $container->make('Kraken\\Config\\ConfigInterface');
$factory = new CommandFactory();
$commands = (array) $config->get('command.models');
foreach ($commands as $commandClass) {
if (!class_exists($commandClass)) {
throw new ResourceUndefinedException("ConsoleCommand [{$commandClass}] does not exist.");
}
$factory->define($commandClass, function ($handler) use($commandClass) {
return new $commandClass($handler);
});
}
$plugins = (array) $config->get('command.plugins');
foreach ($plugins as $pluginClass) {
if (!class_exists($pluginClass)) {
throw new ResourceUndefinedException("FactoryPlugin [{$pluginClass}] does not exist.");
}
$plugin = new $pluginClass();
if (!$plugin instanceof FactoryPluginInterface) {
throw new InvalidArgumentException("FactoryPlugin [{$pluginClass}] does not implement FactoryPluginInterface.");
}
$plugin->registerPlugin($factory);
}
$manager = new CommandManager();
$container->instance('Kraken\\Console\\Client\\Command\\CommandFactoryInterface', $factory);
$container->instance('Kraken\\Console\\Client\\Command\\CommandManagerInterface', $manager);
}