本文整理汇总了PHP中Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand类的典型用法代码示例。如果您正苦于以下问题:PHP ContainerAwareCommand类的具体用法?PHP ContainerAwareCommand怎么用?PHP ContainerAwareCommand使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ContainerAwareCommand类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* @param ContainerAwareCommand $command A ContainerAwareCommand instance to test
* @param ContainerInterface $container The container to be injected in the command to test
*/
public function __construct(ContainerAwareCommand $command, ContainerInterface $container)
{
$application = new Application('Paraunit Command Test: ' . $command->getName());
$application->add($command);
$this->container = $container;
$command->setContainer($container);
parent::__construct($command);
}
示例2: executeCommand
/**
* Executes specified command.
*
* @param ContainerAwareCommand $commandInstance
* @param string $commandNamespace
* @param array $parameters
*
* @return CommandTester
*/
protected function executeCommand(ContainerAwareCommand $commandInstance, $commandNamespace, array $parameters = [])
{
$application = new Application(self::createClient()->getKernel());
$commandInstance->setContainer($this->getServiceContainer());
$application->add($commandInstance);
$command = $application->find($commandNamespace);
$commandTester = new CommandTester($command);
$commandTester->execute(array_merge_recursive(['command' => $command->getName()], $parameters));
return $commandTester;
}
示例3: testExecute
/**
* Check command execute.
*/
public function testExecute()
{
// Parameter was not set, so it has no value.
$this->commandTester->execute(['command' => $this->command->getName(), 'parameter' => 'test1']);
$this->assertContains('Parameter `test1`: has no value.', $this->commandTester->getDisplay());
$this->assertContains('If you want to write new value, use --set="<new value>" option.', $this->commandTester->getDisplay());
// Set some value, and test if it was set and returned.
$value = '2014-01-01 01:01:01';
$this->commandTester->execute(['command' => $this->command->getName(), 'parameter' => 'test1', '--set' => $value]);
$this->assertContains('New value written:', $this->commandTester->getDisplay());
/** @var Repository $repo */
$repo = $this->manager->getRepository('ONGRConnectionsBundle:Pair');
$parameter = $repo->find('test1');
$this->assertEquals($value, $parameter->getValue());
}
示例4: setContainer
/**
* Set the service container, and initialize the command.
*
* @param ContainerInterface $container
*/
public function setContainer(ContainerInterface $container = null)
{
parent::setContainer($container);
$this->templating = $container->get('templating');
$this->logger = $container->get('logger');
$this->em = $container->get('doctrine')->getManager();
}
示例5: configure
public function configure()
{
parent::configure();
$this->setName('partkeepr:user:protect');
$this->setDescription("Protects a given user against changes");
$this->addArgument("username", InputArgument::REQUIRED, "The username to protect against changes");
}
示例6: initialize
protected function initialize(InputInterface $input, OutputInterface $output)
{
parent::initialize($input, $output);
$this->targetPath = $input->getOption('target') ?: sprintf('%s/../web/js/fos_js_routes.js', $this->getContainer()->getParameter('kernel.root_dir'));
$this->extractor = $this->getContainer()->get('fos_js_routing.extractor');
$this->serializer = $this->getContainer()->get('fos_js_routing.serializer');
}
示例7: initialize
/**
* Initialize Connections
* @param InputInterface $input input
* @param OutputInterface $output output
*/
protected function initialize(InputInterface $input, OutputInterface $output)
{
parent::initialize($input, $output);
$this->container = $this->getContainer();
$this->classification = $this->container->get('consult.classification');
$this->wordManager = $this->container->get('consult.word_manager');
}
示例8: execute
/**
* 呼び出し元のコントローラーから呼び出すモデルを判定しrun()を実行します。
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
// 実行中チェック
$name = sprintf('%s.%s', $this->getName(), $input->getArgument('service'));
$this->getContainer()->get('lib.command.manager')->createExecuting($name);
$serviceName = $input->getArgument('service');
$controllerClass = get_class($this);
// サービスのディレクトリ
$serviceDir = preg_replace('/Command$/', '', basename(str_replace('\\', '/', $controllerClass)));
// サービスのクラス名
$clazz = '';
foreach (explode('-', $serviceName) as $_word) {
$clazz .= ucwords($_word);
}
if ($clazz === '') {
throw new IllegalArgumentException('serviceが指定されていません。');
}
$tmp = sprintf('Service\\%s\\%s', $serviceDir, $clazz);
$classPath = preg_replace('/Command.*Command$/', $tmp, $controllerClass);
$service = new $classPath(parent::getContainer(), $this, $input, $output);
if (is_null($service)) {
throw new \ErrorException('Service is not found.');
}
$response = $service->run();
// 実行中チェックを削除
$this->getContainer()->get('lib.command.manager')->removeExecuting($name);
return $response;
}
示例9: isEnabled
/**
* {@inheritdoc}
*/
public function isEnabled()
{
if (!class_exists('Symfony\\Component\\Translation\\Translator')) {
return false;
}
return parent::isEnabled();
}
示例10: isEnabled
/**
* {@inheritdoc}
*/
public function isEnabled()
{
if (version_compare(phpversion(), '5.4.0', '<')) {
return false;
}
return parent::isEnabled();
}
示例11: getHelp
/**
* {@inheritdoc}
*/
public function getHelp()
{
$help = parent::getHelp();
if (null !== $help) {
return $help;
}
/** @var $generators \PhpCollection\Map */
$generators = $this->getContainer()->get('sp_fixture_dumper.generators_map');
$help = <<<EOT
The <info>%1\$s</info> command dumps fixtures to a directory from your existing entities/documents:
<info>./app/console %1\$s /path/to/fixtures</info>
The path argument can include parameters (like <info>%%kernel.root_dir%%</info>) and you can use
the bundle annotation (<info>@AcmeDemoBundle/DataFixtures/Fixtures</info>)
If you want to put all fixtures in one file you can use the <info>--single-file</info> option:
<info>./app/console %1\$s --path=/path/to/fixtures --single-file</info>
You can also use different formats for the dumped fixtures (Available formats: <comment>%2\$s</comment>)
<info>./app/console %1\$s --format=yml --single-file /path/to/fixtures</info>
Some formats require you to enter extra options, like the <comment>class</comment> format where
you have to specify the namespace.
EOT;
return sprintf($help, $this->getName(), implode(', ', $generators->keys()));
}
示例12: isEnabled
/**
* {@inheritdoc}
*/
public function isEnabled()
{
if (!$this->getContainer()->has('security.acl.dbal.connection')) {
return false;
}
return parent::isEnabled();
}
示例13: isEnabled
/**
* {@inheritdoc}
*/
public function isEnabled()
{
if (defined('HHVM_VERSION')) {
return false;
}
return parent::isEnabled();
}
示例14: configure
protected function configure()
{
parent::configure();
$this->setName('debug:rpc_router');
$this->setDescription('Display essential info about RPC routing');
$this->addOption('endpoint', 'p', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'Filter endpoint', null);
}
示例15: __construct
public function __construct(SessionManagerInterface $sessionManager, SessionInterface $defaultSession, SessionInterface $liveSession)
{
$this->sessionManager = $sessionManager;
$this->defaultSession = $defaultSession;
$this->liveSession = $liveSession;
parent::__construct();
}