namespace Symfony\Component\Console\Command;
+use Symfony\Component\Console\Application;
use Symfony\Component\Console\Exception\ExceptionInterface;
-use Symfony\Component\Console\Input\InputDefinition;
-use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Exception\InvalidArgumentException;
+use Symfony\Component\Console\Exception\LogicException;
+use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
-use Symfony\Component\Console\Application;
-use Symfony\Component\Console\Helper\HelperSet;
-use Symfony\Component\Console\Exception\InvalidArgumentException;
-use Symfony\Component\Console\Exception\LogicException;
/**
* Base class for all commands.
*/
public static function getDefaultName()
{
- $class = get_called_class();
+ $class = \get_called_class();
$r = new \ReflectionProperty($class, 'defaultName');
return $class === $r->class ? static::$defaultName : null;
* execute() method, you set the code to execute by passing
* a Closure to the setCode() method.
*
- * @return null|int null or 0 if everything went fine, or an error code
+ * @return int|null null or 0 if everything went fine, or an error code
*
* @throws LogicException When this abstract method is not implemented
*
}
/**
- * Initializes the command just after the input has been validated.
+ * Initializes the command after the input has been bound and before the input
+ * is validated.
*
* This is mainly useful when a lot of commands extends one main command
* where some things need to be initialized based on the input arguments and options.
+ *
+ * @see InputInterface::bind()
+ * @see InputInterface::validate()
*/
protected function initialize(InputInterface $input, OutputInterface $output)
{
$this->initialize($input, $output);
if (null !== $this->processTitle) {
- if (function_exists('cli_set_process_title')) {
+ if (\function_exists('cli_set_process_title')) {
if (!@cli_set_process_title($this->processTitle)) {
if ('Darwin' === PHP_OS) {
- $output->writeln('<comment>Running "cli_get_process_title" as an unprivileged user is not supported on MacOS.</comment>');
+ $output->writeln('<comment>Running "cli_set_process_title" as an unprivileged user is not supported on MacOS.</comment>', OutputInterface::VERBOSITY_VERY_VERBOSE);
} else {
cli_set_process_title($this->processTitle);
}
}
- } elseif (function_exists('setproctitle')) {
+ } elseif (\function_exists('setproctitle')) {
setproctitle($this->processTitle);
} elseif (OutputInterface::VERBOSITY_VERY_VERBOSE === $output->getVerbosity()) {
$output->writeln('<comment>Install the proctitle PECL to be able to change the process title.</comment>');
$input->validate();
if ($this->code) {
- $statusCode = call_user_func($this->code, $input, $output);
+ $statusCode = \call_user_func($this->code, $input, $output);
} else {
$statusCode = $this->execute($input, $output);
}
$this->definition->addOptions($this->application->getDefinition()->getOptions());
+ $this->applicationDefinitionMerged = true;
+
if ($mergeArgs) {
$currentArguments = $this->definition->getArguments();
$this->definition->setArguments($this->application->getDefinition()->getArguments());
$this->definition->addArguments($currentArguments);
- }
- $this->applicationDefinitionMerged = true;
- if ($mergeArgs) {
$this->applicationDefinitionMergedWithArgs = true;
}
}
/**
* Adds an argument.
*
- * @param string $name The argument name
- * @param int $mode The argument mode: InputArgument::REQUIRED or InputArgument::OPTIONAL
- * @param string $description A description text
- * @param mixed $default The default value (for InputArgument::OPTIONAL mode only)
+ * @param string $name The argument name
+ * @param int|null $mode The argument mode: self::REQUIRED or self::OPTIONAL
+ * @param string $description A description text
+ * @param string|string[]|null $default The default value (for self::OPTIONAL mode only)
+ *
+ * @throws InvalidArgumentException When argument mode is not valid
*
* @return $this
*/
/**
* Adds an option.
*
- * @param string $name The option name
- * @param string $shortcut The shortcut (can be null)
- * @param int $mode The option mode: One of the InputOption::VALUE_* constants
- * @param string $description A description text
- * @param mixed $default The default value (must be null for InputOption::VALUE_NONE)
+ * @param string $name The option name
+ * @param string|array $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts
+ * @param int|null $mode The option mode: One of the VALUE_* constants
+ * @param string $description A description text
+ * @param string|string[]|bool|null $default The default value (must be null for self::VALUE_NONE)
+ *
+ * @throws InvalidArgumentException If option mode is invalid or incompatible
*
* @return $this
*/
*/
public function setAliases($aliases)
{
- if (!is_array($aliases) && !$aliases instanceof \Traversable) {
+ if (!\is_array($aliases) && !$aliases instanceof \Traversable) {
throw new InvalidArgumentException('$aliases must be an array or an instance of \Traversable');
}