add() public method

If a command with the same name already exists, it will be overridden. If the command is not enabled it will not be added.
public add ( Command $command ) : Command | null
$command Symfony\Component\Console\Command\Command A Command object
return Symfony\Component\Console\Command\Command | null The registered command if enabled or null
Exemplo n.º 1
1
 /**
  * {@inheritdoc}
  */
 public function execute(ContainerInterface $app)
 {
     foreach ($this->commands as $command) {
         $this->console->add($app->create($command));
     }
     $this->console->run();
 }
Exemplo n.º 2
0
 public function setUp()
 {
     $config = new DummyConfig();
     $this->application = new Application();
     $this->application->add(new CliTaskCommand());
     $this->execDir = getcwd() . "/vendor/opencart";
 }
 protected function setUp()
 {
     $this->application = new Application();
     $this->application->add(new CalculatePomodorosCommand());
     $this->command = $this->application->find('pomodoro:calculate');
     $this->commandTester = new CommandTester($this->command);
 }
Exemplo n.º 4
0
 public function newApplication()
 {
     $application = new Application('WikibaseEntityStore');
     $application->add(new ImportJsonDumpCommand());
     $application->add(new ImportIncrementalXmlDumpCommand());
     return $application;
 }
 /**
  * @param ContainerInterface $container
  * @param string $requestedName
  * @param array $options, optional
  *
  * @return Application
  */
 public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
 {
     $cliApplication = new Application('AsseticBundle', '1.7.0');
     $cliApplication->add(new BuildCommand($container->get('AsseticService')));
     $cliApplication->add(new SetupCommand($container->get('AsseticService')));
     return $cliApplication;
 }
Exemplo n.º 6
0
 public function load(Application $application)
 {
     $in = $this->container->getParameter('seed.directory');
     //add seed:load and seed:unload commands
     $application->add($this->container->get('seed.load_seeds_command'));
     $application->add($this->container->get('seed.unload_seeds_command'));
     //Go through bundles and add *Seeds available in seed.directory
     foreach ($application->getKernel()->getBundles() as $bundle) {
         if (!is_dir($dir = sprintf('%s/%s', $bundle->getPath(), $in))) {
             continue;
         }
         $finder = new Finder();
         $finder->files()->name('*Seed.php')->in($dir);
         $prefix = $bundle->getNameSpace() . '\\' . strtr($in, '/', '\\');
         foreach ($finder as $file) {
             $ns = $prefix;
             if ($relativePath = $file->getRelativePath()) {
                 $ns .= '\\' . strtr($relativePath, '/', '\\');
             }
             $class = $ns . '\\' . $file->getBasename('.php');
             $alias = 'seed.command.' . strtolower(str_replace('\\', '_', $class));
             if ($this->container->has($alias)) {
                 continue;
             }
             $r = new \ReflectionClass($class);
             if ($r->isSubclassOf('Soyuka\\SeedBundle\\Command\\Seed') && !$r->isAbstract() && ($r->hasMethod('load') || $r->hasMethod('unload'))) {
                 $application->add($r->newInstanceArgs([$this->prefix, $this->separator]));
             }
         }
     }
 }
 protected function getCommandTester()
 {
     $this->application->add($this->command);
     $command = $this->application->find('phpci:create-build');
     $commandTester = new CommandTester($command);
     return $commandTester;
 }
Exemplo n.º 8
0
 public function add(Command $command, $namespace = '')
 {
     if (strlen($namespace)) {
         $command->setName($namespace . ':' . $command->getName());
     }
     $this->app->add($command);
 }
 /**
  * Instantiate and adds the console commands to 
  * the console application
  * 
  * @return $this
  */
 protected function setupConsoleCommands()
 {
     foreach ($this->commandClasses() as $class) {
         $this->consoleApplication->add(new $class());
     }
     return $this;
 }
 protected function setUp()
 {
     $tempFile = tempnam(sys_get_temp_dir(), 'sonata_');
     if (file_exists($tempFile)) {
         unlink($tempFile);
     }
     if (mkdir($tempFile)) {
         $this->tempDirectory = $tempFile;
         file_put_contents($this->tempDirectory . '/classes.map', '<?php return array(\'Sonata\\AdminBundle\\Tests\\Fixtures\\Controller\\FooAdminController\', \'Sonata\\AdminBundle\\Tests\\Fixtures\\Controller\\BarAdminController\',);');
     } else {
         $this->markTestSkipped(sprintf('Temp directory "%s" creation error.', $tempFile));
     }
     $this->application = new Application();
     $command = new CreateClassCacheCommand();
     $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
     $kernel = $this->getMock('Symfony\\Component\\HttpKernel\\KernelInterface');
     $kernel->expects($this->any())->method('getCacheDir')->will($this->returnValue($this->tempDirectory));
     $kernel->expects($this->any())->method('isDebug')->will($this->returnValue(false));
     $container->expects($this->any())->method('get')->will($this->returnCallback(function ($id) use($kernel) {
         if ($id == 'kernel') {
             return $kernel;
         }
         return;
     }));
     $command->setContainer($container);
     $this->application->add($command);
 }
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     $controller = $this->createMock(ControllerInterface::class);
     $scheduler = $this->createMock(SchedulerInterface::class);
     $registry = new IteratorRegistry();
     $this->container = $this->createMock(ContainerInterface::class);
     $this->container->expects($this->any())->method('get')->will($this->returnCallback(function ($key) use($scheduler, $registry, $controller) {
         if ($key == 'abc.scheduler.scheduler') {
             return $scheduler;
         } elseif ($key == 'abc.scheduler.iterator_registry') {
             return $registry;
         } elseif ($key == 'abc.process_control.controller') {
             return $controller;
         }
     }));
     $controller->expects($this->any())->method('doStop')->willReturn(false);
     $command = new SchedulerProcessCommand();
     $command->setContainer($this->container);
     $kernel = $this->createMock(KernelInterface::class);
     $this->application = new Application($kernel);
     $this->application->add($command);
     $this->scheduler = $scheduler;
     $this->registry = $registry;
     $this->controller = $controller;
 }
 protected function createTester(ContainerAwareInterface $obj, $shortcat)
 {
     $this->app->add($obj);
     $command = $this->app->find($shortcat);
     $obj->setContainer($this->container);
     return new CommandTester($command);
 }
Exemplo n.º 13
0
 /**
  * {@inheritDoc}
  */
 public function registerCommands(Application $_application)
 {
     $_application->add(new Command\SetupCommand());
     $_application->add(new Command\DumpCommand());
     $_application->add(new Command\WorkflowCommand());
     $_application->add(new Command\FileCommand());
 }
Exemplo n.º 14
0
 /**
  * ConsoleProvider constructor.
  * @param Application $cli
  * @param array $commands
  */
 public function init(Application $cli, $commands = [])
 {
     $this->cli = $cli;
     foreach ($commands as $command) {
         $this->cli->add($this->app->get($command));
     }
 }
Exemplo n.º 15
0
 /**
  * @param Command $command
  * @param $index
  */
 private function registerCommandWithConsole(Command $command, $index)
 {
     $this->console->add($command);
     $command->registerAction(function () use($index) {
         $this->actions->handle($index);
     });
 }
Exemplo n.º 16
0
 protected function setUp()
 {
     $this->cmd = new ExportCmd();
     $this->app = new Application();
     $this->app->add($this->cmd);
     // Virtual filesystem root.
     $this->vfsRoot = vfsStream::setup();
 }
Exemplo n.º 17
0
 public function setUp()
 {
     parent::setUp();
     $this->application = new Application();
     $this->application->add(new \BackgroundCommandStub($this->commandName));
     $this->command = $this->application->find($this->commandName);
     $this->tester = new CommandTester($this->command);
 }
Exemplo n.º 18
0
 /**
  * @return CommandTester
  */
 protected function getCommandTester()
 {
     $this->application->getHelperSet()->set($this->dialog, 'dialog');
     $this->application->add($this->command);
     $command = $this->application->find('phpci:create-admin');
     $commandTester = new CommandTester($command);
     return $commandTester;
 }
Exemplo n.º 19
0
 public static function run($rootPath)
 {
     $app = new Application();
     $app->add(new Command\ApplicationInit($rootPath));
     $app->add(new Command\DatabaseCreate($rootPath));
     $app->add(new Command\ControllerWizard($rootPath));
     $app->run();
 }
Exemplo n.º 20
0
 /**
  * @throws \Exception
  */
 public function run()
 {
     $commands = $this->config('commands');
     foreach ($commands as $command) {
         $this->console->add($this->container->get($command));
     }
     $this->console->run();
 }
 /**
  * Attempts the registration of a single shell command.
  * @param  string $name
  */
 private function attemptRegistration($name)
 {
     try {
         $this->application->add(StrataCommandBase::factory($name));
     } catch (Exception $e) {
         echo "Unable to autoload the '{$name}' command.";
     }
 }
Exemplo n.º 22
0
 public static function getCommandsApp()
 {
     set_time_limit(0);
     $app = new Application('SugarCRM::PSLib', '7.6.3.0');
     $app->add(new Command\GreetCommand());
     $app->add(new Command\QRRCommand());
     $app->run();
 }
Exemplo n.º 23
0
 protected function start()
 {
     $this->console = new SymfonyApplication(self::APP_NAME, self::VERSION);
     foreach ($this->commands as $command) {
         $this->console->add($command);
     }
     $this->console->run();
 }
Exemplo n.º 24
0
 public static function debug()
 {
     set_time_limit(0);
     $application = new Application();
     $application->add(new InstallRun());
     $application->add(new DatabaseDump());
     $application->run();
 }
Exemplo n.º 25
0
 protected function setUp()
 {
     $this->cmd = new ExportCmd();
     $this->app = new Application();
     $this->app->add($this->cmd);
     global $useMyFgets;
     $useMyFgets = true;
 }
Exemplo n.º 26
0
 /**
  * @param  string        $command_class
  * @return CommandTester
  */
 protected function getCommandTesterFor($command_class) : CommandTester
 {
     /** @var Command $command */
     $command = new $command_class();
     $command->setContainer($this->getContainer());
     $this->application->add($command);
     return new CommandTester($this->application->find($command->getName()));
 }
Exemplo n.º 27
0
 /**
  * Constructor
  */
 public function __construct($applicationDir)
 {
     // Init console application
     $this->consoleApplication = new ConsoleApplication();
     // Adding commands
     $commandNotificationSendCommand = new NotificationSendCommand($applicationDir);
     $this->consoleApplication->add($commandNotificationSendCommand);
     $this->consoleApplication->setDefaultCommand($commandNotificationSendCommand->getName());
 }
 /**
  * Attempts the registration of a single shell command.
  * @param  string $name
  */
 private function attemptRegistration($name)
 {
     try {
         $classpath = implode(array("Strata", StrataCommandNamer::getNamespaceStringInStrata(), $name), "\\");
         $this->application->add(new $classpath());
     } catch (Exception $e) {
         echo "Unable to autoload the '{$name}' command.";
     }
 }
 protected function setUp()
 {
     $this->enableSecondLevelCache();
     parent::setUp();
     $this->application = new Application();
     $this->command = new CollectionRegionCommand();
     $this->application->setHelperSet(new HelperSet(array('em' => new EntityManagerHelper($this->_em))));
     $this->application->add($this->command);
 }
Exemplo n.º 30
0
 public static function createApplication()
 {
     $application = new Application('Paraunit', self::VERSION);
     $parallelCommand = new ParallelCommand(new ParallelConfiguration());
     $application->add($parallelCommand);
     $CoverageCommand = new CoverageCommand(new ParallelCoverageConfiguration());
     $application->add($CoverageCommand);
     return $application;
 }