本文整理汇总了PHP中Symfony\Component\Console\Command\Command::getHelperSet方法的典型用法代码示例。如果您正苦于以下问题:PHP Command::getHelperSet方法的具体用法?PHP Command::getHelperSet怎么用?PHP Command::getHelperSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Console\Command\Command
的用法示例。
在下文中一共展示了Command::getHelperSet方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: mockQuestionHelper
/**
* Mocks question helper.
*/
protected function mockQuestionHelper()
{
$question_helper = $this->createMock('Symfony\\Component\\Console\\Helper\\QuestionHelper');
foreach ($this->answers as $key => $answer) {
// @TODO: Figure out where this key ofset comes from.
$question_helper->expects($this->at($key + 2))->method('ask')->willReturn($answer);
}
// We override the question helper with our mock.
$this->command->getHelperSet()->set($question_helper, 'question');
}
示例2: postInstall
public static function postInstall(Event $event)
{
// Check if npm is installed
exec('hash npm 2>/dev/null || { exit 1; }', $result, $returnVar);
$npmInstalled = $returnVar == 0 ? true : false;
if ($npmInstalled === true) {
// Instantiate the Command
$command = new Command('post-create');
$command->setApplication(new Application());
// Load the dialog helper
$dialog = $command->getHelperSet()->get('dialog');
// Write output to the console
$output = new ConsoleOutput();
if ($dialog->askConfirmation($output, "\n<info>Install Gulp and it's dependencies?</info> [<comment>Y,n</comment>]? ", false)) {
// Check if npm is installed
exec('hash gulp 2>/dev/null || { exit 1; }', $out, $returnVar);
$gulpInstalled = $returnVar == 0 ? true : false;
if ($gulpInstalled === false) {
$output->writeln("\n<info>Installing Gulp</info>\n");
$output->writeln("\$ sudo npm install -g gulp\n");
exec('sudo npm install -g gulp');
}
$output->writeln("\n<info>Installing dependencies</info>\n");
$output->writeln("\$ npm install\n");
exec('npm install');
return;
}
}
}
示例3: getCommandTester
/**
* @param Command $command
* @param HelperInterface[] $helpers
* @return CommandTester
*/
protected function getCommandTester(Command $command, array $helpers = [])
{
if (!empty($helpers)) {
foreach ($helpers as $helper) {
if ($helper instanceof HelperInterface) {
$command->getHelperSet()->set($helper, $helper->getName());
} else {
throw new \InvalidArgumentException('Cannot create CommandTester because a given helper is not an instance of HelperInterface.');
}
}
}
return new CommandTester($command);
}
示例4: createPlayerDialog
public function createPlayerDialog(Command $command, OutputInterface $output)
{
/** @var $dialog DialogHelper */
$dialog = $command->getHelperSet()->get("dialog");
/** @var $translations TranslationsHelperInterface */
$translations = $command->getHelper("translations");
$player = new PlayerDataHelper();
$player->name = $dialog->ask($output, $translations->getLine("player_name") . ": ");
$player->sex = $dialog->ask($output, $translations->getLine("player_sex_cmd") . ": ");
$player->class = $dialog->ask($output, $translations->getLine("player_class_cmd") . ": ");
$player->race = $dialog->ask($output, $translations->getLine("player_race_cmd") . ": ");
return $player;
}
示例5: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
if (!parent::getHelperSet()->has('link.connection')) {
throw new \BadMethodCallException('You MUST provide a connection helper to run this command.');
}
/** @var Connection $connection */
$connection = parent::getHelper('link.connection')->getConnection();
$dest = parent::getHelperSet()->has('link.destination') ? $this->getDestinationHelper()->getDestination() : $input->getArgument('destination');
$klass = str_replace('/', '\\', $input->getArgument('entity'));
$entityName = substr($klass, strrpos($klass, '\\') + 1);
$reader = new SqlReader(StringUtil::pluralize(strtolower($entityName)), $connection);
$relations = [];
foreach ($reader->getConstraints() as $constraint) {
if (!$constraint instanceof ForeignKeyConstraint) {
continue;
}
$relations = array_merge($relations, array_map(function (ColumnInterface $column) {
return $column->getField();
}, $constraint->getColumns()));
}
$classBuilder = ClassBuilder::create($entityName, null, substr($klass, 0, strrpos($klass, '\\')))->extends(Entity::class);
$commentBuilder = BlockCommentBuilder::create();
foreach ($reader->getColumns() as $column) {
if (in_array($column->getField(), $relations)) {
continue;
}
$retType = ColumnTypeHelper::toPhpType($column->getType());
$commentBuilder->addDocMethod($this->buildGetterName($column, $retType), false, [$retType]);
if ($column->getField() !== 'id') {
$field = StringUtil::classify($column->getField());
$commentBuilder->addDocMethod('set' . $field, false, ['$this'], [lcfirst($field) => ColumnTypeHelper::toPhpType($column->getType(), null)]);
}
}
if (sizeof($relations) > 0) {
$output->writeln(['<comment>This entity has foreign keys, which means it probably relates another entity (or ', 'entities) in your application. I cannot generate them, so you will need to add them yourself. ', 'Please see https://goo.gl/dFvGYo for information on how to do this.', '</>']);
}
$classBuilder->comment($commentBuilder->build());
if (!file_exists($dest)) {
mkdir($dest, 0755, true);
}
if (file_exists($filePath = $dest . $entityName . '.php') && !$input->getOption('force')) {
throw new \InvalidArgumentException('File already exists at ' . $dest);
}
$result = file_put_contents($filePath, '<?php' . PHP_EOL . $classBuilder->build()->build(1));
if ($result) {
$output->writeln('<info>Generated class written to ' . $filePath . '</>');
} else {
$output->writeln('<error>Could not write to ' . $filePath . '</>');
}
}
示例6: doRunCommand
/**
* Runs the current command.
*
* If an event dispatcher has been attached to the application,
* events are also dispatched during the life-cycle of the command.
*
* @param Command $command A Command instance
* @param InputInterface $input An Input instance
* @param OutputInterface $output An Output instance
*
* @return int 0 if everything went fine, or an error code
*/
protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output)
{
foreach ($command->getHelperSet() as $helper) {
if ($helper instanceof InputAwareInterface) {
$helper->setInput($input);
}
}
if (null === $this->dispatcher) {
return $command->run($input, $output);
}
$event = new ConsoleCommandEvent($command, $input, $output);
$this->dispatcher->dispatch(ConsoleEvents::COMMAND, $event);
try {
$exitCode = $command->run($input, $output);
} catch (\Exception $e) {
$event = new ConsoleTerminateEvent($command, $input, $output, $e->getCode());
$this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event);
$event = new ConsoleExceptionEvent($command, $input, $output, $e, $event->getExitCode());
$this->dispatcher->dispatch(ConsoleEvents::EXCEPTION, $event);
throw $event->getException();
}
$event = new ConsoleTerminateEvent($command, $input, $output, $exitCode);
$this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event);
return $event->getExitCode();
}
示例7: doRunCommand
/**
* Runs the current command.
*
* If an event dispatcher has been attached to the application,
* events are also dispatched during the life-cycle of the command.
*
* @param Command $command A Command instance
* @param InputInterface $input An Input instance
* @param OutputInterface $output An Output instance
*
* @return int 0 if everything went fine, or an error code
*
* @throws \Exception when the command being run threw an exception
*/
protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output)
{
foreach ($command->getHelperSet() as $helper) {
if ($helper instanceof InputAwareInterface) {
$helper->setInput($input);
}
}
if (null === $this->dispatcher) {
return $command->run($input, $output);
}
// bind before the console.command event, so the listeners have access to input options/arguments
try {
$command->mergeApplicationDefinition();
$input->bind($command->getDefinition());
} catch (ExceptionInterface $e) {
// ignore invalid options/arguments for now, to allow the event listeners to customize the InputDefinition
}
$event = new ConsoleCommandEvent($command, $input, $output);
$this->dispatcher->dispatch(ConsoleEvents::COMMAND, $event);
if ($event->commandShouldRun()) {
try {
$exitCode = $command->run($input, $output);
} catch (\Exception $e) {
$event = new ConsoleExceptionEvent($command, $input, $output, $e, $e->getCode());
$this->dispatcher->dispatch(ConsoleEvents::EXCEPTION, $event);
$e = $event->getException();
$event = new ConsoleTerminateEvent($command, $input, $output, $e->getCode());
$this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event);
throw $e;
}
} else {
$exitCode = ConsoleCommandEvent::RETURN_CODE_DISABLED;
}
$event = new ConsoleTerminateEvent($command, $input, $output, $exitCode);
$this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event);
return $event->getExitCode();
}
示例8: getHelperSet
/**
* {@inheritdoc}
*/
public function getHelperSet()
{
return $this->decoratedCommand->getHelperSet();
}
示例9: doRunCommand
/**
* {@inheritdoc}
*/
protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output)
{
$helperSet = $command->getHelperSet();
foreach ($helperSet as $helper) {
if ($helper instanceof OutputAwareInterface) {
$helper->setOutput($output);
}
if ($helper instanceof InputAwareInterface) {
$helper->setInput($input);
}
}
$event = new ConsoleCommandEvent($command, $input, $output);
$this->dispatcher->dispatch(ConsoleEvents::COMMAND, $event);
try {
$exitCode = $command->run($input, $output);
} catch (\Exception $e) {
$event = new ConsoleTerminateEvent($command, $input, $output, $e->getCode());
$this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event);
$event = new ConsoleExceptionEvent($command, $input, $output, $e, $event->getExitCode());
$this->dispatcher->dispatch(ConsoleEvents::EXCEPTION, $event);
if ($e instanceof UserException) {
$this->getHelperSet()->get('gush_style')->error($e->getMessages());
if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
throw $e;
}
return $event->getExitCode();
} else {
throw $event->getException();
}
}
$event = new ConsoleTerminateEvent($command, $input, $output, $exitCode);
$this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event);
return $event->getExitCode();
}
示例10: getHelperSet
public function getHelperSet()
{
return $this->innerCommand->getHelperSet();
}
示例11: mockDialogHelper
/**
* @param Command $command
*/
private function mockDialogHelper(Command $command)
{
$mockBuilder = $this->getMockBuilder(\Symfony\Component\Console\Helper\QuestionHelper::class);
$mockBuilder->setMethods(['ask']);
$helperMock = $mockBuilder->getMock();
$helperMock->method('ask')->willReturn(true);
$command->getHelperSet()->set($helperMock, 'question');
}
示例12: doRunCommand
protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output)
{
foreach ($command->getHelperSet() as $helper) {
if ($helper instanceof InputAwareInterface) {
$helper->setInput($input);
}
}
if (null === $this->dispatcher) {
return $command->run($input, $output);
}
try {
$command->mergeApplicationDefinition();
$input->bind($command->getDefinition());
} catch (ExceptionInterface $e) {
}
$event = new ConsoleCommandEvent($command, $input, $output);
$this->dispatcher->dispatch(ConsoleEvents::COMMAND, $event);
if ($event->commandShouldRun()) {
try {
$exitCode = $command->run($input, $output);
} catch (\Exception $e) {
$event = new ConsoleExceptionEvent($command, $input, $output, $e, $e->getCode());
$this->dispatcher->dispatch(ConsoleEvents::EXCEPTION, $event);
$e = $event->getException();
$event = new ConsoleTerminateEvent($command, $input, $output, $e->getCode());
$this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event);
throw $e;
}
} else {
$exitCode = ConsoleCommandEvent::RETURN_CODE_DISABLED;
}
$event = new ConsoleTerminateEvent($command, $input, $output, $exitCode);
$this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event);
return $event->getExitCode();
}
示例13: __construct
/**
* Render the table and pass the output back.
* This is done this way because the table
* helper dumps everything to the output and
* there is no way to catch so have to override
* with a special output.
*
* @param Command $command
* @return void
*/
public function __construct(Command $command)
{
$this->table = $command->getHelperSet()->get('table');
$this->table->setCellHeaderFormat('<pop>%s</pop>');
$this->output = new CatchOutput();
}
示例14: mockQuestionHelper
/**
* @param Command $cmd Symfony question to ask
* @param callable $mockQuestionHandler anonymous function to handle the asked questions
*
* @since 0.1.0 2015-05-20
*/
function mockQuestionHelper(Command $cmd, callable $mockQuestionHandler)
{
$helper = new QuestionHelperMock();
$helper->setMockQuestionHandler($mockQuestionHandler);
$cmd->getHelperSet()->set($helper, 'question');
}