Allows you to add a command as Command object or as a command name+callable
public command ( string | |
||
$nameOrCommand | string | |
|
$callable | callable | null | Must be a callable if $nameOrCommand is the command's name |
Результат | The command instance that you can further configure |
/** * Tests the command method to see if the command is properly set and the * Cilex application is added as container. */ public function testCommand() { $this->assertFalse($this->fixture['console']->has('demo:greet')); $this->fixture->command(new \Cilex\Command\GreetCommand()); $this->assertTrue($this->fixture['console']->has('demo:greet')); $this->assertSame($this->fixture, $this->fixture['console']->get('demo:greet')->getContainer()); }
/** * Initialize */ private function _initialize() { $wildcardPath = implode(DIRECTORY_SEPARATOR, [$this->app['config']->getProjectPath(), 'application/cli', '*Command.php']); foreach (new \GlobIterator($wildcardPath, \GlobIterator::CURRENT_AS_FILEINFO) as $fileInfo) { /** @var \SplFileInfo $fileInfo */ if (preg_match('/^(?<command>[a-zA-Z]+Command).php$/', $fileInfo->getFilename(), $match)) { $command_namespace = $this->config['namespace'] . $match['command']; $this->app->command(new $command_namespace()); } } }
/** * Registers services on the given app. * * @param Application $app An Application instance */ public function register(Application $app) { if (!isset($app['descriptor.builder'])) { throw new Exception\MissingDependencyException('The builder object that is used to construct the ProjectDescriptor is missing'); } if (!isset($app['serializer'])) { throw new Exception\MissingDependencyException('The serializer object that is used to read the template configuration with is missing'); } $templateDir = __DIR__ . '/../../../data/templates'; // vendored installation if (file_exists(__DIR__ . '/../../../../templates')) { $templateDir = __DIR__ . '/../../../../templates'; } // parameters $app['transformer.template.location'] = $templateDir; $app['linker.substitutions'] = array('phpDocumentor\\Descriptor\\ProjectDescriptor' => array('files'), 'phpDocumentor\\Descriptor\\FileDescriptor' => array('tags', 'classes', 'interfaces', 'traits'), 'phpDocumentor\\Descriptor\\ClassDescriptor' => array('tags', 'parent', 'interfaces', 'constants', 'properties', 'methods'), 'phpDocumentor\\Descriptor\\InterfaceDescriptor' => array('tags', 'parent', 'constants', 'methods'), 'phpDocumentor\\Descriptor\\TraitDescriptor' => array('tags', 'properties', 'methods'), 'phpDocumentor\\Descriptor\\MethodDescriptor' => array('tags', 'arguments'), 'phpDocumentor\\Descriptor\\ArgumentDescriptor' => array('types'), 'phpDocumentor\\Descriptor\\PropertyDescriptor' => array('tags', 'types'), 'phpDocumentor\\Descriptor\\ConstantDescriptor' => array('tags', 'types'), 'phpDocumentor\\Descriptor\\Tag\\ParamDescriptor' => array('types'), 'phpDocumentor\\Descriptor\\Tag\\ReturnDescriptor' => array('types'), 'phpDocumentor\\Descriptor\\Tag\\SeeDescriptor' => array('reference')); // services $app['compiler'] = $app->share(function ($container) { $compiler = new Compiler(); $compiler->insert(new ElementsIndexBuilder(), ElementsIndexBuilder::COMPILER_PRIORITY); $compiler->insert(new PackageTreeBuilder(), PackageTreeBuilder::COMPILER_PRIORITY); $compiler->insert(new NamespaceTreeBuilder(), NamespaceTreeBuilder::COMPILER_PRIORITY); $compiler->insert($container['linker'], Linker::COMPILER_PRIORITY); $compiler->insert($container['transformer'], Transformer::COMPILER_PRIORITY); $compiler->insert(new Debug($container['monolog'], $container['descriptor.analyzer']), Debug::COMPILER_PRIORITY); return $compiler; }); $app['linker'] = $app->share(function ($app) { return new Linker($app['linker.substitutions']); }); $app['transformer.behaviour.collection'] = $app->share(function () { return new Behaviour\Collection(); }); $app['transformer.routing.queue'] = $app->share(function () { $queue = new Router\Queue(); // TODO: load from app configuration instead of hardcoded $queue->insert(new Router\StandardRouter(), 10000); return $queue; }); $app['transformer.writer.collection'] = $app->share(function ($container) { return new Writer\Collection($container['transformer.routing.queue']); }); $app['transformer.template.collection'] = $app->share(function ($container) { return new Template\Collection($container['transformer.template.location'], $container['serializer']); }); $app['transformer'] = $app->share(function ($container) { $transformer = new Transformer($container['transformer.template.collection'], $container['transformer.writer.collection']); $transformer->setBehaviours($container['transformer.behaviour.collection']); return $transformer; }); $app->command(new TransformCommand($app['descriptor.builder'], $app['transformer'], $app['compiler'])); $app->command(new ListCommand()); }
/** * Method responsible for adding the commands for this application. * * @param Application $app * * @return void */ protected function addCommands(Application $app) { $app->command(new Command\Manual\ToHtmlCommand(null, $app[self::TEMPLATE_FACTORY], $app[self::CONVERTER_FACTORY])); // FIXME: Disabled the ToLatex and ToPdf commands for now to prevent confusion of users. // $this->command(new \phpDocumentor\Plugin\Scrybe\Command\Manual\ToLatexCommand()); // $this->command(new \phpDocumentor\Plugin\Scrybe\Command\Manual\ToPdfCommand()); }
/** * Registers services on the given app. * * @param Application $app An Application instance * * @throws Exception\MissingDependencyException if the Descriptor Builder is not present. * * @return void */ public function register(Application $app) { if (!isset($app['descriptor.builder'])) { throw new Exception\MissingDependencyException('The builder object that is used to construct the ProjectDescriptor is missing'); } $app['parser'] = $app->share(function () { return new Parser(); }); /** @var Translator $translator */ $translator = $app['translator']; $translator->addTranslationFolder(__DIR__ . DIRECTORY_SEPARATOR . 'Messages'); $app->command(new ParseCommand($app['descriptor.builder'], $app['parser'], $translator)); /** @var Dispatcher $dispatcher */ $dispatcher = $app['event_dispatcher']; $dispatcher->addListener('reflection.docblock-extraction.post', array($this, 'validateDocBlocks')); }
/** * Registers services on the given app. * * @param Application $app An Application instance * * @throws Exception\MissingDependencyException if the Descriptor Builder is not present. * * @return void */ public function register(Application $app) { if (!isset($app['descriptor.builder'])) { throw new Exception\MissingDependencyException('The builder object that is used to construct the ProjectDescriptor is missing'); } $app['parser'] = $app->share(function ($app) { $parser = new Parser(); $parser->setStopwatch($app['kernel.stopwatch']); $parser->setLogger($app['monolog']); return $parser; }); $app['markdown'] = $app->share(function () { return \Parsedown::instance(); }); /** @var Translator $translator */ $translator = $app['translator']; $translator->addTranslationFolder(__DIR__ . DIRECTORY_SEPARATOR . 'Messages'); $app['parser.files'] = new Collection(); $app->command(new ParseCommand($app['descriptor.builder'], $app['parser'], $translator, $app['parser.files'])); }
/** * Tests whether the getService method correctly retrieves an element from * the container. */ public function testGetService() { $app = new Application('Test'); $app->command($this->fixture); $this->assertInstanceOf('Symfony\\Component\\Console\\Application', $this->fixture->getService('console')); }
#!/usr/bin/env php <?php if (!($bootstrap = (require_once __DIR__ . '/bootstrap.php'))) { die('You must set up the project dependencies.'); } use Cilex\Application; use NewsToChat\Command\Maintenance; use NewsToChat\Command\PushNews; use NewsToChat\Command\PullNews; $runtime = new DateTime(); $runtime = $runtime->format('Y-m-d @ H:i:s'); $settings = parse_ini_file(__DIR__ . '/config/settings.ini', true); $name = $settings['global']['name']; $sources = $settings['sources']; $token = $settings['global']['token']; $version = $settings['global']['version']; $app = new Application($name, $version); $app->command(new Maintenance($entityManager, $runtime)); $app->command(new PullNews($entityManager, $runtime, $sources)); $app->command(new PushNews($entityManager, $runtime, $token)); $app->run();