本文整理汇总了PHP中Symfony\Component\Console\Application::all方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::all方法的具体用法?PHP Application::all怎么用?PHP Application::all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Console\Application
的用法示例。
在下文中一共展示了Application::all方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getListCommands
/**
* Get list commands to array strings
*
* @return array
*/
protected function getListCommands()
{
$commands = $this->application->all();
$commandsArray = array();
foreach ($commands as $command) {
$commandsArray[] = array('class' => get_class($command), 'name' => $command->getName());
}
return $commandsArray;
}
示例2: run
public function run()
{
if ($this->container->getConfig()->get('app.debug')) {
foreach ($this->app->all() as $commandKey => $command) {
if (method_exists($command, 'isVagrant') && $command->isVagrant()) {
$this->toggleVagrantCommand($commandKey, $command);
}
}
}
$this->app->run();
}
示例3: getCronTasks
/**
* @param Application $application
* @param callback|null $filter
* @return CronTaskInfo[]
*/
public function getCronTasks(Application $application, $filter = null)
{
if ($filter === null) {
$filter = function (Reader $reader) {
return $reader->getParameter('crontab');
};
}
if (!is_callable($filter)) {
throw new \InvalidArgumentException('Invalid filter callback');
}
$tasks = [];
foreach ($application->all() as $command) {
$reader = new \DocBlockReader\Reader(get_class($command));
$crontabAnnotations = $filter($reader);
if (empty($crontabAnnotations)) {
continue;
}
if (!is_array($crontabAnnotations)) {
$crontabAnnotations = [$crontabAnnotations];
}
foreach ($crontabAnnotations as $crontabExpression) {
$commandArguments = preg_split('!\\s+!', $crontabExpression, -1, PREG_SPLIT_NO_EMPTY);
array_splice($commandArguments, 0, 5);
$commandArguments = implode(' ', $commandArguments);
$preparedExpression = trim(str_replace([" /", $commandArguments], [' */', ''], " " . $crontabExpression));
$tasks[] = new CronTaskInfo($preparedExpression, $command, $commandArguments);
}
}
return $tasks;
}
示例4: testDescribeApplication
/** @dataProvider getDescribeApplicationTestData */
public function testDescribeApplication(Application $application, $expectedDescription)
{
// Replaces the dynamic placeholders of the command help text with a static version.
// The placeholder %command.full_name% includes the script path that is not predictable
// and can not be tested against.
foreach ($application->all() as $command) {
$command->setHelp(str_replace('%command.full_name%', 'app/console %command.name%', $command->getHelp()));
}
$this->assertEquals(trim($expectedDescription), trim(str_replace(PHP_EOL, "\n", $this->getDescriptor()->describe($application))));
}
示例5: testAdd
public function testAdd()
{
$application = new Application();
$application->add($foo = new \FooCommand());
$commands = $application->all();
$this->assertEquals($foo, $commands['foo:bar'], '->add() registers a command');
$application = new Application();
$application->addCommands(array($foo = new \FooCommand(), $foo1 = new \Foo1Command()));
$commands = $application->all();
$this->assertEquals(array($foo, $foo1), array($commands['foo:bar'], $commands['foo:bar1']), '->addCommands() registers an array of commands');
}
示例6: completeForCommandName
/**
* Attempt to complete the current word as a command name
*
* @return array|false
*/
protected function completeForCommandName()
{
if (!$this->command || count($this->context->getWords()) == 2 && $this->context->getWordIndex() == 1) {
$commands = $this->application->all();
$names = array_keys($commands);
if ($key = array_search('_completion', $names)) {
unset($names[$key]);
}
return $names;
}
return false;
}
示例7: inspectApplication
private function inspectApplication()
{
$this->commands = array();
$this->namespaces = array();
$all = $this->application->all($this->namespace ? $this->application->findNamespace($this->namespace) : null);
foreach ($this->sortCommands($all) as $namespace => $commands) {
$names = array();
/** @var Command $command */
foreach ($commands as $name => $command) {
if (!$command->getName()) {
continue;
}
if ($command->getName() === $name) {
$this->commands[$name] = $command;
} else {
$this->aliases[$name] = $command;
}
$names[] = $name;
}
$this->namespaces[$namespace] = array('id' => $namespace, 'commands' => $names);
}
}
示例8: all
public function all($namespace = null)
{
$commands = parent::all($namespace);
// Remove hidden command to prevent listing commands by ListCommand
foreach ($commands as $name => $command) {
if (method_exists($command, "getDefinedTask")) {
// Consider the command Altax\Command\Command instance
$definedTask = $command->getDefinedTask();
if ($definedTask->isHidden()) {
unset($commands[$name]);
}
}
}
return $commands;
}
示例9: all
/**
* {@inheritdoc}
*/
public function all($namespace = null)
{
$this->registerCommands();
return parent::all($namespace);
}
示例10: ensureStaticCommandHelp
/**
* Replaces the dynamic placeholders of the command help text with a static version.
* The placeholder %command.full_name% includes the script path that is not predictable
* and can not be tested against.
*/
protected function ensureStaticCommandHelp(Application $application)
{
foreach ($application->all() as $command) {
$command->setHelp(str_replace('%command.full_name%', 'app/console %command.name%', $command->getHelp()));
}
}
示例11: EntityManagerHelper
<?php
$app = (require_once __DIR__ . '/bootstrap.php');
use Doctrine\ORM\Tools\Console\ConsoleRunner;
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Helper\DialogHelper;
use Doctrine\DBAL\Migrations\Tools\Console\Command;
use Doctrine\DBAL\Migrations\Configuration\Configuration;
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
use Symfony\Component\Console\Application as SymfonyApplication;
$helpers['em'] = new EntityManagerHelper($app['orm.em']);
$helpers['dialog'] = new DialogHelper();
$helperSet = new HelperSet($helpers);
$commands = array(new Command\DiffCommand(), new Command\ExecuteCommand(), new Command\GenerateCommand(), new Command\MigrateCommand(), new Command\StatusCommand(), new Command\VersionCommand());
$application = new SymfonyApplication();
$config = new Configuration($app['db']);
$config->setName('Skel Migration');
$config->setMigrationsDirectory(__DIR__ . '/data/DoctrineMigrations');
$config->setMigrationsNamespace('Application\\Migrations');
$config->setMigrationsTableName('migration_version');
foreach ($commands as $command) {
if ($command instanceof Command\AbstractCommand) {
$command->setMigrationConfiguration($config);
}
$application->add($command);
}
ConsoleRunner::run($helperSet, $application->all());
示例12: all
/**
* Autocomplete invokes this method to get the command name completiongs.
* If autocomplete is invoked before a command has been run, then
* we need to initialize the application (and register the commands).
*
* {@inheritDoc}
*/
public function all($namespace = null)
{
$this->init();
return parent::all($namespace);
}
示例13: getRegisteredCommands
/**
* @return \Symfony\Component\Console\Command\Command[]
*/
public function getRegisteredCommands()
{
return $this->app->all();
}
示例14: init
/**
* Initialize manager.
*
* @param Application $application
*/
public function init(Application $application)
{
$this->application = $application;
if ($this->chains) {
$commandMap = array_flip(array_reverse(array_map(function ($command) {
return get_class($command);
}, $application->all())));
$chains = $this->chains;
$members = [];
foreach ($chains as $mainCommand => $hisMembers) {
foreach ($hisMembers as $i => $memberClass) {
if (isset($commandMap[$memberClass])) {
$memberCommand = $commandMap[$memberClass];
$chains[$mainCommand][$i] = $memberCommand;
$members[$memberCommand][] = $mainCommand;
} else {
throw new \InvalidArgumentException(sprintf('Command from class "%s" registered as member of "%s" command, but not enabled or incorrect.', $memberClass, $mainCommand));
}
}
}
$this->chains = $chains;
$this->members = $members;
}
}