addCommands() public method

If a Command is not enabled it will not be added.
public addCommands ( array $commands )
$commands array An array of commands
 /**
  * Config doctrine console
  *
  * @param Application $console
  * @param EntityManager $entityManager
  * @return Application
  */
 static function setConsole(Application $console, EntityManager $entityManager)
 {
     $helperSet = new \Symfony\Component\Console\Helper\HelperSet(array('db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($entityManager->getConnection()), 'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($entityManager)));
     $console->setHelperSet($helperSet);
     $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()));
     return $console;
 }
示例#2
0
 /**
  * Services constructor.
  */
 public function __construct()
 {
     $this->kernel = new Kernel();
     $this->application = new Application('Neusta Facilior', FACILIOR_VERSION);
     $this->application->setAutoExit(false);
     //Creates Services Output
     $this->console = new ConsoleService();
     //Loads Commands into Application
     $this->application->addCommands($this->kernel->commands());
 }
示例#3
0
 /**
  * command应用主入口
  * @throws \Exception
  */
 static function main()
 {
     $application = new Application();
     $application->addCommands(self::createCommands());
     $application->setDefaultCommand(self::DEFAULT_COMMAND_NAME);
     $application->run();
 }
示例#4
0
 /**
  * command应用主入口
  * @throws \Exception
  */
 static function main()
 {
     $application = new Application();
     $application->addCommands(self::createCommands());
     $application->setDefaultCommand(ThumbnailCommand::COMMAND_NAME);
     $application->run();
 }
示例#5
0
 /**
  * Inicializa a aplicação.
  *
  * @throws \Exception
  */
 public function run()
 {
     //apenas para inicializar
     Config::getInstance();
     $application = new Application();
     $commands = [];
     /* Carregando os comandos internos */
     $anna_commands = __DIR__ . DS . 'Commands' . DS;
     $anna_commands = $this->loadAppCommands($anna_commands);
     /* Carregandos os comandos criados pelos desenvolvedores */
     $app_commands = SYS_ROOT . 'App' . DS . 'Console' . DS;
     $app_commands = $this->loadAppCommands($app_commands);
     /* Registra todos os comandos encontrados */
     foreach ($app_commands as $cmd) {
         $commands[] = new $cmd();
     }
     foreach ($anna_commands as $cmd) {
         $class = new \ReflectionClass($cmd);
         if (!$class->isAbstract()) {
             $commands[] = new $cmd();
         }
     }
     $application->addCommands($commands);
     $application->run();
 }
示例#6
0
 /**
  * @param Application $cli
  *
  * @return void
  */
 public static function addCommands(Application $cli)
 {
     $cli->addCommands([new Command\ExecuteCommand(), new Command\GenerateCommand(), new Command\LatestCommand(), new Command\MigrateCommand(), new Command\StatusCommand(), new Command\VersionCommand(), new Command\UpToDateCommand()]);
     if ($cli->getHelperSet()->has('em')) {
         $cli->add(new Command\DiffCommand());
     }
 }
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     $this->application = new Application('Drupal Code Generator', '@git-version@');
     $discovery = new GeneratorDiscovery([DCG_ROOT . '/src/Commands'], [DCG_ROOT . '/src/Templates'], new Filesystem());
     $generators = $discovery->getGenerators();
     $this->application->addCommands($generators);
     $navigation = new Navigation();
     $navigation->init($generators);
     $this->application->add($navigation);
     $this->command = $this->application->find('navigation');
     $this->questionHelper = $this->createMock('Symfony\\Component\\Console\\Helper\\QuestionHelper');
     $this->helperSet = $this->command->getHelperSet();
     $this->commandTester = new CommandTester($this->command);
     $this->filesystem = new Filesystem();
     $this->destination = DCG_SANDBOX . '/tests';
 }
示例#8
0
 /**
  * command应用主入口
  * @throws \Exception
  */
 static function main()
 {
     $application = new Application();
     $application->setAutoExit(true);
     $application->addCommands(self::createCommands());
     $application->run();
 }
示例#9
0
 /**
  * Creates console.
  *
  * @param HelperSet $helperSet
  * @param \Symfony\Component\Console\Command\Command[] $commands
  * @return Application
  */
 public function createConsole(HelperSet $helperSet, array $commands)
 {
     $cli = new Application($this->getName(), $this->getVersion());
     $cli->setCatchExceptions(true);
     $cli->setHelperSet($helperSet);
     $cli->addCommands($commands);
     return $cli;
 }
示例#10
0
 /**
  * @param CoreInterface $core
  */
 protected function boot(CoreInterface $core)
 {
     $config = $core->make('Surume\\Config\\ConfigInterface');
     $factory = $core->make('Surume\\Console\\Client\\Command\\CommandFactoryInterface');
     $handler = $core->make('Surume\\Console\\Client\\Command\\CommandHandlerInterface');
     $console = $core->make('Surume\\Console\\Client\\ConsoleClientInterface');
     $cmds = (array) $factory->getDefinitions();
     $commands = [];
     foreach ($cmds as $command => $definition) {
         $commands[] = $factory->create($command, [$handler]);
     }
     $this->symfony->addCommands($commands);
     $version = $core->version();
     $console->onCommand(function () use($version) {
         echo "SurumePHP-v{$version}\n";
         $this->symfony->run();
     });
 }
示例#11
0
文件: Tg.php 项目: twhiston/tg
 /**
  * @param CommandLoader $commandLoader
  * @param $locations
  */
 private function addCommands(CommandLoader $commandLoader, $locations, $bypassCache = false)
 {
     $classes = $this->classCache->getClasses('RoboCommand\\', $locations, $bypassCache);
     $commands = $commandLoader->createRoboCommands($classes, $this->passThroughArgs);
     $this->app->addCommands($commands);
     $classes = $this->classCache->getClasses('Command\\', $locations, $bypassCache);
     $commands = $commandLoader->createSymfonyCommands($classes);
     $this->app->addCommands($commands);
 }
 /**
  * Runs console with the given helperset.
  *
  * @param \Symfony\Component\Console\Helper\HelperSet  $helperSet
  * @param \Symfony\Component\Console\Command\Command[] $commands
  *
  * @return void
  */
 public static function run(HelperSet $helperSet, $commands = array(), OutputInterface $output = null)
 {
     $cli = new Application('Doctrine Command Line Interface', Version::VERSION);
     $cli->setCatchExceptions(true);
     $cli->setHelperSet($helperSet);
     $cli->setAutoExit(false);
     $commands = array_merge(self::getDefaultCommands(), $commands);
     $cli->addCommands($commands);
     $cli->run(null, $output);
 }
示例#13
0
 /** @Provides("Symfony\Component\Console\Application") @Singleton */
 static function provideApp($name = "UNKNOWN", $version = "UNKNOWN", $helpers = [], $commands = [])
 {
     $app = new Application($name, $version);
     $app->addCommands($commands);
     $helperSet = $app->getHelperSet();
     foreach ($helpers as $alias => $helper) {
         $helperSet->set($helper, $alias);
     }
     return $app;
 }
示例#14
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');
 }
示例#15
0
 /**
  * Sets the dojo theme to use.
  *
  * @param \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator
  * @return \Symfony\Component\Console\Application
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get('Config')['sds']['dojo'];
     $configHelper = new \Sds\DojoModule\Tools\Console\Helper\ConfigHelper($config);
     $helperSet = new HelperSet();
     $helperSet->set($configHelper, 'config');
     $cli = new Application();
     $cli->setName('DojoModule Command Line Interface');
     $cli->setHelperSet($helperSet);
     $cli->addCommands(array(new \Sds\DojoModule\Tools\Console\Command\GenerateProfile()));
     return $cli;
 }
示例#16
0
 public function testCliGeneratorLibrary()
 {
     $application = new Application();
     $application->addCommands($this::$cliManager->generateCli());
     $fixtures_commands = $this::$cliResourceBuilder->buildDefinitions();
     foreach ($fixtures_commands as $command => $definition) {
         $command = $application->find($definition['name']);
         $commandTester = new CommandTester($command);
         $commandTester->execute(array('command' => $command->getName(), 'param1' => 'Value for param1'));
         $this->assertRegExp("/Value for param1/", $commandTester->getDisplay());
     }
 }
示例#17
0
 public function testCliGeneratorLibrary()
 {
     $application = new Application();
     $application->addCommands($this::$cliManager->generateCli());
     $fixtures_commands = array('calculator:max' => array('params' => array('value1' => 10, 'value2' => 6), 'expected' => 10), 'calculator:min' => array('params' => array('value1' => 10, 'value2' => 6), 'expected' => 6), 'calculator:abs' => array('params' => array('value1' => -110), 'expected' => 110), 'calculator:sin' => array('params' => array('value1' => M_PI_2), 'expected' => 1));
     foreach ($fixtures_commands as $command => $definition) {
         $command = $application->find($command);
         $commandTester = new CommandTester($command);
         $definition['params']['command'] = $command->getName();
         $commandTester->execute($definition['params']);
         $this->assertTrue($definition['expected'] == $commandTester->getDisplay());
     }
 }
 public function register(Application $app)
 {
     if (!isset($app["doctrine.entity_manager"])) {
         throw new \Exception("The Doctrine Command Runner requires the Doctrine Entity Manager to be set.");
     }
     $app["doctrine.command_runner"] = $app->share(function ($app) {
         $em = $app["doctrine.entity_manager"];
         $helperSet = new HelperSet(array('db' => new ConnectionHelper($em->getConnection()), 'em' => new EntityManagerHelper($em)));
         $commandLine = new ConsoleApplication("Silex Doctrine2 Integration Console", 0.01);
         $commandLine->setCatchExceptions(true);
         $commandLine->setHelperSet($helperSet);
         $commandLine->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()));
         return $commandLine;
     });
 }
 /**
  * @param Container
  * @return Application
  */
 public static function createConsole(Container $container, $config)
 {
     $console = new Application($config['name'], $config['version']);
     $helperSet = new HelperSet();
     foreach (array_keys($container->findByTag(self::HELPER_TAG)) as $name) {
         $helperSet->set($container->getService($name), $name);
     }
     $console->setHelperSet($helperSet);
     $console->setCatchExceptions($config['catchExceptions']);
     $commands = [];
     foreach (array_keys($container->findByTag(self::COMMAND_TAG)) as $name) {
         $commands[] = $container->getService($name);
     }
     foreach (array_keys($container->findByTag(self::KDYBY_COMMAND_TAG)) as $name) {
         $commands[] = $container->getService($name);
     }
     $console->addCommands($commands);
     return $console;
 }
 public function configServiceManager()
 {
     return array('aliases' => array('Symfony\\Component\\Console\\Application' => 'ConsoleApp', 'BasConsole\\Module' => 'BasModule', 'Zend\\Config\\Config' => 'ConfigWriter'), 'factories' => array('ConfigHelper' => function ($sm) {
         $factory = $sm->get('ConfigFactory');
         $config = new Helpers\ConfigHelper($factory);
         return $config;
     }, 'ConfigWriter' => function ($sm) {
         $writer = new ConfigWriter(array());
         return $writer;
     }, 'ConsoleApp' => function ($sm) {
         $factory = $sm->get('ConsoleCommandsFactory');
         $app = new Application();
         $app->addCommands($factory->getCommands());
         return $app;
     }, 'ConsoleCommandsFactory' => function ($sm) {
         $module = $sm->get('BasModule');
         $factory = new Factories\ConsoleCommandsFactory($sm, $module->getConfig());
         return $factory;
     }, 'RouteAddCommand' => function ($sm) {
         $routeService = $sm->get('RouteService');
         $command = new Commands\RouteAddCommand();
         $command->setterInjector($routeService);
         return $command;
     }, 'RouteObject' => function ($sm) {
         $factory = $sm->get('ConfigFactory');
         $config = $factory->getConfigObject();
         $routeObject = new Objects\RouteObject($config);
         return $routeObject;
     }, 'RouteService' => function ($sm) {
         $routeObject = $sm->get('RouteObject');
         $configHelper = $sm->get('ConfigHelper');
         $stringHelper = $sm->get('StringHelper');
         $service = new RouteService($routeObject, $configHelper, $stringHelper);
         return $service;
     }, 'RouteUpdateCommand' => function ($sm) {
         $routeService = $sm->get('RouteService');
         $command = new Commands\RouteUpdateCommand();
         $command->setterInjector($routeService);
         return $command;
     }), 'invokables' => array('AppCommand' => 'BasConsole\\Commands\\AppCommand', 'BasModule' => 'BasConsole\\Module', 'ConfigFactory' => 'BasConsole\\Factories\\ConfigFactory', 'GreetCommand' => 'BasConsole\\Commands\\GreetCommand', 'ModuleCommand' => 'BasConsole\\Commands\\ModuleCommand', 'StringHelper' => 'BasConsole\\Helpers\\StringHelper'));
 }
示例#21
0
文件: Cli.php 项目: stativo/cli
 public function run()
 {
     $call = explode(':', $this->arg->get('call'));
     $task = ucfirst($call[0]);
     if (isset($call[1])) {
         $method = $call[1];
     } else {
         $method = 'run';
     }
     $tasks = array();
     foreach (\Stativo\Helpers\File::lists('Task') as $namespace => $files) {
         foreach ($files as $file) {
             $task = $namespace . '\\Task\\' . $file;
             $tasks[] = new $task();
         }
     }
     $app = new Application('Stativo CLI', '1.0');
     $app->addCommands($tasks);
     $app->run();
     // $call   = \Stativo\Helpers\File::find($task, 'Task');
     // $call = new $call();
     // $call->$method();
 }
 public function run()
 {
     $console = new Application(self::APP_NAME, self::APP_VERSION);
     $console->setDefaultCommand(self::APP_DEFAULT_COMMAND);
     $dispatcher = new EventDispatcher();
     $dispatcher->addListener(ConsoleEvents::COMMAND, function (ConsoleCommandEvent $event) {
         // get the input instance
         // $input = $event->getInput();
         // get the output instance
         $output = $event->getOutput();
         // get the command to be executed
         $command = $event->getCommand();
         // write something about the command
         //$output->writeln(sprintf('Before running command <info>%s</info>', $command->getName()));
         if ($command->getName() == StartServer::CLI_COMMAND) {
             $output->write(self::$BANNER);
         }
         // get the application
         // $application = $command->getApplication();
     });
     $console->setDispatcher($dispatcher);
     $console->addCommands([new Controller\StartServer(), new Controller\StopServer(), new Controller\ListServers(), new Controller\RegisterServer()]);
     $console->run();
 }
<?php

declare (strict_types=1);
/**
 * @author hollodotme
 */
namespace IceHawk\ComponentTemplateGenerator;

use IceHawk\ComponentTemplateGenerator\ConsoleCommands\GenerateComponent;
use IceHawk\ComponentTemplateGenerator\ConsoleCommands\RollBack;
use IceHawk\ComponentTemplateGenerator\ConsoleCommands\SelfUpdate;
use Symfony\Component\Console\Application;
error_reporting(-1);
ini_set('display_errors', 'On');
require __DIR__ . '/../vendor/autoload.php';
define('PHAR_DIR', dirname(__DIR__));
define('WORKING_DIR', getcwd());
try {
    $app = new Application('IceHawk CTG', '@package_version@');
    $app->addCommands([new GenerateComponent('generate:component'), new SelfUpdate('self-update'), new RollBack('rollback')]);
    $code = $app->run();
    exit($code);
} catch (\Throwable $e) {
    echo "Uncaught " . get_class($e) . " with message: " . $e->getMessage() . "\n";
    echo $e->getTraceAsString();
    exit(1);
}
示例#24
0
 /**
  * @param Application $cli
  */
 public static function addCommands(Application $cli)
 {
     $cli->addCommands(array(new SchemaInfoCommand(), new SchemaCreateCommand(), new SchemaDropCommand(), new SchemaImportCommand(), new SchemaExportCommand()));
 }
示例#25
0
文件: deploy.php 项目: lilocon/deploy
<?php

include dirname(__DIR__) . "/vendor/autoload.php";
use Command\Deploy;
use Symfony\Component\Console\Application;
$console = new Application();
$console->addCommands(array(new Deploy()));
$console->run();
示例#26
0
#!/usr/bin/env php
<?php 
require __DIR__ . '/vendor/autoload.php';
use Symfony\Component\Console\Application;
use Fennec\Console\Command\SetupCommand;
$commands = [new SetupCommand()];
$application = new Application();
$application->addCommands($commands);
$application->run();
示例#27
0
 public function addCommands(Application $cli)
 {
     $cli->addCommands([new InitialiseCommand()]);
 }
示例#28
0
<?php

/** vendor/bin/doctrine looks for a config/cli-config.php file in the project - so that's why this is here **/
/** If the bootstrap (Aurex.php) sees this variable, don't 'run' the HTTP front-controller **/
$cli = true;
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/web/index.php';
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain, Symfony\Component\Console\Application as CliApplication, Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper, Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper, UseAllFive\Command\LoadDataFixturesDoctrineCommand, Doctrine\Common\Annotations\AnnotationRegistry, Doctrine\ORM\Mapping\Driver\AnnotationDriver, Doctrine\Common\Annotations\AnnotationReader, Symfony\Component\Console\Helper\HelperSet, Doctrine\ORM\Mapping\Driver\DatabaseDriver, Doctrine\ORM\Tools\Console\Command, Doctrine\DBAL\Connection, Doctrine\DBAL\Version;
/** @var Connection $db The above bootstrap creates the app object for us */
$db = $aurex['db'];
/** @var Doctrine\ORM\EntityManager $em The entity manager */
$em = $aurex['orm.em'];
$driver = new DatabaseDriver($db->getSchemaManager());
$driver->setNamespace('Aurex\\Application\\Entity\\');
$annotationsFile = __DIR__ . '/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php';
AnnotationRegistry::registerFile($annotationsFile);
$driverChain = new MappingDriverChain();
$driverChain->addDriver(new AnnotationDriver(new AnnotationReader(), [__DIR__ . '/lib/Application/Model/Entity']), 'Aurex\\Application\\Model\\Entity\\');
$em->getConfiguration()->setMetadataDriverImpl($driverChain);
/** @var Symfony\Component\Console\Application $cli */
$cli = new CliApplication('Doctrine Command Line Interface', Version::VERSION);
$cli->setCatchExceptions(true);
$cli->setHelperSet(new HelperSet(['db' => new ConnectionHelper($em->getConnection()), 'em' => new EntityManagerHelper($em)]));
$cli->addCommands([new Command\GenerateRepositoriesCommand(), new Command\GenerateEntitiesCommand(), new Command\ConvertMappingCommand(), new Command\ValidateSchemaCommand(), new Command\SchemaTool\CreateCommand(), new Command\SchemaTool\UpdateCommand(), new Command\GenerateProxiesCommand(), new LoadDataFixturesDoctrineCommand()]);
$cli->run();
示例#29
0
<?php

/**
 * PHP version 5.6
 *
 * This source file is subject to the license that is bundled with this package in the file LICENSE.
 */
require __DIR__ . '/../vendor/autoload.php';
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Helper\HelperSet;
use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper;
use Doctrine\DBAL\DriverManager;
use ComPHPPuebla\Console\Command\LoadFixtureCommand;
$cli = new Application('DBAL Fixtures CLI', '2.0.0');
$cli->setCatchExceptions(true);
$connection = DriverManager::getConnection(require 'config/connection.config.php');
$helperSet = new HelperSet();
$helperSet->set(new ConnectionHelper($connection), 'db');
$cli->setHelperSet($helperSet);
$cli->addCommands([new LoadFixtureCommand()]);
$cli->run();
示例#30
0
 /**
  * Sets default commands list.
  *
  * @param Application $cli
  */
 public static function addDefaultCommands(Application $cli)
 {
     $cli->addCommands(array(new PoolDBMCommand\GenerateMultiModelCommand()));
 }