setHelperSet() публичный метод

Set a helper set to be used with the command.
public setHelperSet ( Symfony\Component\Console\Helper\HelperSet $helperSet )
$helperSet Symfony\Component\Console\Helper\HelperSet The helper set
 /**
  * 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;
 }
 /**
  * Bootstraps the application.
  *
  * This method is called after all services are registered
  * and should be used for "dynamic" configuration (whenever
  * a service must be requested).
  *
  * @param Application $app
  */
 public function boot(Application $app)
 {
     $helperSet = new HelperSet(array('connection' => new ConnectionHelper($app['db']), 'dialog' => new DialogHelper()));
     if (isset($app['orm.em'])) {
         $helperSet->set(new EntityManagerHelper($app['orm.em']), 'em');
     }
     $this->console->setHelperSet($helperSet);
     $commands = array('Doctrine\\DBAL\\Migrations\\Tools\\Console\\Command\\ExecuteCommand', 'Doctrine\\DBAL\\Migrations\\Tools\\Console\\Command\\GenerateCommand', 'Doctrine\\DBAL\\Migrations\\Tools\\Console\\Command\\MigrateCommand', 'Doctrine\\DBAL\\Migrations\\Tools\\Console\\Command\\StatusCommand', 'Doctrine\\DBAL\\Migrations\\Tools\\Console\\Command\\VersionCommand');
     // @codeCoverageIgnoreStart
     if (true === $this->console->getHelperSet()->has('em')) {
         $commands[] = 'Doctrine\\DBAL\\Migrations\\Tools\\Console\\Command\\DiffCommand';
     }
     // @codeCoverageIgnoreEnd
     $configuration = new Configuration($app['db'], $app['migrations.output_writer']);
     $configuration->setMigrationsDirectory($app['migrations.directory']);
     $configuration->setName($app['migrations.name']);
     $configuration->setMigrationsNamespace($app['migrations.namespace']);
     $configuration->setMigrationsTableName($app['migrations.table_name']);
     $configuration->registerMigrationsFromDirectory($app['migrations.directory']);
     foreach ($commands as $name) {
         /** @var AbstractCommand $command */
         $command = new $name();
         $command->setMigrationConfiguration($configuration);
         $this->console->add($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);
 }
Пример #4
0
 protected function setUp()
 {
     parent::setUp();
     $this->application = new Application();
     $command = new InfoCommand();
     $this->application->setHelperSet(new HelperSet(array('em' => new EntityManagerHelper($this->_em))));
     $this->application->add($command);
     $this->command = $this->application->find('orm:info');
     $this->tester = new CommandTester($command);
 }
Пример #5
0
 protected function setUp()
 {
     $this->useModelSet('generic');
     parent::setUp();
     $this->application = new Application();
     $this->command = new RunDqlCommand();
     $this->application->setHelperSet(new HelperSet(array('em' => new EntityManagerHelper($this->_em))));
     $this->application->add($this->command);
     $this->tester = new CommandTester($this->command);
 }
 public function setUp()
 {
     $this->connection = $this->getMockBuilder('Doctrine\\DBAL\\Connection')->disableOriginalConstructor()->getMock();
     $this->platform = $this->getMockBuilder('Doctrine\\DBAL\\Platforms\\MySqlPlatform')->disableOriginalConstructor()->getMock();
     $this->connection->expects($this->any())->method('getDatabasePlatform')->will($this->returnValue($this->platform));
     $this->helperSet = new HelperSet(array('phpcr' => new DoctrineDbalHelper($this->connection)));
     $this->application = new Application();
     $this->application->setHelperSet($this->helperSet);
     $command = new InitDoctrineDbalCommand();
     $this->application->add($command);
 }
Пример #7
0
 /**
  * @param $orm
  */
 public function ormCommands($orm)
 {
     if (is_array($orm) && in_array('doctrine', $orm)) {
         /** @var EntityManager $em */
         $em = Model::orm('doctrine')->getOrm();
         $helperSet = ConsoleRunner::createHelperSet($em);
         $this->cli->setCatchExceptions(true);
         $this->cli->setHelperSet($helperSet);
         ConsoleRunner::addCommands($this->cli);
     }
 }
 /**
  * @inheritdoc
  */
 protected function setUp()
 {
     parent::setUp();
     $this->path = \sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid('doctrine_');
     \mkdir($this->path);
     $metadataDriver = $this->_em->getConfiguration()->getMetadataDriverImpl();
     $metadataDriver->addPaths(array(__DIR__ . '/../../../../Models/DDC3231/'));
     $this->application = new Application();
     $this->application->setHelperSet(new HelperSet(array('em' => new EntityManagerHelper($this->_em))));
     $this->application->add(new GenerateRepositoriesCommand());
 }
 public function testExecuteWithExectedUnavailableVersionAndInteraction()
 {
     // Mocks
     $configuration = $this->buildMock('AntiMattr\\MongoDB\\Migrations\\Configuration\\Configuration');
     $executedVersion = $this->buildMock('AntiMattr\\MongoDB\\Migrations\\Version');
     $migration = $this->buildMock('AntiMattr\\MongoDB\\Migrations\\Migration');
     $dialog = $this->buildMock('Symfony\\Component\\Console\\Helper\\DialogHelper');
     // Variables and Objects
     $numVersion = '000123456789';
     $input = new ArgvInput(array('application-name', MigrateCommand::NAME, $numVersion));
     $interactive = true;
     $executedVersions = array($executedVersion);
     $availableVersions = array();
     $application = new Application();
     $helperSet = new HelperSet(array('dialog' => $dialog));
     // Set properties on objects
     $application->setHelperSet($helperSet);
     $this->command->setApplication($application);
     $input->setInteractive($interactive);
     $this->command->setMigration($migration);
     $this->command->setMigrationConfiguration($configuration);
     // Expectations
     $configuration->expects($this->once())->method('getMigratedVersions')->will($this->returnValue($executedVersions));
     $configuration->expects($this->once())->method('getAvailableVersions')->will($this->returnValue($availableVersions));
     $dialog->expects($this->exactly(2))->method('askConfirmation')->will($this->returnValue(true));
     $migration->expects($this->once())->method('migrate')->with($numVersion);
     // Run command, run.
     $this->command->run($input, $this->output);
 }
Пример #10
0
 /**
  * @return \Symfony\Component\Console\Application
  */
 public function getConsole()
 {
     $application = new Application('psx', Base::getVersion());
     $application->setHelperSet(new HelperSet($this->appendConsoleHelpers()));
     $this->appendConsoleCommands($application);
     return $application;
 }
Пример #11
0
 /**
  * @param HelperSet $helperSet
  * @param array $commands
  */
 public static function run(HelperSet $helperSet, $commands = array())
 {
     $cli = new \Symfony\Component\Console\Application('Malocher EventStore CLI', self::VERSION);
     $cli->setHelperSet($helperSet);
     $cli->setCatchExceptions(true);
     self::addCommands($cli);
     $cli->run();
 }
Пример #12
0
 /**
  * Run console with the given helperset.
  *
  * @param \Symfony\Component\Console\Helper\HelperSet $helperSet
  * @return void
  */
 public static function run(HelperSet $helperSet)
 {
     $cli = new Application('Propel Command Line Tool', \PropelCli\Version::VERSION);
     $cli->setCatchExceptions(true);
     $cli->setHelperSet($helperSet);
     self::addCommands($cli);
     $cli->run();
 }
Пример #13
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;
 }
Пример #14
0
 public function setUp()
 {
     $this->session = $this->getMock('PHPCR\\SessionInterface');
     $this->workspace = $this->getMock('PHPCR\\WorkspaceInterface');
     $this->repository = $this->getMock('PHPCR\\RepositoryInterface');
     $this->queryManager = $this->getMock('PHPCR\\Query\\QueryManagerInterface');
     $this->row1 = $this->getMock('PHPCR\\Tests\\Stubs\\MockRow');
     $this->node1 = $this->getMock('PHPCR\\Tests\\Stubs\\MockNode');
     $this->dumperHelper = $this->getMockBuilder('PHPCR\\Util\\Console\\Helper\\PhpcrConsoleDumperHelper')->disableOriginalConstructor()->getMock();
     $this->helperSet = new HelperSet(array('phpcr' => new PhpcrHelper($this->session), 'phpcr_console_dumper' => $this->dumperHelper));
     $this->session->expects($this->any())->method('getWorkspace')->will($this->returnValue($this->workspace));
     $this->workspace->expects($this->any())->method('getName')->will($this->returnValue('test'));
     $this->workspace->expects($this->any())->method('getQueryManager')->will($this->returnValue($this->queryManager));
     $this->queryManager->expects($this->any())->method('getSupportedQueryLanguages')->will($this->returnValue(array('JCR-SQL2')));
     $this->application = new Application();
     $this->application->setHelperSet($this->helperSet);
 }
Пример #15
0
 /**
  * Run console with the given helperset.
  *
  * @param \Symfony\Component\Console\Helper\HelperSet $helperSet
  * @return void
  */
 public static function run(HelperSet $helperSet)
 {
     $cli = new Application('Doctrine Command Line Interface', \Doctrine\ORM\Version::VERSION);
     $cli->setCatchExceptions(true);
     $cli->setHelperSet($helperSet);
     self::addCommands($cli);
     $cli->run();
 }
 /**
  * Constructor
  *
  * @param Application $console Console
  * @param ContainerInterface $container Container DI
  */
 public function __construct(Application $console, ContainerInterface $container)
 {
     $entityManager = $container->get('EntityManager');
     $helperSet = ConsoleRunner::createHelperSet($entityManager);
     $helperSet->set(new QuestionHelper(), 'dialog');
     $console->setHelperSet($helperSet);
     ConsoleRunner::addCommands($console);
 }
Пример #17
0
 /**
  * Runs console with the given helperset.
  *
  * @param HelperSet                                    $helperSet
  * @param \Symfony\Component\Console\Command\Command[] $commands
  *
  * @return void
  */
 public static function run(HelperSet $helperSet, $commands = array())
 {
     $cli = new Application('PoolDBM Command Line Interface', Version::VERSION);
     $cli->setCatchExceptions(true);
     $cli->setHelperSet(new HelperSet($helperSet));
     self::addDefaultCommands($cli);
     $cli->addCommands($commands);
     $cli->run();
 }
 /**
  * Creates a console application with the given helperset and
  * optional commands.
  *
  * @param \Symfony\Component\Console\Helper\HelperSet $helperSet
  * @param array $commands
  *
  * @return \Symfony\Component\Console\Application
  */
 public static function createApplication(HelperSet $helperSet, $commands = array())
 {
     $cli = new Application('Doctrine Command Line Interface', Version::VERSION);
     $cli->setCatchExceptions(true);
     $cli->setHelperSet($helperSet);
     self::addCommands($cli);
     $cli->addCommands($commands);
     return $cli;
 }
Пример #19
0
 /**
  * Creates a console application with the given helperset and
  * optional commands.
  *
  * @param HelperSet $helperSet
  * @param \Symfony\Component\Console\Command\Command[] $commands
  *
  * @return Application
  */
 public static function createApplication(HelperSet $helperSet, $commands = [])
 {
     $cli = new Application('Humus Amqp Command Line Interface');
     $cli->setCatchExceptions(true);
     $cli->setHelperSet($helperSet);
     self::addCommands($cli);
     $cli->addCommands($commands);
     return $cli;
 }
Пример #20
0
 /**
  * Creates a console application with the given helperset and
  * optional commands.
  *
  * @param \Symfony\Component\Console\Helper\HelperSet $helperSet
  * @param array $commands
  *
  * @return \Symfony\Component\Console\Application
  */
 public static function createApplication(HelperSet $helperSet, $commands = [])
 {
     $cli = new Application('Doctrine Migrations', MigrationsVersion::VERSION());
     $cli->setCatchExceptions(true);
     $cli->setHelperSet($helperSet);
     self::addCommands($cli);
     $cli->addCommands($commands);
     return $cli;
 }
 /**
  * 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);
 }
Пример #22
0
 /**
  * {@inheritDoc}
  * @return Application
  */
 public function createService(ServiceLocatorInterface $sl)
 {
     $cli = new Application();
     $cli->setName('DoctrineModule Command Line Interface');
     $cli->setVersion(Version::VERSION);
     $cli->setHelperSet(new HelperSet());
     // Load commands using event
     $this->getEventManager($sl)->trigger('loadCli.post', $cli, array('ServiceManager' => $sl));
     return $cli;
 }
Пример #23
0
 /**
  * {@inheritDoc}
  * @return Application
  */
 public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
 {
     $cli = new Application();
     $cli->setName('DoctrineModule Command Line Interface');
     $cli->setVersion(Version::VERSION);
     $cli->setHelperSet(new HelperSet());
     $cli->setCatchExceptions(true);
     $cli->setAutoExit(false);
     // Load commands using event
     $this->getEventManager($container)->trigger('loadCli.post', $cli, array('ServiceManager' => $container));
     return $cli;
 }
Пример #24
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;
 }
 /**
  * Registers services on the given app.
  *
  * This method should only be used to configure services and parameters.
  * It should not get services.
  *
  * @param Application $app An Application instance
  */
 public function register(Application $app)
 {
     $app["console.helperset"] = $app->share(function ($app) {
         return new HelperSet(array("app" => new ApplicationHelper($app), "formatter" => new FormatterHelper(), "dialog" => new DialogHelper()));
     });
     $app["console"] = $app->share(function ($app) {
         $console = new ConsoleApplication("app console");
         $console->setHelperSet($app["console.helperset"]);
         $console->add(new RouterDebugCommand());
         $console->add(new ListServicesCommand());
         return $console;
     });
 }
Пример #26
0
 /**
  *
  */
 public function initialize()
 {
     $commands = $this->container->configuration->get('commands', []);
     $application = new Application();
     /** @var EntityManager $em */
     $em = $this->container->get('doctrine')->getManager();
     $application->setHelperSet(new HelperSet(['container' => new ContainerHelper($this->container), 'em' => new EntityManagerHelper($em), 'db' => new ConnectionHelper($em->getConnection())]));
     foreach ($commands as $name => $class) {
         $command = new $class();
         $application->add($command);
     }
     $this->application = $application;
 }
 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;
     });
 }
Пример #28
0
 /**
  * Runs the application using the given HelperSet
  *
  * This method is responsible for creating the console application, adding
  * relevant commands, and running it. Other code is responsible for producing
  * the HelperSet itself (your cli-config.php or bootstrap code), and for
  * calling this method (the actual bin command file).
  *
  * @param HelperSet $helperSet
  * @param Application $application
  * @throws \Doxport\Exception\Exception
  * @return integer 0 if everything went fine, or an error code
  */
 public static function run(HelperSet $helperSet, Application $application = null)
 {
     if (!$helperSet->has('em')) {
         throw new Exception('Helper set passed to Doxport console runner must have an entity manager ("em")');
     }
     if (!$application) {
         $application = new Application('Doxport relational data tool', Version::VERSION);
     }
     $application->setCatchExceptions(true);
     $application->setHelperSet($helperSet);
     $application->add(new ExportCommand());
     $application->add(new DeleteCommand());
     $application->add(new ImportCommand());
     return $application->run();
 }
Пример #29
0
 /**
  * 
  * @param ServiceLocatorInterface $serviceLocator
  * @return Application
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $config = $serviceLocator->get(ConfigHelper::class);
     $commandManager = $serviceLocator->get('CommandManager');
     $commands = array_values($commandManager->getCanonicalNames());
     $application = new Application($config->get('application.name'), $config->get('application.version'));
     foreach ($commands as $command) {
         $application->add($commandManager->get($command));
     }
     $application->setHelperSet(new HelperSet());
     $application->setCatchExceptions(true);
     $application->setAutoExit(false);
     $this->getEventManager($serviceLocator)->trigger('loadCli.post', $application, array('ServiceManager' => $serviceLocator));
     return $application;
 }
 /**
  * @group legacy
  */
 public function testExecuteInteractiveWithDialogHelper()
 {
     if (!class_exists('Symfony\\Component\\Console\\Helper\\DialogHelper')) {
         $this->markTestSkipped('Using the DialogHelper is not possible on Symfony 3+.');
     }
     $application = new Application();
     $dialog = $this->createMock('Symfony\\Component\\Console\\Helper\\DialogHelper', array('askAndValidate'));
     $dialog->expects($this->at(0))->method('askAndValidate')->will($this->returnValue('user'));
     $helperSet = new HelperSet(array('dialog' => $dialog));
     $application->setHelperSet($helperSet);
     $commandTester = $this->createCommandTester($this->getContainer('user'), $application);
     $exitCode = $commandTester->execute(array('command' => 'fos:user:deactivate'), array('decorated' => false, 'interactive' => true));
     $this->assertEquals(0, $exitCode, 'Returns 0 in case of success');
     $this->assertRegExp('/User "user" has been deactivated/', $commandTester->getDisplay());
 }