Gets the InputDefinition related to this Application.
public getDefinition ( ) : Symfony\Component\Console\Input\InputDefinition | ||
Résultat | Symfony\Component\Console\Input\InputDefinition | The InputDefinition instance |
/** * @param array $definition * @return array */ private function mergeApplicationDefinition(array $definition) { array_splice($definition, 0, 0, $this->generatorDefinition); if ($this->application) { $appDefinition = $this->application->getDefinition(); array_splice($definition, 0, 0, $appDefinition->getArguments()); array_splice($definition, 0, 0, $appDefinition->getOptions()); } return $definition; }
/** * Constructor. * * @param AbstractApplication $pplication Application to which this console belongs. */ public function __construct(AbstractApplication $application, LoggerInterface $logger = null) { $this->application = $application; $this->logger = $logger; // initialize Symfony Console component $this->consoleApplication = new ConsoleApplication($application->getName() . ' (Splot Console)', $application->getVersion()); $definition = $this->consoleApplication->getDefinition(); $definition->addOption(new InputOption('env', null, InputOption::VALUE_REQUIRED, 'Environment in which to run.')); $definition->addOption(new InputOption('no-debug', null, InputOption::VALUE_NONE, 'Turn off debug mode.')); // now gather all commands from the application foreach ($this->application->getModules() as $module) { $this->readModuleCommands($module); } }
/** * Get the combined options of the application and entered command * * @return InputOption[] */ protected function getAllOptions() { if (!$this->command) { return $this->application->getDefinition()->getOptions(); } return array_merge($this->command->getNativeDefinition()->getOptions(), $this->application->getDefinition()->getOptions()); }
/** * {@inheritdoc} * * Overridden so the application doesn't expect the command name as the first * argument. */ public function getDefinition() { $definition = parent::getDefinition(); // Clears the normal first argument (the command name). $definition->setArguments(); return $definition; }
/** * @inheritDoc */ public function getDefinition() { $inputDefinition = parent::getDefinition(); // remove command name from arguments $inputDefinition->setArguments(); return $inputDefinition; }
/** * {@inheritDoc} */ public function getDefinition() { $inputDefinition = parent::getDefinition(); // clear out the normal first argument, which is the command name $inputDefinition->setArguments(); return $inputDefinition; }
public static function run() { // Create the instance $app = new ConsoleApp(); $app->setName(self::NAME); $app->setVersion(self::VERSION); // Remove default options. We only keep help & version. $options = $app->getDefinition()->getOptions(); $options = [$options['version'], $options['help']]; $app->getDefinition()->setOptions($options); // TODO: Use a more comfortable way to handle included commands (configuration file / autoload / whatever) // Add some commands $app->add(new Main()); // Lets go... $app->run(); }
/** * Registers services on the given container. * * This method should only be used to configure services and parameters. * It should not get services. * * @param \Pimple\Container $container A container instance */ public function register(Container $container) { $container['console.name'] = 'Console'; $container['console.version'] = '1.0'; $container['console.event_dispatcher'] = null; $container['console.enable_xdebug'] = false; $container['console'] = function (Container $container) { $console = new ConsoleApplication($container['console.name'], $container['console.version']); if ($container['console.enable_xdebug'] && function_exists('xdebug_enable')) { $definition = $console->getDefinition(); $definition->addOption(new InputOption('debug', null, InputOption::VALUE_NONE, 'Enable XDebug jit remote mode')); $console->setDefinition($definition); foreach ($_SERVER['argv'] as $arg) { if ('--debug' === $arg) { poke_xdebug(); break; } elseif ('--' === $arg) { break; } } } $dispatcher = $container['console.event_dispatcher']; if (is_string($dispatcher)) { $dispatcher = $container[$dispatcher]; } if ($dispatcher instanceof EventDispatcherInterface) { $console->setDispatcher($dispatcher); $dispatcher->dispatch(Events::INIT, new InitializeConsoleEvent($console)); } return $console; }; }
/** * Surchargé afin que l'application accepte que le premier argument ne * soit pas le nom. */ public function getDefinition() { $inputDefinition = parent::getDefinition(); // efface le premier argument, qui est le nom de la commande $inputDefinition->setArguments(); return $inputDefinition; }
/** * @return InputDefinition */ public function getDefinition() { $inputDefinition = parent::getDefinition(); if (null !== $this->commandName) { $inputDefinition->setArguments(); } return $inputDefinition; }
/** * @param Application $application * @param mixed $default * @param array $options * @return ConfigurationHelper */ public static function initHelper(Application $application, $default = null, array $options = []) { $options = $options + ['name' => 'config', 'abbreviation' => 'c', 'description' => 'Path to the configuration file.', 'filename' => 'cli-config.php']; $helper = new static($options['name'], $options['filename']); $helper->setDefault($default); $application->getDefinition()->addOption(new InputOption($options['name'], $options['abbreviation'], InputOption::VALUE_REQUIRED, $options['description'])); $application->getHelperSet()->set($helper); return $helper; }
/** * {@inheritdoc} */ public function getDefinition() { $inputDefinition = parent::getDefinition(); $inputDefinition->setArguments(); $inputDefinition->addOption(new InputOption('config', 'c', InputOption::VALUE_REQUIRED, 'Path to the configuration file')); $inputDefinition->addOption(new InputOption('log', 'l', InputOption::VALUE_REQUIRED, 'Log into a file')); $inputDefinition->addOption(new InputOption('log-level', 'L', InputOption::VALUE_REQUIRED, 'The log level (emergency, alert, critical, error, warning, notice, info, debug)', 'info')); return $inputDefinition; }
public function getDefinition() { if (method_exists('Symfony\\Component\\Console\\Application', 'getDefaultCommands')) { return parent::getDefinition(); } else { // For compatibility with Symfony 2.0 static $definition; if (is_null($definition)) { $definition = $this->getDefaultInputDefinition(); } return $definition; } }
/** * @param Container $container */ private function setupApplication(Container $container) { $this->addMany($container, ['application.ucd' => function (Container $container) { $application = new Application('Unicode Character Database', PHPUCD_VERSION); $application->add($container['command.repository_transfer']); $application->add($container['command.search']); $application->add($container['command.props']); $definition = $application->getDefinition(); $option = new InputOption('config', 'c', InputOption::VALUE_OPTIONAL, 'Configuration file', null); $definition->addOption($option); return $application; }]); }
/** * {@inheritdoc} */ protected function describeApplication(Application $application, array $options = []) { $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null; $description = new ApplicationDescription($application, $describedNamespace); if (isset($options['raw_text']) && $options['raw_text']) { $width = $this->getColumnWidth($description->getCommands()); foreach ($description->getCommands() as $command) { $this->writeText(sprintf("%-{$width}s %s", $command->getName(), $command->getDescription()), $options); $this->writeText("\n"); } } else { if ('' != ($help = $application->getHelp())) { $this->writeText("{$help}\n\n", $options); } $this->writeText("<comment>Usage:</comment>\n", $options); $this->writeText(" command [options] [arguments]\n\n", $options); $this->describeInputDefinition(new InputDefinition($application->getDefinition()->getOptions()), $options); $this->writeText("\n"); $this->writeText("\n"); $width = $this->getColumnWidth($description->getCommands()); if ($describedNamespace) { $this->writeText(sprintf('<comment>Available commands for the "%s" namespace:</comment>', $describedNamespace), $options); } else { $this->writeText('<comment>Available commands:</comment>', $options); } // add commands by namespace foreach ($description->getNamespaces() as $namespace) { if ($this->shouldListCommand($namespace['id']) === false) { continue; } if (!$describedNamespace && ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) { $this->writeText("\n"); $this->writeText(' <comment>' . $namespace['id'] . '</comment>', $options); } foreach ($namespace['commands'] as $name) { if ($this->shouldListCommand($namespace['id'], $name) === false) { continue; } $this->writeText("\n"); $spacingWidth = $width - strlen($name); $this->writeText(sprintf(' <info>%s</info>%s%s', $name, str_repeat(' ', $spacingWidth), $description->getCommand($name)->getDescription()), $options); } } $this->writeText("\n"); } }
/** * {@inheritdoc} */ protected function describeApplication(Application $application, array $options = array()) { $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null; $description = new ApplicationDescription($application, $describedNamespace); if (isset($options['raw_text']) && $options['raw_text']) { $width = $this->getColumnWidth($description->getCommands()); foreach ($description->getCommands() as $command) { $this->writeText(sprintf("%-{$width}s %s", $command->getName(), $command->getDescription()), $options); $this->writeText("\n"); } } else { if ('' != ($help = $application->getHelp())) { $this->writeText("{$help}\n\n", $options); } $this->describeInputDefinition(new InputDefinition($application->getDefinition()->getOptions()), $options); $this->writeText("\n"); $this->writeText("\n"); $width = $this->getColumnWidth($description->getCommands()); if ($describedNamespace) { $this->writeText(sprintf('<comment>Available commands for the "%s" namespace:</comment>', $describedNamespace), $options); } else { $this->writeText('<comment>Available commands:</comment>', $options); } // add commands by namespace foreach ($description->getNamespaces() as $namespace) { if (!$describedNamespace && ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) { $this->writeText("\n"); $this->writeText(' <comment>' . $namespace['id'] . '</comment>', $options); } foreach ($namespace['commands'] as $name) { $command = $description->getCommand($name); $aliases = $command->getAliases(); if ($aliases && in_array($name, $aliases)) { // skip aliases continue; } $this->writeText("\n"); $this->writeText(sprintf(" %-{$width}s %s", "<info>{$name}</info>" . $this->formatAliases($aliases), $command->getDescription()), $options); } } $this->writeText("\n"); } }
public function testSettingCustomInputDefinitionOverwritesDefaultValues() { $application = new Application(); $application->setAutoExit(false); $application->setCatchExceptions(false); $application->setDefinition(new InputDefinition(array(new InputOption('--custom', '-c', InputOption::VALUE_NONE, 'Set the custom input definition.')))); $inputDefinition = $application->getDefinition(); // check whether the default arguments and options are not returned any more $this->assertFalse($inputDefinition->hasArgument('command')); $this->assertFalse($inputDefinition->hasOption('help')); $this->assertFalse($inputDefinition->hasOption('quiet')); $this->assertFalse($inputDefinition->hasOption('verbose')); $this->assertFalse($inputDefinition->hasOption('version')); $this->assertFalse($inputDefinition->hasOption('ansi')); $this->assertFalse($inputDefinition->hasOption('no-ansi')); $this->assertFalse($inputDefinition->hasOption('no-interaction')); $this->assertTrue($inputDefinition->hasOption('custom')); }
/** * Overridden so that the application doesn't expect the command * name to be the first argument. */ public function getDefinition() { $inputDefinition = parent::getDefinition(); $inputDefinition->setArguments(); return $inputDefinition; }
public function testMergeApplicationDefinitionWithoutArgsThenWithArgsAddsArgs() { $application1 = new Application(); $application1->getDefinition()->addArguments(array(new InputArgument('foo'))); $application1->getDefinition()->addOptions(array(new InputOption('bar'))); $command = new \TestCommand(); $command->setApplication($application1); $command->setDefinition($definition = new InputDefinition(array())); $r = new \ReflectionObject($command); $m = $r->getMethod('mergeApplicationDefinition'); $m->setAccessible(true); $m->invoke($command, false); $this->assertTrue($command->getDefinition()->hasOption('bar'), '->mergeApplicationDefinition(false) merges the application and the commmand options'); $this->assertFalse($command->getDefinition()->hasArgument('foo'), '->mergeApplicationDefinition(false) does not merge the application arguments'); $m->invoke($command, true); $this->assertTrue($command->getDefinition()->hasArgument('foo'), '->mergeApplicationDefinition(true) merges the application arguments and the command arguments'); $m->invoke($command); $this->assertEquals(2, $command->getDefinition()->getArgumentCount(), '->mergeApplicationDefinition() does not try to merge twice the application arguments'); }
public function getDefinition() { $inputDefinition = parent::getDefinition(); $inputDefinition->addOptions([new InputOption('--config', '-c', InputOption::VALUE_OPTIONAL, 'Loopback PHP Generator Config YML File', self::DEFAULT_CONFIG)]); return $inputDefinition; }
public function getDefinition() { $inputDefinition = AbstractApplication::getDefinition(); $inputDefinition->setArguments(); return $inputDefinition; }
/** * Gets the InputDefinition related to this Application. * * @return InputDefinition The InputDefinition instance */ public function getDefinition() { $inputDefinition = parent::getDefinition(); return $inputDefinition; }
<?php use Symfony\Component\Console\Application; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; $console = new Application('Artsper Backoffice', 'n/a'); $console->getDefinition()->addOption(new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', 'dev')); $console->setDispatcher($app['dispatcher']); $console->register('my-command')->setDefinition(array())->setDescription('My command description')->setCode(function (InputInterface $input, OutputInterface $output) use($app) { // do something }); return $console;
/** * {@inheritdoc} */ protected function describeApplication(Application $application, array $options = array()) { $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null; $description = new ApplicationDescription($application, $describedNamespace); if (isset($options['raw_text']) && $options['raw_text']) { $width = $this->getColumnWidth($description->getCommands()); foreach ($description->getCommands() as $command) { $this->writeText(sprintf("%-{$width}s %s", $command->getName(), $command->getDescription()), $options); $this->writeText("\n"); } } else { if ('' != ($help = $application->getHelp())) { $this->writeText("{$help}\n\n", $options); } $this->writeText($application->trans('commands.list.messages.usage'), $options); $this->writeText($application->trans('commands.list.messages.usage_details'), $options); $options['application'] = $application; $this->describeInputDefinition(new InputDefinition($application->getDefinition()->getOptions()), $options); $this->writeText("\n"); $this->writeText("\n"); $width = $this->getColumnWidth($description->getCommands()); if ($describedNamespace) { $this->writeText(sprintf($application->trans('commands.list.messages.comment'), $describedNamespace), $options); } else { $this->writeText($application->trans('commands.list.messages.available-commands'), $options); } // add commands by namespace foreach ($description->getNamespaces() as $namespace) { if (!$describedNamespace && ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) { $this->writeText("\n"); $this->writeText(' <comment>' . $namespace['id'] . '</comment>', $options); } foreach ($namespace['commands'] as $name) { $this->writeText("\n"); $spacingWidth = $width - strlen($name); $this->writeText(sprintf(' <info>%s</info>%s%s', $name, str_repeat(' ', $spacingWidth), $description->getCommand($name)->getDescription()), $options); } } $this->writeText("\n"); } }
<?php use Symfony\Component\Console\Application; use Symfony\Component\Console\Input\InputOption; use Doctrine\ORM\Tools\Console\ConsoleRunner; $console = new Application('Kinetise Api Skeleton', '0.1 beta'); $console->getDefinition()->addOption(new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', APP_ENV)); $console->getDefinition()->addOption(new InputOption('--debug', '-d', InputOption::VALUE_REQUIRED, 'The Environment name.', APP_DEBUG)); $console->setHelperSet(ConsoleRunner::createHelperSet($app['orm.em'])); $console->setDispatcher($app['dispatcher']); $console->addCommands(array(new \Doctrine\DBAL\Tools\Console\Command\RunSqlCommand(), new \Doctrine\DBAL\Tools\Console\Command\ImportCommand(), new \Doctrine\ORM\Tools\Console\Command\ClearCache\MetadataCommand(), new \Doctrine\ORM\Tools\Console\Command\ClearCache\ResultCommand(), new \Doctrine\ORM\Tools\Console\Command\ClearCache\QueryCommand(), new \Doctrine\ORM\Tools\Console\Command\SchemaTool\CreateCommand(), new \Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand(), new \Doctrine\ORM\Tools\Console\Command\SchemaTool\DropCommand(), new \Doctrine\ORM\Tools\Console\Command\EnsureProductionSettingsCommand(), new \Doctrine\ORM\Tools\Console\Command\ConvertDoctrine1SchemaCommand(), new \Doctrine\ORM\Tools\Console\Command\GenerateRepositoriesCommand(), new \Doctrine\ORM\Tools\Console\Command\GenerateEntitiesCommand(), new \Doctrine\ORM\Tools\Console\Command\GenerateProxiesCommand(), new \Doctrine\ORM\Tools\Console\Command\ConvertMappingCommand(), new \Doctrine\ORM\Tools\Console\Command\RunDqlCommand(), new \Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand(), new \Doctrine\ORM\Tools\Console\Command\InfoCommand(), new \Doctrine\ORM\Tools\Console\Command\MappingDescribeCommand())); return $console;
/** * {@inheritdoc} */ protected function describeApplication(Application $application, array $options = array()) { $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null; $description = new ApplicationDescription($application, $describedNamespace); if (isset($options['raw_text']) && $options['raw_text']) { $width = $this->getColumnWidth($description->getCommands()); foreach ($description->getCommands() as $command) { $this->writeText(sprintf("%-{$width}s %s", $command->getName(), $command->getDescription()), $options); $this->writeText("\n"); } } else { if ('' != ($help = $application->getHelp())) { $this->writeText("{$help}\n\n", $options); } $this->writeText("<comment>Usage:</comment>\n", $options); $this->writeText(" [options] command [arguments]\n\n", $options); $this->writeText('<comment>Options:</comment>', $options); $inputOptions = $application->getDefinition()->getOptions(); $width = 0; foreach ($inputOptions as $option) { $nameLength = strlen($option->getName()) + 2; if ($option->getShortcut()) { $nameLength += strlen($option->getShortcut()) + 3; } $width = max($width, $nameLength); } ++$width; foreach ($inputOptions as $option) { $this->writeText("\n", $options); $this->describeInputOption($option, array_merge($options, array('name_width' => $width))); } $this->writeText("\n\n", $options); $width = $this->getColumnWidth($description->getCommands()); if ($describedNamespace) { $this->writeText(sprintf("<comment>Available commands for the \"%s\" namespace:</comment>", $describedNamespace), $options); } else { $this->writeText('<comment>Available commands:</comment>', $options); } // add commands by namespace foreach ($description->getNamespaces() as $namespace) { if (!$describedNamespace && ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) { $this->writeText("\n"); $this->writeText('<comment>' . $namespace['id'] . '</comment>', $options); } foreach ($namespace['commands'] as $name) { $this->writeText("\n"); $this->writeText(sprintf(" <info>%-{$width}s</info> %s", $name, $description->getCommand($name)->getDescription()), $options); } } $this->writeText("\n"); } }
public function getDefinition() { $def = parent::getDefinition(); $def->setArguments(); return $def; }
/** * Replaces the default InputDefinition with one containing only the 'command' argument. * {@inheritdoc} */ public function getDefinition() { $inputDefinition = parent::getDefinition(); $inputDefinition->setArguments([new InputArgument('command', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'The input command')]); return $inputDefinition; }
public function testMergeApplicationDefinition() { $application1 = new Application(); $application1->getDefinition()->addArguments(array(new InputArgument('foo'))); $application1->getDefinition()->addOptions(array(new InputOption('bar'))); $command = new \TestCommand(); $command->setApplication($application1); $command->setDefinition($definition = new InputDefinition(array(new InputArgument('bar'), new InputOption('foo')))); $command->mergeApplicationDefinition(); $this->assertTrue($command->getDefinition()->hasArgument('foo'), '->mergeApplicationDefinition() merges the application arguments and the command arguments'); $this->assertTrue($command->getDefinition()->hasArgument('bar'), '->mergeApplicationDefinition() merges the application arguments and the command arguments'); $this->assertTrue($command->getDefinition()->hasOption('foo'), '->mergeApplicationDefinition() merges the application options and the command options'); $this->assertTrue($command->getDefinition()->hasOption('bar'), '->mergeApplicationDefinition() merges the application options and the command options'); $command->mergeApplicationDefinition(); $this->assertEquals(3, $command->getDefinition()->getArgumentCount(), '->mergeApplicationDefinition() does not try to merge twice the application arguments and options'); $command = new \TestCommand(); $command->mergeApplicationDefinition(); }
public function testGetDefaultInputDefinitionReturnsDefaultValues() { $application = new Application(); $application->setAutoExit(false); $application->setCatchExceptions(false); $inputDefinition = $application->getDefinition(); $this->assertTrue($inputDefinition->hasArgument('command')); $this->assertTrue($inputDefinition->hasOption('help')); $this->assertTrue($inputDefinition->hasOption('quiet')); $this->assertTrue($inputDefinition->hasOption('verbose')); $this->assertTrue($inputDefinition->hasOption('version')); $this->assertTrue($inputDefinition->hasOption('ansi')); $this->assertTrue($inputDefinition->hasOption('no-ansi')); $this->assertTrue($inputDefinition->hasOption('no-interaction')); }