Skip to content

Commit

Permalink
Stubbing out new @Calls annotation.
Browse files Browse the repository at this point in the history
  • Loading branch information
grasmash committed Jan 17, 2017
1 parent f8567e3 commit 2647005
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/AnnotatedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
*/
class AnnotatedCommand extends Command implements HelpDocumentAlter
{
protected $calls = [];
protected $commandCallback;
protected $commandProcessor;
protected $annotationData;
Expand Down Expand Up @@ -120,8 +121,20 @@ public function setTopics($topics)
return $this;
}

public function getCalls()
{
return $this->calls;
}

public function setCalls($calls)
{
$this->calls = $calls;
return $this;
}

public function setCommandInfo($commandInfo)
{
$this->setCalls($commandInfo->getCalls());
$this->setDescription($commandInfo->getDescription());
$this->setHelp($commandInfo->getHelp());
$this->setAliases($commandInfo->getAliases());
Expand Down Expand Up @@ -376,11 +389,23 @@ protected function initialize(InputInterface $input, OutputInterface $output)
$this->commandProcessor()->initializeHook($input, $this->getNames(), $this->annotationData);
}

protected function executeCallsCommands() {
if ($this->getCalls()) {
foreach ($this->getCalls as $command_name) {
// @todo validate that $command_name exists in this application.
// @todo Execute command.
// @todo On failure, return exit code of called command.
}
}
}

/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
// @todo Call $this->executeCallsCommands();

// Validate, run, process, alter, handle results.
return $this->commandProcessor()->process(
$output,
Expand Down
24 changes: 24 additions & 0 deletions src/Parser/CommandInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ class CommandInfo
*/
protected $optionParamName;

/**
* @var array
*/
protected $calls = [];

/**
* Create a new CommandInfo class for a particular method of a class.
*
Expand Down Expand Up @@ -333,6 +338,25 @@ public function getTopics()
return explode(',', trim($topics));
}

/**
* Returns an array of commands that this command calls.
*
* @return string[]
*/
public function getCalls()
{
return $this->calls;
}

public function setCalls($calls) {
if (is_string($calls)) {
$calls = explode(',', static::convertListToCommaSeparated($calls));
}
$this->calls = array_filter($calls);

return $this;
}

/**
* Return the list of refleaction parameters.
*
Expand Down
9 changes: 9 additions & 0 deletions src/Parser/Internal/AbstractCommandDocBlockParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ abstract class AbstractCommandDocBlockParser
'usage' => 'processUsageTag',
'description' => 'processAlternateDescriptionTag',
'desc' => 'processAlternateDescriptionTag',
'calls' => 'processCalls',
];

public function __construct(CommandInfo $commandInfo, \ReflectionMethod $reflection)
Expand Down Expand Up @@ -168,6 +169,14 @@ protected function processAliases($tag)
$this->commandInfo->setAliases((string)$tag->getDescription());
}

/**
* Process the comma-separated list of commands to call.
*/
protected function processCalls($tag)
{
$this->commandInfo->setCalls((string)$tag->getDescription());
}

/**
* Store the data from a @param annotation in our argument descriptions.
*/
Expand Down

0 comments on commit 2647005

Please sign in to comment.