本文整理汇总了PHP中Doctrine\ORM\Tools\Console\ConsoleRunner::addCommands方法的典型用法代码示例。如果您正苦于以下问题:PHP ConsoleRunner::addCommands方法的具体用法?PHP ConsoleRunner::addCommands怎么用?PHP ConsoleRunner::addCommands使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Tools\Console\ConsoleRunner
的用法示例。
在下文中一共展示了ConsoleRunner::addCommands方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onBootstrap
/**
* {@inheritDoc}
*/
public function onBootstrap(EventInterface $e)
{
/* @var $app \Zend\Mvc\ApplicationInterface */
$app = $e->getTarget();
$events = $app->getEventManager()->getSharedManager();
// Attach to helper set event and load the entity manager helper.
$events->attach('doctrine', 'loadCli.post', function (EventInterface $e) {
/* @var $cli \Symfony\Component\Console\Application */
$cli = $e->getTarget();
ConsoleRunner::addCommands($cli);
$cli->addCommands(array(new DiffCommand(), new ExecuteCommand(), new GenerateCommand(), new MigrateCommand(), new StatusCommand(), new VersionCommand()));
/* @var $sm ServiceLocatorInterface */
$sm = $e->getParam('ServiceManager');
/* @var $em \Doctrine\ORM\EntityManager */
$em = $sm->get('doctrine.entitymanager.orm_default');
$helperSet = $cli->getHelperSet();
$helperSet->set(new DialogHelper(), 'dialog');
$helperSet->set(new ConnectionHelper($em->getConnection()), 'db');
$helperSet->set(new EntityManagerHelper($em), 'em');
});
$config = $app->getServiceManager()->get('Config');
$app->getServiceManager()->get('doctrine.entity_resolver.orm_default');
if (isset($config['zenddevelopertools']['profiler']['enabled']) && $config['zenddevelopertools']['profiler']['enabled']) {
$app->getServiceManager()->get('doctrine.sql_logger_collector.orm_default');
}
}
示例2: __construct
/**
* 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);
}
示例3: registerCommands
public function registerCommands(Application $application)
{
parent::registerCommands($application);
//include Doctrine ORM commands if exist
if (class_exists('Doctrine\\ORM\\Version')) {
ConsoleRunner::addCommands($application);
}
}
示例4: run
/**
* Run console with the given helperset. Use the in-built Doctrine commands, plus Flextrine specific ones.
*
* @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);
parent::addCommands($cli);
self::addCommands($cli);
$cli->run();
}
示例5: __construct
public function __construct()
{
parent::__construct(static::NAME, static::VERSION);
//Add Doctrine support to console
$em = Configuration::getEntityManager();
$doctrineHelperSet = new HelperSet(['db' => new ConnectionHelper($em->getConnection()), 'em' => new EntityManagerHelper($em)]);
$this->setHelperSet($doctrineHelperSet);
ConsoleRunner::addCommands($this);
$this->addCommands([new Command\ModuleUpdateCommand()]);
}
示例6: ormCommands
/**
* @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);
}
}
示例7: setupDoctrineCommands
public function setupDoctrineCommands()
{
if (!Core::make('app')->isInstalled()) {
return;
}
$helperSet = ConsoleRunner::createHelperSet(\ORM::entityManager('core'));
$this->setHelperSet($helperSet);
$migrationsConfiguration = new MigrationsConfiguration();
/** @var \Doctrine\DBAL\Migrations\Tools\Console\Command\AbstractCommand[] $commands */
$commands = array(new \Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand());
foreach ($commands as $migrationsCommand) {
$migrationsCommand->setMigrationConfiguration($migrationsConfiguration);
$this->add($migrationsCommand);
}
ConsoleRunner::addCommands($this);
}
示例8: init
/**
* {@inheritDoc}
*/
public function init(ModuleManager $e)
{
$events = $e->getEventManager()->getSharedManager();
// Attach to helper set event and load the entity manager helper.
$events->attach('doctrine', 'loadCli.post', function (EventInterface $e) {
/* @var $cli \Symfony\Component\Console\Application */
$cli = $e->getTarget();
/* @var $sm ServiceLocatorInterface */
$sm = $e->getParam('ServiceManager');
$em = $sm->get('doctrine.entitymanager.orm_default');
$paths = $sm->get('doctrine.configuration.fixtures');
$importCommand = new ImportCommand();
$importCommand->setEntityManager($em);
$importCommand->setPath($paths);
ConsoleRunner::addCommands($cli);
$cli->addCommands(array($importCommand));
});
}
示例9: onBootstrap
public function onBootstrap(EventInterface $e)
{
$app = $e->getTarget();
$events = $app->getEventManager()->getSharedManager();
// Attach to helper set event and load the entity manager helper.
$events->attach('doctrine', 'loadCli.post', function (EventInterface $e) {
$cli = $e->getTarget();
ConsoleRunner::addCommands($cli);
if (class_exists('Doctrine\\DBAL\\Migrations\\Versions')) {
$cli->add(array(new DiffCommand(), new ExecuteCommand(), new GenerateCommand(), new MigrateCommand(), new StatusCommand(), new VersionCommand()));
}
$sm = $e->getParam('ServiceManager');
$em = $sm->get('doctrine.entitymanager.orm_another');
$helperSet = $cli->getHelperSet();
$helperSet->set(new DialogHelper(), 'dialog');
$helperSet->set(new ConnectionHelper($em->getConnection()), 'db');
$helperSet->set(new EntityManagerHelper($em), 'em');
});
}
示例10: addOrmCommands
/**
* Add Doctrine commands
*
* @return $this
*/
public function addOrmCommands()
{
ConsoleRunner::addCommands($this);
return $this;
}
示例11: SilexApplication
use Symfony\Component\Console\Helper\HelperSet;
use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper;
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
use Doctrine\ORM\Tools\Console\ConsoleRunner;
use MJanssen\Command\CacheClearCommand;
use MJanssen\Command\DocsCreateCommand;
use MJanssen\Command\LogClearCommand;
chdir(dirname(__DIR__));
$loader = (require_once 'vendor/autoload.php');
set_time_limit(0);
$app = new SilexApplication();
$cli = true;
require_once 'app/bootstrap.php';
$console = new ConsoleApplication('Silex - Rest API Edition', '1.0');
$console->getDefinition()->addOption(new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', 'dev'));
$command = new CacheClearCommand();
$command->setCachePath($app['cache.path']);
$console->add($command);
$command = new LogClearCommand();
$command->setLogPath($app['log.path']);
$console->add($command);
$command = new DocsCreateCommand();
$command->setApplicationPath($app['app.path']);
$console->add($command);
/*
* Doctrine CLI
*/
$helperSet = new HelperSet(array('db' => new ConnectionHelper($app['orm.em']->getConnection()), 'em' => new EntityManagerHelper($app['orm.em'])));
$console->setHelperSet($helperSet);
ConsoleRunner::addCommands($console);
$console->run();
示例12: registerCommands
/**
* @param OutputInterface $output
*/
protected function registerCommands(OutputInterface $output)
{
//Wrap database related logic in a try-catch
//so that non-db commands can still execute
try {
$em = $this->kernel->getContainer()->get('models');
// setup doctrine commands
$helperSet = $this->getHelperSet();
$helperSet->set(new EntityManagerHelper($em), 'em');
$helperSet->set(new ConnectionHelper($em->getConnection()), 'db');
DoctrineConsoleRunner::addCommands($this);
$this->registerEventCommands();
} catch (\Exception $e) {
$formatter = $this->getHelperSet()->get('formatter');
$output->writeln($formatter->formatBlock('WARNING! ' . $e->getMessage() . " in " . $e->getFile(), 'error'));
}
$this->registerFilesystemCommands();
}
示例13: HelperSet
case 'yml':
case 'yaml':
//$driver = new YamlDriver( $mappingPaths );
//$driver->setFileExtension('.yml');
$ymlConfig = Setup::createYAMLMetadataConfiguration($mappingPaths, $env == 'dev');
//$ymlConfig->setMetadataDriverImpl( $driver );
$entityManager = EntityManager::create($dbParams, $ymlConfig);
break;
case 'annotation':
$annotationConfig = Setup::createAnnotationMetadataConfiguration($mappingPaths, $env == 'dev');
$entityManager = EntityManager::create($dbParams, $annotationConfig);
break;
default:
throw new \Exception("Config: Unknown mapping type of '{$mappingType}'.");
}
if (empty($entityManager)) {
throw new \Exception("Config: Unable to instantiate an entity manager. Please check the configuration.");
}
$helperSet = new HelperSet(array('db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($entityManager->getConnection()), 'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($entityManager)));
$app = new DoctrineConsole();
$app->setCatchExceptions(false);
$app->setDispatcher($dispatcher);
$app->setHelperSet($helperSet);
ConsoleRunner::addCommands($app);
$commands = array(new \Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\LatestCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand(), new \Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand());
$app->addCommands($commands);
$app->run();
} catch (\Exception $e) {
$output = new \Symfony\Component\Console\Output\ConsoleOutput();
$app->renderException($e, $output->getErrorOutput());
}
示例14: runConsole
/**
* @return RZ\Roadiz\Core\Kernel $this
*/
public function runConsole()
{
/*
* Define a request wide timezone
*/
if (!empty($this->container['config']["timezone"])) {
date_default_timezone_set($this->container['config']["timezone"]);
} else {
date_default_timezone_set("Europe/Paris");
}
$application = new Application('Roadiz Console Application', static::$cmsVersion);
$helperSet = new HelperSet(['configuration' => new ConfigurationHelper($this->container['config']), 'db' => new ConnectionHelper($this->container['em']->getConnection()), 'em' => new EntityManagerHelper($this->container['em']), 'question' => new QuestionHelper(), 'solr' => new SolrHelper($this->container['solr']), 'ns-cache' => new CacheProviderHelper($this->container['nodesSourcesUrlCacheProvider']), 'mailer' => new MailerHelper($this->container['mailer']), 'templating' => new TemplatingHelper($this->container['twig.environment']), 'translator' => new TranslatorHelper($this->container['translator'])]);
$application->setHelperSet($helperSet);
$application->add(new \RZ\Roadiz\Console\TranslationsCommand());
$application->add(new \RZ\Roadiz\Console\NodeTypesCommand());
$application->add(new \RZ\Roadiz\Console\NodesSourcesCommand());
$application->add(new \RZ\Roadiz\Console\NodesCommand());
$application->add(new \RZ\Roadiz\Console\ThemesCommand());
$application->add(new \RZ\Roadiz\Console\InstallCommand());
$application->add(new \RZ\Roadiz\Console\UsersCommand());
$application->add(new \RZ\Roadiz\Console\RequirementsCommand());
$application->add(new \RZ\Roadiz\Console\SolrCommand());
$application->add(new \RZ\Roadiz\Console\CacheCommand());
$application->add(new \RZ\Roadiz\Console\ConfigurationCommand());
$application->add(new \RZ\Roadiz\Console\ThemeInstallCommand());
$application->add(new \RZ\Roadiz\Console\DocumentDownscaleCommand());
/*
* Register user defined Commands
* Add them in your config.yml
*/
if (isset($this->container['config']['additionalCommands'])) {
foreach ($this->container['config']['additionalCommands'] as $commandClass) {
if (class_exists($commandClass)) {
$application->add(new $commandClass());
} else {
throw new \Exception("Command class does not exists (" . $commandClass . ")", 1);
}
}
}
// Use default Doctrine commands
ConsoleRunner::addCommands($application);
$application->run();
$this->container['stopwatch']->stop('global');
return $this;
}
示例15: registerCommands
protected function registerCommands()
{
//Wrap database related logic in a try-catch
//so that non-db commands can still execute
try {
$em = $this->kernel->getContainer()->get('models');
// setup doctrine commands
$helperSet = $this->getHelperSet();
$helperSet->set(new EntityManagerHelper($em), 'em');
$helperSet->set(new ConnectionHelper($em->getConnection()), 'db');
DoctrineConsoleRunner::addCommands($this);
$this->registerEventCommands();
} catch (\Exception $e) {
}
$this->registerFilesystemCommands();
}