/** * @param ContainerInterface $container * @throws Exception */ 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); }
/** * */ public function testCaseFactory_PossesAllDefinitions() { $factory = new CommandFactory(); $commands = ['ArchStartCommand' => 'Kraken\\Console\\Client\\Command\\Arch\\ArchStartCommand', 'ArchStopCommand' => 'Kraken\\Console\\Client\\Command\\Arch\\ArchStopCommand', 'ArchStatusCommand' => 'Kraken\\Console\\Client\\Command\\Arch\\ArchStatusCommand', 'ProjectCreateCommand' => 'Kraken\\Console\\Client\\Command\\Project\\ProjectCreateCommand', 'ProjectDestroyCommand' => 'Kraken\\Console\\Client\\Command\\Project\\ProjectDestroyCommand', 'ProjectStartCommand' => 'Kraken\\Console\\Client\\Command\\Project\\ProjectStartCommand', 'ProjectStopCommand' => 'Kraken\\Console\\Client\\Command\\Project\\ProjectStopCommand', 'ProjectStatusCommand' => 'Kraken\\Console\\Client\\Command\\Project\\ProjectStatusCommand', 'ProcessExistsCommand' => 'Kraken\\Console\\Client\\Command\\Process\\ProcessExistsCommand', 'ProcessCreateCommand' => 'Kraken\\Console\\Client\\Command\\Process\\ProcessCreateCommand', 'ProcessDestroyCommand' => 'Kraken\\Console\\Client\\Command\\Process\\ProcessDestroyCommand', 'ProcessStartCommand' => 'Kraken\\Console\\Client\\Command\\Process\\ProcessStartCommand', 'ProcessStopCommand' => 'Kraken\\Console\\Client\\Command\\Process\\ProcessStopCommand', 'ThreadExistsCommand' => 'Kraken\\Console\\Client\\Command\\Thread\\ThreadExistsCommand', 'ThreadCreateCommand' => 'Kraken\\Console\\Client\\Command\\Thread\\ThreadCreateCommand', 'ThreadDestroyCommand' => 'Kraken\\Console\\Client\\Command\\Thread\\ThreadDestroyCommand', 'ThreadStartCommand' => 'Kraken\\Console\\Client\\Command\\Thread\\ThreadStartCommand', 'ThreadStopCommand' => 'Kraken\\Console\\Client\\Command\\Thread\\ThreadStopCommand', 'RuntimeExistsCommand' => 'Kraken\\Console\\Client\\Command\\Runtime\\RuntimeExistsCommand', 'RuntimeDestroyCommand' => 'Kraken\\Console\\Client\\Command\\Runtime\\RuntimeDestroyCommand', 'RuntimeStartCommand' => 'Kraken\\Console\\Client\\Command\\Runtime\\RuntimeStartCommand', 'RuntimeStopCommand' => 'Kraken\\Console\\Client\\Command\\Runtime\\RuntimeStopCommand', 'ContainerDestroyCommand' => 'Kraken\\Console\\Client\\Command\\Container\\ContainerDestroyCommand', 'ContainerStartCommand' => 'Kraken\\Console\\Client\\Command\\Container\\ContainerStartCommand', 'ContainerStopCommand' => 'Kraken\\Console\\Client\\Command\\Container\\ContainerStopCommand', 'ContainerStatusCommand' => 'Kraken\\Console\\Client\\Command\\Container\\ContainerStatusCommand']; foreach ($commands as $alias => $class) { $this->assertTrue($factory->hasDefinition($alias)); $this->assertTrue($factory->hasDefinition($class)); } }