PHPDoc for Console

This commit is contained in:
Tim Nagel 2011-02-06 16:34:24 -08:00 committed by Fabien Potencier
parent 4252680ccf
commit f3b6e1a30c
9 changed files with 85 additions and 6 deletions

View File

@ -201,7 +201,7 @@ class Application
}
/**
* Get the helper set associated with the command
* Get the helper set associated with the command.
*
* @return HelperSet The HelperSet instance associated with this command
*/
@ -396,7 +396,7 @@ class Application
}
/**
* Returns true if the command exists, false otherwise
* Returns true if the command exists, false otherwise.
*
* @param string $name The command name or alias
*
@ -429,6 +429,8 @@ class Application
/**
* Finds a registered namespace by a name or an abbreviation.
*
* @param string $namespace A namespace or abbreviation to search for
*
* @return string A registered namespace
*
* @throws \InvalidArgumentException When namespace is incorrect or ambiguous
@ -715,11 +717,25 @@ class Application
}
}
/**
* Gets the name of the command based on input.
*
* @param InputInterface $input The input interface
*
* @return string The command name
*/
protected function getCommandName(InputInterface $input)
{
return $input->getFirstArgument('command');
}
/**
* Sorts commands in alphabetical order.
*
* @param array $commands An associative array of commands to sort
*
* @return array A sorted array of commands
*/
protected function sortCommands($commands)
{
$namespacedCommands = array();
@ -741,6 +757,13 @@ class Application
return $namespacedCommands;
}
/**
* Returns abbreviated suggestions in string format.
*
* @param array $abbrevs Abbreviated suggestions to convert
*
* @return string A formatted string of abbreviated suggestions
*/
protected function getAbbreviationSuggestions($abbrevs)
{
return sprintf('%s, %s%s', $abbrevs[0], $abbrevs[1], count($abbrevs) > 2 ? sprintf(' and %d more', count($abbrevs) - 2) : '');

View File

@ -28,7 +28,7 @@ class HelpCommand extends Command
protected $command;
/**
* @see Command
* {@inheritdoc}
*/
protected function configure()
{
@ -54,13 +54,18 @@ EOF
);
}
/**
* Sets the command
*
* @param Command $command The command to set
*/
public function setCommand(Command $command)
{
$this->command = $command;
}
/**
* @see Command
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{

View File

@ -26,7 +26,7 @@ use Symfony\Component\Console\Command\Command;
class ListCommand extends Command
{
/**
* @see Command
* {@inheritdoc}
*/
protected function configure()
{
@ -54,7 +54,7 @@ EOF
}
/**
* @see Command
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{

View File

@ -67,6 +67,13 @@ class FormatterHelper extends Helper
return implode("\n", $messages);
}
/**
* Returns the length of a string, uses mb_strlen if it is available.
*
* @param string $string The string to check its length
*
* @return integer The length of the string
*/
protected function strlen($string)
{
return function_exists('mb_strlen') ? mb_strlen($string) : strlen($string);
@ -74,6 +81,8 @@ class FormatterHelper extends Helper
/**
* Returns the helper's canonical name
*
* @return string The canonical name of the helper
*/
public function getName()
{

View File

@ -64,6 +64,8 @@ abstract class Input implements InputInterface
abstract protected function parse();
/**
* Validates the input.
*
* @throws \RuntimeException When not enough arguments are given
*/
public function validate()
@ -73,11 +75,21 @@ abstract class Input implements InputInterface
}
}
/**
* Checks if the input is interactive.
*
* @return Boolean Returns true if the input is interactive
*/
public function isInteractive()
{
return $this->interactive;
}
/**
* Sets the input interactivity.
*
* @param Boolean $interactive If the input should be interactive
*/
public function setInteractive($interactive)
{
$this->interactive = (Boolean) $interactive;

View File

@ -42,6 +42,11 @@ class InputDefinition
$this->setDefinition($definition);
}
/**
* Sets the definition of the input.
*
* @param array $definition The definition array
*/
public function setDefinition(array $definition)
{
$arguments = array();
@ -297,6 +302,8 @@ class InputDefinition
/**
* Gets an InputOption by shortcut.
*
* @param string $shortcut the Shortcut name
*
* @return InputOption An InputOption object
*/
public function getOptionForShortcut($shortcut)

View File

@ -63,6 +63,7 @@ interface InputInterface
/**
* Get argument by name.
*
* @param string $name The name of the argument
* @return mixed
*/
function getArgument($name);
@ -72,6 +73,12 @@ interface InputInterface
*/
function getOptions();
/**
* Get an option by name.
*
* @param string $name The name of the option
* @return mixed
*/
function getOption($name);
/**

View File

@ -39,6 +39,9 @@ class StringInput extends ArgvInput
}
/**
* Tokenizes a string.
*
* @param string $input The input to tokenise
* @throws \InvalidArgumentException When unable to parse input (should never happen)
*/
protected function tokenize($input)

View File

@ -179,6 +179,12 @@ abstract class Output implements OutputInterface
}
/**
* Replaces the starting style of the output.
*
* @param array $match
*
* @return string The replaced style
*
* @throws \InvalidArgumentException When style is unknown
*/
protected function replaceStartStyle($match)
@ -220,6 +226,13 @@ abstract class Output implements OutputInterface
return "\033[".implode(';', $codes).'m';
}
/**
* Replaces the end style.
*
* @param string $match The text to match
*
* @return string The end style
*/
protected function replaceEndStyle($match)
{
if (!$this->decorated) {