本文整理汇总了PHP中Symfony\Component\Console\Application::getDefinition方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::getDefinition方法的具体用法?PHP Application::getDefinition怎么用?PHP Application::getDefinition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Console\Application
的用法示例。
在下文中一共展示了Application::getDefinition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: mergeApplicationDefinition
/**
* @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;
}
示例2: __construct
/**
* 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);
}
}
示例3: getAllOptions
/**
* 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());
}
示例4: getDefinition
/**
* {@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;
}
示例5: getDefinition
/**
* @inheritDoc
*/
public function getDefinition()
{
$inputDefinition = parent::getDefinition();
// remove command name from arguments
$inputDefinition->setArguments();
return $inputDefinition;
}
示例6: getDefinition
/**
* {@inheritDoc}
*/
public function getDefinition()
{
$inputDefinition = parent::getDefinition();
// clear out the normal first argument, which is the command name
$inputDefinition->setArguments();
return $inputDefinition;
}
示例7: run
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();
}
示例8: register
/**
* 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;
};
}
示例9: getDefinition
/**
* 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;
}
示例10: getDefinition
/**
* @return InputDefinition
*/
public function getDefinition()
{
$inputDefinition = parent::getDefinition();
if (null !== $this->commandName) {
$inputDefinition->setArguments();
}
return $inputDefinition;
}
示例11: initHelper
/**
* @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;
}
示例12: getDefinition
/**
* {@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;
}
示例13: getDefinition
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;
}
}
示例14: setupApplication
/**
* @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;
}]);
}
示例15: describeApplication
/**
* {@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");
}
}