all() public method

The array keys are the full names and the values the command instances.
public all ( string $namespace = null ) : Command[]
$namespace string A namespace name
return Symfony\Component\Console\Command\Command[] An array of Command instances
 /**
  * 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;
 }
Example #2
0
 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();
 }
Example #3
0
 /**
  * @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;
 }
Example #4
0
 /**
  * @param Application $application
  * @param callable|null $annotationFinder
  * @return CronTaskInfo[]
  */
 public function getCronTasks(Application $application, callable $annotationFinder = null)
 {
     if ($annotationFinder === null) {
         $annotationFinder = function (Reader $reader) {
             return $reader->getParameter('crontab');
         };
     }
     $tasks = [];
     foreach ($application->all() as $command) {
         $reader = new Reader(get_class($command));
         $crontabAnnotations = $annotationFinder($reader);
         if (empty($crontabAnnotations)) {
             continue;
         }
         $crontabAnnotations = (array) $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;
 }
 /** @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))));
 }
Example #6
0
 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');
 }
 /**
  * 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;
 }
 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);
     }
 }
Example #9
0
 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;
 }
Example #10
0
 /**
  * {@inheritdoc}
  */
 public function all($namespace = null)
 {
     $this->registerCommands();
     return parent::all($namespace);
 }
 /**
  * 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()));
     }
 }
Example #12
0
<?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());
Example #13
0
 /**
  * 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);
 }
Example #14
0
File: Tg.php Project: twhiston/tg
 /**
  * @return \Symfony\Component\Console\Command\Command[]
  */
 public function getRegisteredCommands()
 {
     return $this->app->all();
 }
 /**
  * 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;
     }
 }