feature #14894 [Console] Add domain exceptions to replace generic exceptions (GromNaN)
This PR was squashed before being merged into the 2.8 branch (closes #14894).
Discussion
----------
[Console] Add domain exceptions to replace generic exceptions
Creates domain specific exception classes for the case where a user type an invalid command name or option name.
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #14873
| License | MIT
| Doc PR | N/A
TODO:
* [x] Replace `\InvalidArgumentException` by `Symfony\Component\Console\Exception\InvalidArgumentException`
* [x] Add `Symfony\Component\Console\Exception\ExceptionInterface`
Commits
-------
dd17dc0
[Console] Add domain exceptions to replace generic exceptions
This commit is contained in:
commit
dacbfe9699
@ -38,6 +38,8 @@ use Symfony\Component\Console\Helper\TableHelper;
|
|||||||
use Symfony\Component\Console\Event\ConsoleCommandEvent;
|
use Symfony\Component\Console\Event\ConsoleCommandEvent;
|
||||||
use Symfony\Component\Console\Event\ConsoleExceptionEvent;
|
use Symfony\Component\Console\Event\ConsoleExceptionEvent;
|
||||||
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
|
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
|
||||||
|
use Symfony\Component\Console\Exception\CommandNotFoundException;
|
||||||
|
use Symfony\Component\Console\Exception\LogicException;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -392,7 +394,7 @@ class Application
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (null === $command->getDefinition()) {
|
if (null === $command->getDefinition()) {
|
||||||
throw new \LogicException(sprintf('Command class "%s" is not correctly initialized. You probably forgot to call the parent constructor.', get_class($command)));
|
throw new LogicException(sprintf('Command class "%s" is not correctly initialized. You probably forgot to call the parent constructor.', get_class($command)));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->commands[$command->getName()] = $command;
|
$this->commands[$command->getName()] = $command;
|
||||||
@ -411,14 +413,14 @@ class Application
|
|||||||
*
|
*
|
||||||
* @return Command A Command object
|
* @return Command A Command object
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException When command name given does not exist
|
* @throws CommandNotFoundException When command name given does not exist
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
public function get($name)
|
public function get($name)
|
||||||
{
|
{
|
||||||
if (!isset($this->commands[$name])) {
|
if (!isset($this->commands[$name])) {
|
||||||
throw new \InvalidArgumentException(sprintf('The command "%s" does not exist.', $name));
|
throw new CommandNotFoundException(sprintf('The command "%s" does not exist.', $name));
|
||||||
}
|
}
|
||||||
|
|
||||||
$command = $this->commands[$name];
|
$command = $this->commands[$name];
|
||||||
@ -477,7 +479,7 @@ class Application
|
|||||||
*
|
*
|
||||||
* @return string A registered namespace
|
* @return string A registered namespace
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException When namespace is incorrect or ambiguous
|
* @throws CommandNotFoundException When namespace is incorrect or ambiguous
|
||||||
*/
|
*/
|
||||||
public function findNamespace($namespace)
|
public function findNamespace($namespace)
|
||||||
{
|
{
|
||||||
@ -498,12 +500,12 @@ class Application
|
|||||||
$message .= implode("\n ", $alternatives);
|
$message .= implode("\n ", $alternatives);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new \InvalidArgumentException($message);
|
throw new CommandNotFoundException($message, $alternatives);
|
||||||
}
|
}
|
||||||
|
|
||||||
$exact = in_array($namespace, $namespaces, true);
|
$exact = in_array($namespace, $namespaces, true);
|
||||||
if (count($namespaces) > 1 && !$exact) {
|
if (count($namespaces) > 1 && !$exact) {
|
||||||
throw new \InvalidArgumentException(sprintf('The namespace "%s" is ambiguous (%s).', $namespace, $this->getAbbreviationSuggestions(array_values($namespaces))));
|
throw new CommandNotFoundException(sprintf('The namespace "%s" is ambiguous (%s).', $namespace, $this->getAbbreviationSuggestions(array_values($namespaces))), array_values($namespaces));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $exact ? $namespace : reset($namespaces);
|
return $exact ? $namespace : reset($namespaces);
|
||||||
@ -519,7 +521,7 @@ class Application
|
|||||||
*
|
*
|
||||||
* @return Command A Command instance
|
* @return Command A Command instance
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException When command name is incorrect or ambiguous
|
* @throws CommandNotFoundException When command name is incorrect or ambiguous
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@ -546,7 +548,7 @@ class Application
|
|||||||
$message .= implode("\n ", $alternatives);
|
$message .= implode("\n ", $alternatives);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new \InvalidArgumentException($message);
|
throw new CommandNotFoundException($message, $alternatives);
|
||||||
}
|
}
|
||||||
|
|
||||||
// filter out aliases for commands which are already on the list
|
// filter out aliases for commands which are already on the list
|
||||||
@ -563,7 +565,7 @@ class Application
|
|||||||
if (count($commands) > 1 && !$exact) {
|
if (count($commands) > 1 && !$exact) {
|
||||||
$suggestions = $this->getAbbreviationSuggestions(array_values($commands));
|
$suggestions = $this->getAbbreviationSuggestions(array_values($commands));
|
||||||
|
|
||||||
throw new \InvalidArgumentException(sprintf('Command "%s" is ambiguous (%s).', $name, $suggestions));
|
throw new CommandNotFoundException(sprintf('Command "%s" is ambiguous (%s).', $name, $suggestions), array_values($commands));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->get($exact ? $name : reset($commands));
|
return $this->get($exact ? $name : reset($commands));
|
||||||
|
@ -21,6 +21,8 @@ use Symfony\Component\Console\Output\BufferedOutput;
|
|||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Symfony\Component\Console\Application;
|
use Symfony\Component\Console\Application;
|
||||||
use Symfony\Component\Console\Helper\HelperSet;
|
use Symfony\Component\Console\Helper\HelperSet;
|
||||||
|
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
||||||
|
use Symfony\Component\Console\Exception\LogicException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for all commands.
|
* Base class for all commands.
|
||||||
@ -51,7 +53,7 @@ class Command
|
|||||||
*
|
*
|
||||||
* @param string|null $name The name of the command; passing null means it must be set in configure()
|
* @param string|null $name The name of the command; passing null means it must be set in configure()
|
||||||
*
|
*
|
||||||
* @throws \LogicException When the command name is empty
|
* @throws LogicException When the command name is empty
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@ -66,7 +68,7 @@ class Command
|
|||||||
$this->configure();
|
$this->configure();
|
||||||
|
|
||||||
if (!$this->name) {
|
if (!$this->name) {
|
||||||
throw new \LogicException(sprintf('The command defined in "%s" cannot have an empty name.', get_class($this)));
|
throw new LogicException(sprintf('The command defined in "%s" cannot have an empty name.', get_class($this)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,13 +164,13 @@ class Command
|
|||||||
*
|
*
|
||||||
* @return null|int null or 0 if everything went fine, or an error code
|
* @return null|int null or 0 if everything went fine, or an error code
|
||||||
*
|
*
|
||||||
* @throws \LogicException When this abstract method is not implemented
|
* @throws LogicException When this abstract method is not implemented
|
||||||
*
|
*
|
||||||
* @see setCode()
|
* @see setCode()
|
||||||
*/
|
*/
|
||||||
protected function execute(InputInterface $input, OutputInterface $output)
|
protected function execute(InputInterface $input, OutputInterface $output)
|
||||||
{
|
{
|
||||||
throw new \LogicException('You must override the execute() method in the concrete command class.');
|
throw new LogicException('You must override the execute() method in the concrete command class.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -272,7 +274,7 @@ class Command
|
|||||||
*
|
*
|
||||||
* @return Command The current instance
|
* @return Command The current instance
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*
|
*
|
||||||
* @see execute()
|
* @see execute()
|
||||||
*
|
*
|
||||||
@ -281,7 +283,7 @@ class Command
|
|||||||
public function setCode($code)
|
public function setCode($code)
|
||||||
{
|
{
|
||||||
if (!is_callable($code)) {
|
if (!is_callable($code)) {
|
||||||
throw new \InvalidArgumentException('Invalid callable provided to Command::setCode.');
|
throw new InvalidArgumentException('Invalid callable provided to Command::setCode.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PHP_VERSION_ID >= 50400 && $code instanceof \Closure) {
|
if (PHP_VERSION_ID >= 50400 && $code instanceof \Closure) {
|
||||||
@ -423,7 +425,7 @@ class Command
|
|||||||
*
|
*
|
||||||
* @return Command The current instance
|
* @return Command The current instance
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException When the name is invalid
|
* @throws InvalidArgumentException When the name is invalid
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@ -552,14 +554,14 @@ class Command
|
|||||||
*
|
*
|
||||||
* @return Command The current instance
|
* @return Command The current instance
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException When an alias is invalid
|
* @throws InvalidArgumentException When an alias is invalid
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
public function setAliases($aliases)
|
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');
|
throw new InvalidArgumentException('$aliases must be an array or an instance of \Traversable');
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($aliases as $alias) {
|
foreach ($aliases as $alias) {
|
||||||
@ -634,7 +636,7 @@ class Command
|
|||||||
*
|
*
|
||||||
* @return mixed The helper value
|
* @return mixed The helper value
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException if the helper is not defined
|
* @throws InvalidArgumentException if the helper is not defined
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@ -693,12 +695,12 @@ class Command
|
|||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException When the name is invalid
|
* @throws InvalidArgumentException When the name is invalid
|
||||||
*/
|
*/
|
||||||
private function validateName($name)
|
private function validateName($name)
|
||||||
{
|
{
|
||||||
if (!preg_match('/^[^\:]++(\:[^\:]++)*$/', $name)) {
|
if (!preg_match('/^[^\:]++(\:[^\:]++)*$/', $name)) {
|
||||||
throw new \InvalidArgumentException(sprintf('Command name "%s" is invalid.', $name));
|
throw new InvalidArgumentException(sprintf('Command name "%s" is invalid.', $name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ namespace Symfony\Component\Console\Descriptor;
|
|||||||
|
|
||||||
use Symfony\Component\Console\Application;
|
use Symfony\Component\Console\Application;
|
||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
use Symfony\Component\Console\Exception\CommandNotFoundException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
|
* @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
|
||||||
@ -89,12 +90,12 @@ class ApplicationDescription
|
|||||||
*
|
*
|
||||||
* @return Command
|
* @return Command
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException
|
* @throws CommandNotFoundException
|
||||||
*/
|
*/
|
||||||
public function getCommand($name)
|
public function getCommand($name)
|
||||||
{
|
{
|
||||||
if (!isset($this->commands[$name]) && !isset($this->aliases[$name])) {
|
if (!isset($this->commands[$name]) && !isset($this->aliases[$name])) {
|
||||||
throw new \InvalidArgumentException(sprintf('Command %s does not exist.', $name));
|
throw new CommandNotFoundException(sprintf('Command %s does not exist.', $name));
|
||||||
}
|
}
|
||||||
|
|
||||||
return isset($this->commands[$name]) ? $this->commands[$name] : $this->aliases[$name];
|
return isset($this->commands[$name]) ? $this->commands[$name] : $this->aliases[$name];
|
||||||
|
@ -17,6 +17,7 @@ use Symfony\Component\Console\Input\InputArgument;
|
|||||||
use Symfony\Component\Console\Input\InputDefinition;
|
use Symfony\Component\Console\Input\InputDefinition;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
|
* @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
|
||||||
@ -54,7 +55,7 @@ abstract class Descriptor implements DescriptorInterface
|
|||||||
$this->describeApplication($object, $options);
|
$this->describeApplication($object, $options);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new \InvalidArgumentException(sprintf('Object of type "%s" is not describable.', get_class($object)));
|
throw new InvalidArgumentException(sprintf('Object of type "%s" is not describable.', get_class($object)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Component\Console\Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents an incorrect command name typed in the console.
|
||||||
|
*
|
||||||
|
* @author Jérôme Tamarelle <jerome@tamarelle.net>
|
||||||
|
*/
|
||||||
|
class CommandNotFoundException extends \InvalidArgumentException implements ExceptionInterface
|
||||||
|
{
|
||||||
|
private $alternatives;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $message Exception message to throw.
|
||||||
|
* @param array $alternatives List of similar defined names.
|
||||||
|
* @param int $code Exception code.
|
||||||
|
* @param Exception $previous previous exception used for the exception chaining.
|
||||||
|
*/
|
||||||
|
public function __construct($message, array $alternatives = array(), $code = 0, \Exception $previous = null)
|
||||||
|
{
|
||||||
|
parent::__construct($message, $code, $previous);
|
||||||
|
|
||||||
|
$this->alternatives = $alternatives;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array A list of similar defined names.
|
||||||
|
*/
|
||||||
|
public function getAlternatives()
|
||||||
|
{
|
||||||
|
return $this->alternatives;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Component\Console\Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ExceptionInterface.
|
||||||
|
*
|
||||||
|
* @author Jérôme Tamarelle <jerome@tamarelle.net>
|
||||||
|
*
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
interface ExceptionInterface
|
||||||
|
{
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Component\Console\Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Jérôme Tamarelle <jerome@tamarelle.net>
|
||||||
|
*/
|
||||||
|
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
|
||||||
|
{
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Component\Console\Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents an incorrect option name typed in the console.
|
||||||
|
*
|
||||||
|
* @author Jérôme Tamarelle <jerome@tamarelle.net>
|
||||||
|
*/
|
||||||
|
class InvalidOptionException extends \InvalidArgumentException implements ExceptionInterface
|
||||||
|
{
|
||||||
|
}
|
19
src/Symfony/Component/Console/Exception/LogicException.php
Normal file
19
src/Symfony/Component/Console/Exception/LogicException.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Component\Console\Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Jérôme Tamarelle <jerome@tamarelle.net>
|
||||||
|
*/
|
||||||
|
class LogicException extends \LogicException implements ExceptionInterface
|
||||||
|
{
|
||||||
|
}
|
19
src/Symfony/Component/Console/Exception/RuntimeException.php
Normal file
19
src/Symfony/Component/Console/Exception/RuntimeException.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Component\Console\Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Jérôme Tamarelle <jerome@tamarelle.net>
|
||||||
|
*/
|
||||||
|
class RuntimeException extends \RuntimeException implements ExceptionInterface
|
||||||
|
{
|
||||||
|
}
|
@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Console\Formatter;
|
namespace Symfony\Component\Console\Formatter;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Formatter class for console output.
|
* Formatter class for console output.
|
||||||
*
|
*
|
||||||
@ -118,14 +120,14 @@ class OutputFormatter implements OutputFormatterInterface
|
|||||||
*
|
*
|
||||||
* @return OutputFormatterStyleInterface
|
* @return OutputFormatterStyleInterface
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException When style isn't defined
|
* @throws InvalidArgumentException When style isn't defined
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
public function getStyle($name)
|
public function getStyle($name)
|
||||||
{
|
{
|
||||||
if (!$this->hasStyle($name)) {
|
if (!$this->hasStyle($name)) {
|
||||||
throw new \InvalidArgumentException(sprintf('Undefined style: %s', $name));
|
throw new InvalidArgumentException(sprintf('Undefined style: %s', $name));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->styles[strtolower($name)];
|
return $this->styles[strtolower($name)];
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Console\Formatter;
|
namespace Symfony\Component\Console\Formatter;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Formatter style class for defining styles.
|
* Formatter style class for defining styles.
|
||||||
*
|
*
|
||||||
@ -81,7 +83,7 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface
|
|||||||
*
|
*
|
||||||
* @param string|null $color The color name
|
* @param string|null $color The color name
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException When the color name isn't defined
|
* @throws InvalidArgumentException When the color name isn't defined
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@ -94,7 +96,7 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!isset(static::$availableForegroundColors[$color])) {
|
if (!isset(static::$availableForegroundColors[$color])) {
|
||||||
throw new \InvalidArgumentException(sprintf(
|
throw new InvalidArgumentException(sprintf(
|
||||||
'Invalid foreground color specified: "%s". Expected one of (%s)',
|
'Invalid foreground color specified: "%s". Expected one of (%s)',
|
||||||
$color,
|
$color,
|
||||||
implode(', ', array_keys(static::$availableForegroundColors))
|
implode(', ', array_keys(static::$availableForegroundColors))
|
||||||
@ -109,7 +111,7 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface
|
|||||||
*
|
*
|
||||||
* @param string|null $color The color name
|
* @param string|null $color The color name
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException When the color name isn't defined
|
* @throws InvalidArgumentException When the color name isn't defined
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@ -122,7 +124,7 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!isset(static::$availableBackgroundColors[$color])) {
|
if (!isset(static::$availableBackgroundColors[$color])) {
|
||||||
throw new \InvalidArgumentException(sprintf(
|
throw new InvalidArgumentException(sprintf(
|
||||||
'Invalid background color specified: "%s". Expected one of (%s)',
|
'Invalid background color specified: "%s". Expected one of (%s)',
|
||||||
$color,
|
$color,
|
||||||
implode(', ', array_keys(static::$availableBackgroundColors))
|
implode(', ', array_keys(static::$availableBackgroundColors))
|
||||||
@ -137,14 +139,14 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface
|
|||||||
*
|
*
|
||||||
* @param string $option The option name
|
* @param string $option The option name
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException When the option name isn't defined
|
* @throws InvalidArgumentException When the option name isn't defined
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
public function setOption($option)
|
public function setOption($option)
|
||||||
{
|
{
|
||||||
if (!isset(static::$availableOptions[$option])) {
|
if (!isset(static::$availableOptions[$option])) {
|
||||||
throw new \InvalidArgumentException(sprintf(
|
throw new InvalidArgumentException(sprintf(
|
||||||
'Invalid option specified: "%s". Expected one of (%s)',
|
'Invalid option specified: "%s". Expected one of (%s)',
|
||||||
$option,
|
$option,
|
||||||
implode(', ', array_keys(static::$availableOptions))
|
implode(', ', array_keys(static::$availableOptions))
|
||||||
@ -161,12 +163,12 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface
|
|||||||
*
|
*
|
||||||
* @param string $option The option name
|
* @param string $option The option name
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException When the option name isn't defined
|
* @throws InvalidArgumentException When the option name isn't defined
|
||||||
*/
|
*/
|
||||||
public function unsetOption($option)
|
public function unsetOption($option)
|
||||||
{
|
{
|
||||||
if (!isset(static::$availableOptions[$option])) {
|
if (!isset(static::$availableOptions[$option])) {
|
||||||
throw new \InvalidArgumentException(sprintf(
|
throw new InvalidArgumentException(sprintf(
|
||||||
'Invalid option specified: "%s". Expected one of (%s)',
|
'Invalid option specified: "%s". Expected one of (%s)',
|
||||||
$option,
|
$option,
|
||||||
implode(', ', array_keys(static::$availableOptions))
|
implode(', ', array_keys(static::$availableOptions))
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Console\Formatter;
|
namespace Symfony\Component\Console\Formatter;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jean-François Simon <contact@jfsimon.fr>
|
* @author Jean-François Simon <contact@jfsimon.fr>
|
||||||
*/
|
*/
|
||||||
@ -62,7 +64,7 @@ class OutputFormatterStyleStack
|
|||||||
*
|
*
|
||||||
* @return OutputFormatterStyleInterface
|
* @return OutputFormatterStyleInterface
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException When style tags incorrectly nested
|
* @throws InvalidArgumentException When style tags incorrectly nested
|
||||||
*/
|
*/
|
||||||
public function pop(OutputFormatterStyleInterface $style = null)
|
public function pop(OutputFormatterStyleInterface $style = null)
|
||||||
{
|
{
|
||||||
@ -82,7 +84,7 @@ class OutputFormatterStyleStack
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new \InvalidArgumentException('Incorrectly nested style tag found.');
|
throw new InvalidArgumentException('Incorrectly nested style tag found.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -17,6 +17,7 @@ use Symfony\Component\Console\Descriptor\MarkdownDescriptor;
|
|||||||
use Symfony\Component\Console\Descriptor\TextDescriptor;
|
use Symfony\Component\Console\Descriptor\TextDescriptor;
|
||||||
use Symfony\Component\Console\Descriptor\XmlDescriptor;
|
use Symfony\Component\Console\Descriptor\XmlDescriptor;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class adds helper method to describe objects in various formats.
|
* This class adds helper method to describe objects in various formats.
|
||||||
@ -54,7 +55,7 @@ class DescriptorHelper extends Helper
|
|||||||
* @param object $object
|
* @param object $object
|
||||||
* @param array $options
|
* @param array $options
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException when the given format is not supported
|
* @throws InvalidArgumentException when the given format is not supported
|
||||||
*/
|
*/
|
||||||
public function describe(OutputInterface $output, $object, array $options = array())
|
public function describe(OutputInterface $output, $object, array $options = array())
|
||||||
{
|
{
|
||||||
@ -64,7 +65,7 @@ class DescriptorHelper extends Helper
|
|||||||
), $options);
|
), $options);
|
||||||
|
|
||||||
if (!isset($this->descriptors[$options['format']])) {
|
if (!isset($this->descriptors[$options['format']])) {
|
||||||
throw new \InvalidArgumentException(sprintf('Unsupported format "%s".', $options['format']));
|
throw new InvalidArgumentException(sprintf('Unsupported format "%s".', $options['format']));
|
||||||
}
|
}
|
||||||
|
|
||||||
$descriptor = $this->descriptors[$options['format']];
|
$descriptor = $this->descriptors[$options['format']];
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Console\Helper;
|
namespace Symfony\Component\Console\Helper;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
||||||
|
use Symfony\Component\Console\Exception\RuntimeException;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
|
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
|
||||||
|
|
||||||
@ -48,7 +50,7 @@ class DialogHelper extends InputAwareHelper
|
|||||||
*
|
*
|
||||||
* @return int|string|array The selected value or values (the key of the choices array)
|
* @return int|string|array The selected value or values (the key of the choices array)
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function select(OutputInterface $output, $question, $choices, $default = null, $attempts = false, $errorMessage = 'Value "%s" is invalid', $multiselect = false)
|
public function select(OutputInterface $output, $question, $choices, $default = null, $attempts = false, $errorMessage = 'Value "%s" is invalid', $multiselect = false)
|
||||||
{
|
{
|
||||||
@ -68,7 +70,7 @@ class DialogHelper extends InputAwareHelper
|
|||||||
if ($multiselect) {
|
if ($multiselect) {
|
||||||
// Check for a separated comma values
|
// Check for a separated comma values
|
||||||
if (!preg_match('/^[a-zA-Z0-9_-]+(?:,[a-zA-Z0-9_-]+)*$/', $selectedChoices, $matches)) {
|
if (!preg_match('/^[a-zA-Z0-9_-]+(?:,[a-zA-Z0-9_-]+)*$/', $selectedChoices, $matches)) {
|
||||||
throw new \InvalidArgumentException(sprintf($errorMessage, $picked));
|
throw new InvalidArgumentException(sprintf($errorMessage, $picked));
|
||||||
}
|
}
|
||||||
$selectedChoices = explode(',', $selectedChoices);
|
$selectedChoices = explode(',', $selectedChoices);
|
||||||
} else {
|
} else {
|
||||||
@ -79,7 +81,7 @@ class DialogHelper extends InputAwareHelper
|
|||||||
|
|
||||||
foreach ($selectedChoices as $value) {
|
foreach ($selectedChoices as $value) {
|
||||||
if (empty($choices[$value])) {
|
if (empty($choices[$value])) {
|
||||||
throw new \InvalidArgumentException(sprintf($errorMessage, $value));
|
throw new InvalidArgumentException(sprintf($errorMessage, $value));
|
||||||
}
|
}
|
||||||
$multiselectChoices[] = $value;
|
$multiselectChoices[] = $value;
|
||||||
}
|
}
|
||||||
@ -104,7 +106,7 @@ class DialogHelper extends InputAwareHelper
|
|||||||
*
|
*
|
||||||
* @return string The user answer
|
* @return string The user answer
|
||||||
*
|
*
|
||||||
* @throws \RuntimeException If there is no data to read in the input stream
|
* @throws RuntimeException If there is no data to read in the input stream
|
||||||
*/
|
*/
|
||||||
public function ask(OutputInterface $output, $question, $default = null, array $autocomplete = null)
|
public function ask(OutputInterface $output, $question, $default = null, array $autocomplete = null)
|
||||||
{
|
{
|
||||||
@ -119,7 +121,7 @@ class DialogHelper extends InputAwareHelper
|
|||||||
if (null === $autocomplete || !$this->hasSttyAvailable()) {
|
if (null === $autocomplete || !$this->hasSttyAvailable()) {
|
||||||
$ret = fgets($inputStream, 4096);
|
$ret = fgets($inputStream, 4096);
|
||||||
if (false === $ret) {
|
if (false === $ret) {
|
||||||
throw new \RuntimeException('Aborted');
|
throw new RuntimeException('Aborted');
|
||||||
}
|
}
|
||||||
$ret = trim($ret);
|
$ret = trim($ret);
|
||||||
} else {
|
} else {
|
||||||
@ -265,7 +267,7 @@ class DialogHelper extends InputAwareHelper
|
|||||||
*
|
*
|
||||||
* @return string The answer
|
* @return string The answer
|
||||||
*
|
*
|
||||||
* @throws \RuntimeException In case the fallback is deactivated and the response can not be hidden
|
* @throws RuntimeException In case the fallback is deactivated and the response can not be hidden
|
||||||
*/
|
*/
|
||||||
public function askHiddenResponse(OutputInterface $output, $question, $fallback = true)
|
public function askHiddenResponse(OutputInterface $output, $question, $fallback = true)
|
||||||
{
|
{
|
||||||
@ -300,7 +302,7 @@ class DialogHelper extends InputAwareHelper
|
|||||||
shell_exec(sprintf('stty %s', $sttyMode));
|
shell_exec(sprintf('stty %s', $sttyMode));
|
||||||
|
|
||||||
if (false === $value) {
|
if (false === $value) {
|
||||||
throw new \RuntimeException('Aborted');
|
throw new RuntimeException('Aborted');
|
||||||
}
|
}
|
||||||
|
|
||||||
$value = trim($value);
|
$value = trim($value);
|
||||||
@ -323,7 +325,7 @@ class DialogHelper extends InputAwareHelper
|
|||||||
return $this->ask($output, $question);
|
return $this->ask($output, $question);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new \RuntimeException('Unable to hide the response');
|
throw new RuntimeException('Unable to hide the response');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -370,8 +372,8 @@ class DialogHelper extends InputAwareHelper
|
|||||||
*
|
*
|
||||||
* @return string The response
|
* @return string The response
|
||||||
*
|
*
|
||||||
* @throws \Exception When any of the validators return an error
|
* @throws \Exception When any of the validators return an error
|
||||||
* @throws \RuntimeException In case the fallback is deactivated and the response can not be hidden
|
* @throws RuntimeException In case the fallback is deactivated and the response can not be hidden
|
||||||
*/
|
*/
|
||||||
public function askHiddenResponseAndValidate(OutputInterface $output, $question, $validator, $attempts = false, $fallback = true)
|
public function askHiddenResponseAndValidate(OutputInterface $output, $question, $validator, $attempts = false, $fallback = true)
|
||||||
{
|
{
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
namespace Symfony\Component\Console\Helper;
|
namespace Symfony\Component\Console\Helper;
|
||||||
|
|
||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HelperSet represents a set of helpers to be used with a command.
|
* HelperSet represents a set of helpers to be used with a command.
|
||||||
@ -70,12 +71,12 @@ class HelperSet implements \IteratorAggregate
|
|||||||
*
|
*
|
||||||
* @return HelperInterface The helper instance
|
* @return HelperInterface The helper instance
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException if the helper is not defined
|
* @throws InvalidArgumentException if the helper is not defined
|
||||||
*/
|
*/
|
||||||
public function get($name)
|
public function get($name)
|
||||||
{
|
{
|
||||||
if (!$this->has($name)) {
|
if (!$this->has($name)) {
|
||||||
throw new \InvalidArgumentException(sprintf('The helper "%s" is not defined.', $name));
|
throw new InvalidArgumentException(sprintf('The helper "%s" is not defined.', $name));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('dialog' === $name && $this->helpers[$name] instanceof DialogHelper) {
|
if ('dialog' === $name && $this->helpers[$name] instanceof DialogHelper) {
|
||||||
|
@ -13,6 +13,7 @@ namespace Symfony\Component\Console\Helper;
|
|||||||
|
|
||||||
use Symfony\Component\Console\Output\ConsoleOutputInterface;
|
use Symfony\Component\Console\Output\ConsoleOutputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Console\Exception\LogicException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The ProgressBar provides helpers to display progress output.
|
* The ProgressBar provides helpers to display progress output.
|
||||||
@ -355,7 +356,7 @@ class ProgressBar
|
|||||||
*
|
*
|
||||||
* @param int $step Number of steps to advance
|
* @param int $step Number of steps to advance
|
||||||
*
|
*
|
||||||
* @throws \LogicException
|
* @throws LogicException
|
||||||
*/
|
*/
|
||||||
public function advance($step = 1)
|
public function advance($step = 1)
|
||||||
{
|
{
|
||||||
@ -369,7 +370,7 @@ class ProgressBar
|
|||||||
*
|
*
|
||||||
* @param int $step The current progress
|
* @param int $step The current progress
|
||||||
*
|
*
|
||||||
* @throws \LogicException
|
* @throws LogicException
|
||||||
*/
|
*/
|
||||||
public function setCurrent($step)
|
public function setCurrent($step)
|
||||||
{
|
{
|
||||||
@ -393,13 +394,13 @@ class ProgressBar
|
|||||||
*
|
*
|
||||||
* @param int $step The current progress
|
* @param int $step The current progress
|
||||||
*
|
*
|
||||||
* @throws \LogicException
|
* @throws LogicException
|
||||||
*/
|
*/
|
||||||
public function setProgress($step)
|
public function setProgress($step)
|
||||||
{
|
{
|
||||||
$step = (int) $step;
|
$step = (int) $step;
|
||||||
if ($step < $this->step) {
|
if ($step < $this->step) {
|
||||||
throw new \LogicException('You can\'t regress the progress bar.');
|
throw new LogicException('You can\'t regress the progress bar.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->max && $step > $this->max) {
|
if ($this->max && $step > $this->max) {
|
||||||
@ -562,7 +563,7 @@ class ProgressBar
|
|||||||
},
|
},
|
||||||
'remaining' => function (ProgressBar $bar) {
|
'remaining' => function (ProgressBar $bar) {
|
||||||
if (!$bar->getMaxSteps()) {
|
if (!$bar->getMaxSteps()) {
|
||||||
throw new \LogicException('Unable to display the remaining time if the maximum number of steps is not set.');
|
throw new LogicException('Unable to display the remaining time if the maximum number of steps is not set.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$bar->getProgress()) {
|
if (!$bar->getProgress()) {
|
||||||
@ -575,7 +576,7 @@ class ProgressBar
|
|||||||
},
|
},
|
||||||
'estimated' => function (ProgressBar $bar) {
|
'estimated' => function (ProgressBar $bar) {
|
||||||
if (!$bar->getMaxSteps()) {
|
if (!$bar->getMaxSteps()) {
|
||||||
throw new \LogicException('Unable to display the estimated time if the maximum number of steps is not set.');
|
throw new LogicException('Unable to display the estimated time if the maximum number of steps is not set.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$bar->getProgress()) {
|
if (!$bar->getProgress()) {
|
||||||
|
@ -13,6 +13,7 @@ namespace Symfony\Component\Console\Helper;
|
|||||||
|
|
||||||
use Symfony\Component\Console\Output\NullOutput;
|
use Symfony\Component\Console\Output\NullOutput;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Console\Exception\LogicException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Progress class provides helpers to display progress output.
|
* The Progress class provides helpers to display progress output.
|
||||||
@ -236,7 +237,7 @@ class ProgressHelper extends Helper
|
|||||||
* @param int $step Number of steps to advance
|
* @param int $step Number of steps to advance
|
||||||
* @param bool $redraw Whether to redraw or not
|
* @param bool $redraw Whether to redraw or not
|
||||||
*
|
*
|
||||||
* @throws \LogicException
|
* @throws LogicException
|
||||||
*/
|
*/
|
||||||
public function advance($step = 1, $redraw = false)
|
public function advance($step = 1, $redraw = false)
|
||||||
{
|
{
|
||||||
@ -249,18 +250,18 @@ class ProgressHelper extends Helper
|
|||||||
* @param int $current The current progress
|
* @param int $current The current progress
|
||||||
* @param bool $redraw Whether to redraw or not
|
* @param bool $redraw Whether to redraw or not
|
||||||
*
|
*
|
||||||
* @throws \LogicException
|
* @throws LogicException
|
||||||
*/
|
*/
|
||||||
public function setCurrent($current, $redraw = false)
|
public function setCurrent($current, $redraw = false)
|
||||||
{
|
{
|
||||||
if (null === $this->startTime) {
|
if (null === $this->startTime) {
|
||||||
throw new \LogicException('You must start the progress bar before calling setCurrent().');
|
throw new LogicException('You must start the progress bar before calling setCurrent().');
|
||||||
}
|
}
|
||||||
|
|
||||||
$current = (int) $current;
|
$current = (int) $current;
|
||||||
|
|
||||||
if ($current < $this->current) {
|
if ($current < $this->current) {
|
||||||
throw new \LogicException('You can\'t regress the progress bar');
|
throw new LogicException('You can\'t regress the progress bar');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 === $this->current) {
|
if (0 === $this->current) {
|
||||||
@ -282,12 +283,12 @@ class ProgressHelper extends Helper
|
|||||||
*
|
*
|
||||||
* @param bool $finish Forces the end result
|
* @param bool $finish Forces the end result
|
||||||
*
|
*
|
||||||
* @throws \LogicException
|
* @throws LogicException
|
||||||
*/
|
*/
|
||||||
public function display($finish = false)
|
public function display($finish = false)
|
||||||
{
|
{
|
||||||
if (null === $this->startTime) {
|
if (null === $this->startTime) {
|
||||||
throw new \LogicException('You must start the progress bar before calling display().');
|
throw new LogicException('You must start the progress bar before calling display().');
|
||||||
}
|
}
|
||||||
|
|
||||||
$message = $this->format;
|
$message = $this->format;
|
||||||
@ -315,7 +316,7 @@ class ProgressHelper extends Helper
|
|||||||
public function finish()
|
public function finish()
|
||||||
{
|
{
|
||||||
if (null === $this->startTime) {
|
if (null === $this->startTime) {
|
||||||
throw new \LogicException('You must start the progress bar before calling finish().');
|
throw new LogicException('You must start the progress bar before calling finish().');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null !== $this->startTime) {
|
if (null !== $this->startTime) {
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Console\Helper;
|
namespace Symfony\Component\Console\Helper;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
||||||
|
use Symfony\Component\Console\Exception\RuntimeException;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\ConsoleOutputInterface;
|
use Symfony\Component\Console\Output\ConsoleOutputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
@ -38,7 +40,7 @@ class QuestionHelper extends Helper
|
|||||||
*
|
*
|
||||||
* @return string The user answer
|
* @return string The user answer
|
||||||
*
|
*
|
||||||
* @throws \RuntimeException If there is no data to read in the input stream
|
* @throws RuntimeException If there is no data to read in the input stream
|
||||||
*/
|
*/
|
||||||
public function ask(InputInterface $input, OutputInterface $output, Question $question)
|
public function ask(InputInterface $input, OutputInterface $output, Question $question)
|
||||||
{
|
{
|
||||||
@ -70,12 +72,12 @@ class QuestionHelper extends Helper
|
|||||||
*
|
*
|
||||||
* @param resource $stream The input stream
|
* @param resource $stream The input stream
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException In case the stream is not a resource
|
* @throws InvalidArgumentException In case the stream is not a resource
|
||||||
*/
|
*/
|
||||||
public function setInputStream($stream)
|
public function setInputStream($stream)
|
||||||
{
|
{
|
||||||
if (!is_resource($stream)) {
|
if (!is_resource($stream)) {
|
||||||
throw new \InvalidArgumentException('Input stream must be a valid resource.');
|
throw new InvalidArgumentException('Input stream must be a valid resource.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->inputStream = $stream;
|
$this->inputStream = $stream;
|
||||||
@ -315,7 +317,7 @@ class QuestionHelper extends Helper
|
|||||||
*
|
*
|
||||||
* @return string The answer
|
* @return string The answer
|
||||||
*
|
*
|
||||||
* @throws \RuntimeException In case the fallback is deactivated and the response cannot be hidden
|
* @throws RuntimeException In case the fallback is deactivated and the response cannot be hidden
|
||||||
*/
|
*/
|
||||||
private function getHiddenResponse(OutputInterface $output, $inputStream)
|
private function getHiddenResponse(OutputInterface $output, $inputStream)
|
||||||
{
|
{
|
||||||
@ -347,7 +349,7 @@ class QuestionHelper extends Helper
|
|||||||
shell_exec(sprintf('stty %s', $sttyMode));
|
shell_exec(sprintf('stty %s', $sttyMode));
|
||||||
|
|
||||||
if (false === $value) {
|
if (false === $value) {
|
||||||
throw new \RuntimeException('Aborted');
|
throw new RuntimeException('Aborted');
|
||||||
}
|
}
|
||||||
|
|
||||||
$value = trim($value);
|
$value = trim($value);
|
||||||
@ -365,7 +367,7 @@ class QuestionHelper extends Helper
|
|||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new \RuntimeException('Unable to hide the response.');
|
throw new RuntimeException('Unable to hide the response.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -431,7 +433,7 @@ class QuestionHelper extends Helper
|
|||||||
*
|
*
|
||||||
* @return string User input
|
* @return string User input
|
||||||
*
|
*
|
||||||
* @throws \RuntimeException
|
* @throws RuntimeException
|
||||||
*/
|
*/
|
||||||
private function readFromInput($stream)
|
private function readFromInput($stream)
|
||||||
{
|
{
|
||||||
@ -442,7 +444,7 @@ class QuestionHelper extends Helper
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (false === $ret) {
|
if (false === $ret) {
|
||||||
throw new \RuntimeException('Aborted');
|
throw new RuntimeException('Aborted');
|
||||||
}
|
}
|
||||||
|
|
||||||
return trim($ret);
|
return trim($ret);
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Console\Helper;
|
namespace Symfony\Component\Console\Helper;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Exception\LogicException;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Symfony\Component\Console\Question\ChoiceQuestion;
|
use Symfony\Component\Console\Question\ChoiceQuestion;
|
||||||
@ -38,7 +39,7 @@ class SymfonyQuestionHelper extends QuestionHelper
|
|||||||
|
|
||||||
// make required
|
// make required
|
||||||
if (!is_array($value) && !is_bool($value) && 0 === strlen($value)) {
|
if (!is_array($value) && !is_bool($value) && 0 === strlen($value)) {
|
||||||
throw new \Exception('A value is required.');
|
throw new LogicException('A value is required.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $value;
|
return $value;
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
namespace Symfony\Component\Console\Helper;
|
namespace Symfony\Component\Console\Helper;
|
||||||
|
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides helpers to display a table.
|
* Provides helpers to display a table.
|
||||||
@ -102,7 +103,7 @@ class Table
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!self::$styles[$name]) {
|
if (!self::$styles[$name]) {
|
||||||
throw new \InvalidArgumentException(sprintf('Style "%s" is not defined.', $name));
|
throw new InvalidArgumentException(sprintf('Style "%s" is not defined.', $name));
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::$styles[$name];
|
return self::$styles[$name];
|
||||||
@ -122,7 +123,7 @@ class Table
|
|||||||
} elseif (isset(self::$styles[$name])) {
|
} elseif (isset(self::$styles[$name])) {
|
||||||
$this->style = self::$styles[$name];
|
$this->style = self::$styles[$name];
|
||||||
} else {
|
} else {
|
||||||
throw new \InvalidArgumentException(sprintf('Style "%s" is not defined.', $name));
|
throw new InvalidArgumentException(sprintf('Style "%s" is not defined.', $name));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@ -175,7 +176,7 @@ class Table
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!is_array($row)) {
|
if (!is_array($row)) {
|
||||||
throw new \InvalidArgumentException('A row must be an array or a TableSeparator instance.');
|
throw new InvalidArgumentException('A row must be an array or a TableSeparator instance.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->rows[] = array_values($row);
|
$this->rows[] = array_values($row);
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Console\Helper;
|
namespace Symfony\Component\Console\Helper;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Abdellatif Ait boudad <a.aitboudad@gmail.com>
|
* @author Abdellatif Ait boudad <a.aitboudad@gmail.com>
|
||||||
*/
|
*/
|
||||||
@ -39,7 +41,7 @@ class TableCell
|
|||||||
|
|
||||||
// check option names
|
// check option names
|
||||||
if ($diff = array_diff(array_keys($options), array_keys($this->options))) {
|
if ($diff = array_diff(array_keys($options), array_keys($this->options))) {
|
||||||
throw new \InvalidArgumentException(sprintf('The TableCell does not support the following options: \'%s\'.', implode('\', \'', $diff)));
|
throw new InvalidArgumentException(sprintf('The TableCell does not support the following options: \'%s\'.', implode('\', \'', $diff)));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->options = array_merge($this->options, $options);
|
$this->options = array_merge($this->options, $options);
|
||||||
|
@ -13,6 +13,7 @@ namespace Symfony\Component\Console\Helper;
|
|||||||
|
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Symfony\Component\Console\Output\NullOutput;
|
use Symfony\Component\Console\Output\NullOutput;
|
||||||
|
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides helpers to display table output.
|
* Provides helpers to display table output.
|
||||||
@ -50,7 +51,7 @@ class TableHelper extends Helper
|
|||||||
*
|
*
|
||||||
* @return TableHelper
|
* @return TableHelper
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException when the table layout is not known
|
* @throws InvalidArgumentException when the table layout is not known
|
||||||
*/
|
*/
|
||||||
public function setLayout($layout)
|
public function setLayout($layout)
|
||||||
{
|
{
|
||||||
@ -68,7 +69,7 @@ class TableHelper extends Helper
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new \InvalidArgumentException(sprintf('Invalid table layout "%s".', $layout));
|
throw new InvalidArgumentException(sprintf('Invalid table layout "%s".', $layout));
|
||||||
};
|
};
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -11,6 +11,9 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Console\Helper;
|
namespace Symfony\Component\Console\Helper;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
||||||
|
use Symfony\Component\Console\Exception\LogicException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the styles for a Table.
|
* Defines the styles for a Table.
|
||||||
*
|
*
|
||||||
@ -39,7 +42,7 @@ class TableStyle
|
|||||||
public function setPaddingChar($paddingChar)
|
public function setPaddingChar($paddingChar)
|
||||||
{
|
{
|
||||||
if (!$paddingChar) {
|
if (!$paddingChar) {
|
||||||
throw new \LogicException('The padding char must not be empty');
|
throw new LogicException('The padding char must not be empty');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->paddingChar = $paddingChar;
|
$this->paddingChar = $paddingChar;
|
||||||
@ -235,7 +238,7 @@ class TableStyle
|
|||||||
public function setPadType($padType)
|
public function setPadType($padType)
|
||||||
{
|
{
|
||||||
if (!in_array($padType, array(STR_PAD_LEFT, STR_PAD_RIGHT, STR_PAD_BOTH), true)) {
|
if (!in_array($padType, array(STR_PAD_LEFT, STR_PAD_RIGHT, STR_PAD_BOTH), true)) {
|
||||||
throw new \InvalidArgumentException('Invalid padding type. Expected one of (STR_PAD_LEFT, STR_PAD_RIGHT, STR_PAD_BOTH).');
|
throw new InvalidArgumentException('Invalid padding type. Expected one of (STR_PAD_LEFT, STR_PAD_RIGHT, STR_PAD_BOTH).');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->padType = $padType;
|
$this->padType = $padType;
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Console\Input;
|
namespace Symfony\Component\Console\Input;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Exception\RuntimeException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ArgvInput represents an input coming from the CLI arguments.
|
* ArgvInput represents an input coming from the CLI arguments.
|
||||||
*
|
*
|
||||||
@ -118,14 +120,14 @@ class ArgvInput extends Input
|
|||||||
*
|
*
|
||||||
* @param string $name The current token
|
* @param string $name The current token
|
||||||
*
|
*
|
||||||
* @throws \RuntimeException When option given doesn't exist
|
* @throws RuntimeException When option given doesn't exist
|
||||||
*/
|
*/
|
||||||
private function parseShortOptionSet($name)
|
private function parseShortOptionSet($name)
|
||||||
{
|
{
|
||||||
$len = strlen($name);
|
$len = strlen($name);
|
||||||
for ($i = 0; $i < $len; ++$i) {
|
for ($i = 0; $i < $len; ++$i) {
|
||||||
if (!$this->definition->hasShortcut($name[$i])) {
|
if (!$this->definition->hasShortcut($name[$i])) {
|
||||||
throw new \RuntimeException(sprintf('The "-%s" option does not exist.', $name[$i]));
|
throw new RuntimeException(sprintf('The "-%s" option does not exist.', $name[$i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
$option = $this->definition->getOptionForShortcut($name[$i]);
|
$option = $this->definition->getOptionForShortcut($name[$i]);
|
||||||
@ -160,7 +162,7 @@ class ArgvInput extends Input
|
|||||||
*
|
*
|
||||||
* @param string $token The current token
|
* @param string $token The current token
|
||||||
*
|
*
|
||||||
* @throws \RuntimeException When too many arguments are given
|
* @throws RuntimeException When too many arguments are given
|
||||||
*/
|
*/
|
||||||
private function parseArgument($token)
|
private function parseArgument($token)
|
||||||
{
|
{
|
||||||
@ -178,7 +180,7 @@ class ArgvInput extends Input
|
|||||||
|
|
||||||
// unexpected argument
|
// unexpected argument
|
||||||
} else {
|
} else {
|
||||||
throw new \RuntimeException('Too many arguments.');
|
throw new RuntimeException('Too many arguments.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,12 +190,12 @@ class ArgvInput extends Input
|
|||||||
* @param string $shortcut The short option key
|
* @param string $shortcut The short option key
|
||||||
* @param mixed $value The value for the option
|
* @param mixed $value The value for the option
|
||||||
*
|
*
|
||||||
* @throws \RuntimeException When option given doesn't exist
|
* @throws RuntimeException When option given doesn't exist
|
||||||
*/
|
*/
|
||||||
private function addShortOption($shortcut, $value)
|
private function addShortOption($shortcut, $value)
|
||||||
{
|
{
|
||||||
if (!$this->definition->hasShortcut($shortcut)) {
|
if (!$this->definition->hasShortcut($shortcut)) {
|
||||||
throw new \RuntimeException(sprintf('The "-%s" option does not exist.', $shortcut));
|
throw new RuntimeException(sprintf('The "-%s" option does not exist.', $shortcut));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->addLongOption($this->definition->getOptionForShortcut($shortcut)->getName(), $value);
|
$this->addLongOption($this->definition->getOptionForShortcut($shortcut)->getName(), $value);
|
||||||
@ -205,12 +207,12 @@ class ArgvInput extends Input
|
|||||||
* @param string $name The long option key
|
* @param string $name The long option key
|
||||||
* @param mixed $value The value for the option
|
* @param mixed $value The value for the option
|
||||||
*
|
*
|
||||||
* @throws \RuntimeException When option given doesn't exist
|
* @throws RuntimeException When option given doesn't exist
|
||||||
*/
|
*/
|
||||||
private function addLongOption($name, $value)
|
private function addLongOption($name, $value)
|
||||||
{
|
{
|
||||||
if (!$this->definition->hasOption($name)) {
|
if (!$this->definition->hasOption($name)) {
|
||||||
throw new \RuntimeException(sprintf('The "--%s" option does not exist.', $name));
|
throw new RuntimeException(sprintf('The "--%s" option does not exist.', $name));
|
||||||
}
|
}
|
||||||
|
|
||||||
$option = $this->definition->getOption($name);
|
$option = $this->definition->getOption($name);
|
||||||
@ -221,7 +223,7 @@ class ArgvInput extends Input
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (null !== $value && !$option->acceptValue()) {
|
if (null !== $value && !$option->acceptValue()) {
|
||||||
throw new \RuntimeException(sprintf('The "--%s" option does not accept a value.', $name));
|
throw new RuntimeException(sprintf('The "--%s" option does not accept a value.', $name));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null === $value && $option->acceptValue() && count($this->parsed)) {
|
if (null === $value && $option->acceptValue() && count($this->parsed)) {
|
||||||
@ -239,7 +241,7 @@ class ArgvInput extends Input
|
|||||||
|
|
||||||
if (null === $value) {
|
if (null === $value) {
|
||||||
if ($option->isValueRequired()) {
|
if ($option->isValueRequired()) {
|
||||||
throw new \RuntimeException(sprintf('The "--%s" option requires a value.', $name));
|
throw new RuntimeException(sprintf('The "--%s" option requires a value.', $name));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$option->isArray()) {
|
if (!$option->isArray()) {
|
||||||
|
@ -11,6 +11,9 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Console\Input;
|
namespace Symfony\Component\Console\Input;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
||||||
|
use Symfony\Component\Console\Exception\InvalidOptionException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ArrayInput represents an input provided as an array.
|
* ArrayInput represents an input provided as an array.
|
||||||
*
|
*
|
||||||
@ -153,12 +156,12 @@ class ArrayInput extends Input
|
|||||||
* @param string $shortcut The short option key
|
* @param string $shortcut The short option key
|
||||||
* @param mixed $value The value for the option
|
* @param mixed $value The value for the option
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException When option given doesn't exist
|
* @throws InvalidOptionException When option given doesn't exist
|
||||||
*/
|
*/
|
||||||
private function addShortOption($shortcut, $value)
|
private function addShortOption($shortcut, $value)
|
||||||
{
|
{
|
||||||
if (!$this->definition->hasShortcut($shortcut)) {
|
if (!$this->definition->hasShortcut($shortcut)) {
|
||||||
throw new \InvalidArgumentException(sprintf('The "-%s" option does not exist.', $shortcut));
|
throw new InvalidOptionException(sprintf('The "-%s" option does not exist.', $shortcut));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->addLongOption($this->definition->getOptionForShortcut($shortcut)->getName(), $value);
|
$this->addLongOption($this->definition->getOptionForShortcut($shortcut)->getName(), $value);
|
||||||
@ -170,20 +173,20 @@ class ArrayInput extends Input
|
|||||||
* @param string $name The long option key
|
* @param string $name The long option key
|
||||||
* @param mixed $value The value for the option
|
* @param mixed $value The value for the option
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException When option given doesn't exist
|
* @throws InvalidOptionException When option given doesn't exist
|
||||||
* @throws \InvalidArgumentException When a required value is missing
|
* @throws InvalidOptionException When a required value is missing
|
||||||
*/
|
*/
|
||||||
private function addLongOption($name, $value)
|
private function addLongOption($name, $value)
|
||||||
{
|
{
|
||||||
if (!$this->definition->hasOption($name)) {
|
if (!$this->definition->hasOption($name)) {
|
||||||
throw new \InvalidArgumentException(sprintf('The "--%s" option does not exist.', $name));
|
throw new InvalidOptionException(sprintf('The "--%s" option does not exist.', $name));
|
||||||
}
|
}
|
||||||
|
|
||||||
$option = $this->definition->getOption($name);
|
$option = $this->definition->getOption($name);
|
||||||
|
|
||||||
if (null === $value) {
|
if (null === $value) {
|
||||||
if ($option->isValueRequired()) {
|
if ($option->isValueRequired()) {
|
||||||
throw new \InvalidArgumentException(sprintf('The "--%s" option requires a value.', $name));
|
throw new InvalidOptionException(sprintf('The "--%s" option requires a value.', $name));
|
||||||
}
|
}
|
||||||
|
|
||||||
$value = $option->isValueOptional() ? $option->getDefault() : true;
|
$value = $option->isValueOptional() ? $option->getDefault() : true;
|
||||||
@ -198,12 +201,12 @@ class ArrayInput extends Input
|
|||||||
* @param string $name The argument name
|
* @param string $name The argument name
|
||||||
* @param mixed $value The value for the argument
|
* @param mixed $value The value for the argument
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException When argument given doesn't exist
|
* @throws InvalidArgumentException When argument given doesn't exist
|
||||||
*/
|
*/
|
||||||
private function addArgument($name, $value)
|
private function addArgument($name, $value)
|
||||||
{
|
{
|
||||||
if (!$this->definition->hasArgument($name)) {
|
if (!$this->definition->hasArgument($name)) {
|
||||||
throw new \InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
|
throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->arguments[$name] = $value;
|
$this->arguments[$name] = $value;
|
||||||
|
@ -11,6 +11,9 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Console\Input;
|
namespace Symfony\Component\Console\Input;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
||||||
|
use Symfony\Component\Console\Exception\RuntimeException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Input is the base class for all concrete Input classes.
|
* Input is the base class for all concrete Input classes.
|
||||||
*
|
*
|
||||||
@ -69,12 +72,12 @@ abstract class Input implements InputInterface
|
|||||||
/**
|
/**
|
||||||
* Validates the input.
|
* Validates the input.
|
||||||
*
|
*
|
||||||
* @throws \RuntimeException When not enough arguments are given
|
* @throws RuntimeException When not enough arguments are given
|
||||||
*/
|
*/
|
||||||
public function validate()
|
public function validate()
|
||||||
{
|
{
|
||||||
if (count($this->arguments) < $this->definition->getArgumentRequiredCount()) {
|
if (count($this->arguments) < $this->definition->getArgumentRequiredCount()) {
|
||||||
throw new \RuntimeException('Not enough arguments.');
|
throw new RuntimeException('Not enough arguments.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,12 +118,12 @@ abstract class Input implements InputInterface
|
|||||||
*
|
*
|
||||||
* @return mixed The argument value
|
* @return mixed The argument value
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException When argument given doesn't exist
|
* @throws InvalidArgumentException When argument given doesn't exist
|
||||||
*/
|
*/
|
||||||
public function getArgument($name)
|
public function getArgument($name)
|
||||||
{
|
{
|
||||||
if (!$this->definition->hasArgument($name)) {
|
if (!$this->definition->hasArgument($name)) {
|
||||||
throw new \InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
|
throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
|
||||||
}
|
}
|
||||||
|
|
||||||
return isset($this->arguments[$name]) ? $this->arguments[$name] : $this->definition->getArgument($name)->getDefault();
|
return isset($this->arguments[$name]) ? $this->arguments[$name] : $this->definition->getArgument($name)->getDefault();
|
||||||
@ -132,12 +135,12 @@ abstract class Input implements InputInterface
|
|||||||
* @param string $name The argument name
|
* @param string $name The argument name
|
||||||
* @param string $value The argument value
|
* @param string $value The argument value
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException When argument given doesn't exist
|
* @throws InvalidArgumentException When argument given doesn't exist
|
||||||
*/
|
*/
|
||||||
public function setArgument($name, $value)
|
public function setArgument($name, $value)
|
||||||
{
|
{
|
||||||
if (!$this->definition->hasArgument($name)) {
|
if (!$this->definition->hasArgument($name)) {
|
||||||
throw new \InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
|
throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->arguments[$name] = $value;
|
$this->arguments[$name] = $value;
|
||||||
@ -172,12 +175,12 @@ abstract class Input implements InputInterface
|
|||||||
*
|
*
|
||||||
* @return mixed The option value
|
* @return mixed The option value
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException When option given doesn't exist
|
* @throws InvalidArgumentException When option given doesn't exist
|
||||||
*/
|
*/
|
||||||
public function getOption($name)
|
public function getOption($name)
|
||||||
{
|
{
|
||||||
if (!$this->definition->hasOption($name)) {
|
if (!$this->definition->hasOption($name)) {
|
||||||
throw new \InvalidArgumentException(sprintf('The "%s" option does not exist.', $name));
|
throw new InvalidArgumentException(sprintf('The "%s" option does not exist.', $name));
|
||||||
}
|
}
|
||||||
|
|
||||||
return isset($this->options[$name]) ? $this->options[$name] : $this->definition->getOption($name)->getDefault();
|
return isset($this->options[$name]) ? $this->options[$name] : $this->definition->getOption($name)->getDefault();
|
||||||
@ -189,12 +192,12 @@ abstract class Input implements InputInterface
|
|||||||
* @param string $name The option name
|
* @param string $name The option name
|
||||||
* @param string|bool $value The option value
|
* @param string|bool $value The option value
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException When option given doesn't exist
|
* @throws InvalidArgumentException When option given doesn't exist
|
||||||
*/
|
*/
|
||||||
public function setOption($name, $value)
|
public function setOption($name, $value)
|
||||||
{
|
{
|
||||||
if (!$this->definition->hasOption($name)) {
|
if (!$this->definition->hasOption($name)) {
|
||||||
throw new \InvalidArgumentException(sprintf('The "%s" option does not exist.', $name));
|
throw new InvalidArgumentException(sprintf('The "%s" option does not exist.', $name));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->options[$name] = $value;
|
$this->options[$name] = $value;
|
||||||
|
@ -11,6 +11,9 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Console\Input;
|
namespace Symfony\Component\Console\Input;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
||||||
|
use Symfony\Component\Console\Exception\LogicException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a command line argument.
|
* Represents a command line argument.
|
||||||
*
|
*
|
||||||
@ -37,7 +40,7 @@ class InputArgument
|
|||||||
* @param string $description A description text
|
* @param string $description A description text
|
||||||
* @param mixed $default The default value (for self::OPTIONAL mode only)
|
* @param mixed $default The default value (for self::OPTIONAL mode only)
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException When argument mode is not valid
|
* @throws InvalidArgumentException When argument mode is not valid
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@ -46,7 +49,7 @@ class InputArgument
|
|||||||
if (null === $mode) {
|
if (null === $mode) {
|
||||||
$mode = self::OPTIONAL;
|
$mode = self::OPTIONAL;
|
||||||
} elseif (!is_int($mode) || $mode > 7 || $mode < 1) {
|
} elseif (!is_int($mode) || $mode > 7 || $mode < 1) {
|
||||||
throw new \InvalidArgumentException(sprintf('Argument mode "%s" is not valid.', $mode));
|
throw new InvalidArgumentException(sprintf('Argument mode "%s" is not valid.', $mode));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
@ -91,19 +94,19 @@ class InputArgument
|
|||||||
*
|
*
|
||||||
* @param mixed $default The default value
|
* @param mixed $default The default value
|
||||||
*
|
*
|
||||||
* @throws \LogicException When incorrect default value is given
|
* @throws LogicException When incorrect default value is given
|
||||||
*/
|
*/
|
||||||
public function setDefault($default = null)
|
public function setDefault($default = null)
|
||||||
{
|
{
|
||||||
if (self::REQUIRED === $this->mode && null !== $default) {
|
if (self::REQUIRED === $this->mode && null !== $default) {
|
||||||
throw new \LogicException('Cannot set a default value except for InputArgument::OPTIONAL mode.');
|
throw new LogicException('Cannot set a default value except for InputArgument::OPTIONAL mode.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->isArray()) {
|
if ($this->isArray()) {
|
||||||
if (null === $default) {
|
if (null === $default) {
|
||||||
$default = array();
|
$default = array();
|
||||||
} elseif (!is_array($default)) {
|
} elseif (!is_array($default)) {
|
||||||
throw new \LogicException('A default value for an array argument must be an array.');
|
throw new LogicException('A default value for an array argument must be an array.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,8 @@ namespace Symfony\Component\Console\Input;
|
|||||||
use Symfony\Component\Console\Descriptor\TextDescriptor;
|
use Symfony\Component\Console\Descriptor\TextDescriptor;
|
||||||
use Symfony\Component\Console\Descriptor\XmlDescriptor;
|
use Symfony\Component\Console\Descriptor\XmlDescriptor;
|
||||||
use Symfony\Component\Console\Output\BufferedOutput;
|
use Symfony\Component\Console\Output\BufferedOutput;
|
||||||
|
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
||||||
|
use Symfony\Component\Console\Exception\LogicException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A InputDefinition represents a set of valid command line arguments and options.
|
* A InputDefinition represents a set of valid command line arguments and options.
|
||||||
@ -110,22 +112,22 @@ class InputDefinition
|
|||||||
*
|
*
|
||||||
* @param InputArgument $argument An InputArgument object
|
* @param InputArgument $argument An InputArgument object
|
||||||
*
|
*
|
||||||
* @throws \LogicException When incorrect argument is given
|
* @throws LogicException When incorrect argument is given
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
public function addArgument(InputArgument $argument)
|
public function addArgument(InputArgument $argument)
|
||||||
{
|
{
|
||||||
if (isset($this->arguments[$argument->getName()])) {
|
if (isset($this->arguments[$argument->getName()])) {
|
||||||
throw new \LogicException(sprintf('An argument with name "%s" already exists.', $argument->getName()));
|
throw new LogicException(sprintf('An argument with name "%s" already exists.', $argument->getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->hasAnArrayArgument) {
|
if ($this->hasAnArrayArgument) {
|
||||||
throw new \LogicException('Cannot add an argument after an array argument.');
|
throw new LogicException('Cannot add an argument after an array argument.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($argument->isRequired() && $this->hasOptional) {
|
if ($argument->isRequired() && $this->hasOptional) {
|
||||||
throw new \LogicException('Cannot add a required argument after an optional one.');
|
throw new LogicException('Cannot add a required argument after an optional one.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($argument->isArray()) {
|
if ($argument->isArray()) {
|
||||||
@ -148,14 +150,14 @@ class InputDefinition
|
|||||||
*
|
*
|
||||||
* @return InputArgument An InputArgument object
|
* @return InputArgument An InputArgument object
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException When argument given doesn't exist
|
* @throws InvalidArgumentException When argument given doesn't exist
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
public function getArgument($name)
|
public function getArgument($name)
|
||||||
{
|
{
|
||||||
if (!$this->hasArgument($name)) {
|
if (!$this->hasArgument($name)) {
|
||||||
throw new \InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
|
throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
|
||||||
}
|
}
|
||||||
|
|
||||||
$arguments = is_int($name) ? array_values($this->arguments) : $this->arguments;
|
$arguments = is_int($name) ? array_values($this->arguments) : $this->arguments;
|
||||||
@ -259,20 +261,20 @@ class InputDefinition
|
|||||||
*
|
*
|
||||||
* @param InputOption $option An InputOption object
|
* @param InputOption $option An InputOption object
|
||||||
*
|
*
|
||||||
* @throws \LogicException When option given already exist
|
* @throws LogicException When option given already exist
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
public function addOption(InputOption $option)
|
public function addOption(InputOption $option)
|
||||||
{
|
{
|
||||||
if (isset($this->options[$option->getName()]) && !$option->equals($this->options[$option->getName()])) {
|
if (isset($this->options[$option->getName()]) && !$option->equals($this->options[$option->getName()])) {
|
||||||
throw new \LogicException(sprintf('An option named "%s" already exists.', $option->getName()));
|
throw new LogicException(sprintf('An option named "%s" already exists.', $option->getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($option->getShortcut()) {
|
if ($option->getShortcut()) {
|
||||||
foreach (explode('|', $option->getShortcut()) as $shortcut) {
|
foreach (explode('|', $option->getShortcut()) as $shortcut) {
|
||||||
if (isset($this->shortcuts[$shortcut]) && !$option->equals($this->options[$this->shortcuts[$shortcut]])) {
|
if (isset($this->shortcuts[$shortcut]) && !$option->equals($this->options[$this->shortcuts[$shortcut]])) {
|
||||||
throw new \LogicException(sprintf('An option with shortcut "%s" already exists.', $shortcut));
|
throw new LogicException(sprintf('An option with shortcut "%s" already exists.', $shortcut));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -292,14 +294,14 @@ class InputDefinition
|
|||||||
*
|
*
|
||||||
* @return InputOption A InputOption object
|
* @return InputOption A InputOption object
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException When option given doesn't exist
|
* @throws InvalidArgumentException When option given doesn't exist
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
public function getOption($name)
|
public function getOption($name)
|
||||||
{
|
{
|
||||||
if (!$this->hasOption($name)) {
|
if (!$this->hasOption($name)) {
|
||||||
throw new \InvalidArgumentException(sprintf('The "--%s" option does not exist.', $name));
|
throw new InvalidArgumentException(sprintf('The "--%s" option does not exist.', $name));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->options[$name];
|
return $this->options[$name];
|
||||||
@ -377,12 +379,12 @@ class InputDefinition
|
|||||||
*
|
*
|
||||||
* @return string The InputOption name
|
* @return string The InputOption name
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException When option given does not exist
|
* @throws InvalidArgumentException When option given does not exist
|
||||||
*/
|
*/
|
||||||
private function shortcutToName($shortcut)
|
private function shortcutToName($shortcut)
|
||||||
{
|
{
|
||||||
if (!isset($this->shortcuts[$shortcut])) {
|
if (!isset($this->shortcuts[$shortcut])) {
|
||||||
throw new \InvalidArgumentException(sprintf('The "-%s" option does not exist.', $shortcut));
|
throw new InvalidArgumentException(sprintf('The "-%s" option does not exist.', $shortcut));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->shortcuts[$shortcut];
|
return $this->shortcuts[$shortcut];
|
||||||
|
@ -88,7 +88,7 @@ interface InputInterface
|
|||||||
* @param string $name The argument name
|
* @param string $name The argument name
|
||||||
* @param string $value The argument value
|
* @param string $value The argument value
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException When argument given doesn't exist
|
* @throws InvalidArgumentException When argument given doesn't exist
|
||||||
*/
|
*/
|
||||||
public function setArgument($name, $value);
|
public function setArgument($name, $value);
|
||||||
|
|
||||||
@ -123,7 +123,7 @@ interface InputInterface
|
|||||||
* @param string $name The option name
|
* @param string $name The option name
|
||||||
* @param string|bool $value The option value
|
* @param string|bool $value The option value
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException When option given doesn't exist
|
* @throws InvalidArgumentException When option given doesn't exist
|
||||||
*/
|
*/
|
||||||
public function setOption($name, $value);
|
public function setOption($name, $value);
|
||||||
|
|
||||||
|
@ -11,6 +11,9 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Console\Input;
|
namespace Symfony\Component\Console\Input;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
||||||
|
use Symfony\Component\Console\Exception\LogicException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a command line option.
|
* Represents a command line option.
|
||||||
*
|
*
|
||||||
@ -40,7 +43,7 @@ class InputOption
|
|||||||
* @param string $description A description text
|
* @param string $description A description text
|
||||||
* @param mixed $default The default value (must be null for self::VALUE_REQUIRED or self::VALUE_NONE)
|
* @param mixed $default The default value (must be null for self::VALUE_REQUIRED or self::VALUE_NONE)
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException If option mode is invalid or incompatible
|
* @throws InvalidArgumentException If option mode is invalid or incompatible
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@ -51,7 +54,7 @@ class InputOption
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (empty($name)) {
|
if (empty($name)) {
|
||||||
throw new \InvalidArgumentException('An option name cannot be empty.');
|
throw new InvalidArgumentException('An option name cannot be empty.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($shortcut)) {
|
if (empty($shortcut)) {
|
||||||
@ -67,14 +70,14 @@ class InputOption
|
|||||||
$shortcut = implode('|', $shortcuts);
|
$shortcut = implode('|', $shortcuts);
|
||||||
|
|
||||||
if (empty($shortcut)) {
|
if (empty($shortcut)) {
|
||||||
throw new \InvalidArgumentException('An option shortcut cannot be empty.');
|
throw new InvalidArgumentException('An option shortcut cannot be empty.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null === $mode) {
|
if (null === $mode) {
|
||||||
$mode = self::VALUE_NONE;
|
$mode = self::VALUE_NONE;
|
||||||
} elseif (!is_int($mode) || $mode > 15 || $mode < 1) {
|
} elseif (!is_int($mode) || $mode > 15 || $mode < 1) {
|
||||||
throw new \InvalidArgumentException(sprintf('Option mode "%s" is not valid.', $mode));
|
throw new InvalidArgumentException(sprintf('Option mode "%s" is not valid.', $mode));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
@ -83,7 +86,7 @@ class InputOption
|
|||||||
$this->description = $description;
|
$this->description = $description;
|
||||||
|
|
||||||
if ($this->isArray() && !$this->acceptValue()) {
|
if ($this->isArray() && !$this->acceptValue()) {
|
||||||
throw new \InvalidArgumentException('Impossible to have an option mode VALUE_IS_ARRAY if the option does not accept a value.');
|
throw new InvalidArgumentException('Impossible to have an option mode VALUE_IS_ARRAY if the option does not accept a value.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setDefault($default);
|
$this->setDefault($default);
|
||||||
@ -154,19 +157,19 @@ class InputOption
|
|||||||
*
|
*
|
||||||
* @param mixed $default The default value
|
* @param mixed $default The default value
|
||||||
*
|
*
|
||||||
* @throws \LogicException When incorrect default value is given
|
* @throws LogicException When incorrect default value is given
|
||||||
*/
|
*/
|
||||||
public function setDefault($default = null)
|
public function setDefault($default = null)
|
||||||
{
|
{
|
||||||
if (self::VALUE_NONE === (self::VALUE_NONE & $this->mode) && null !== $default) {
|
if (self::VALUE_NONE === (self::VALUE_NONE & $this->mode) && null !== $default) {
|
||||||
throw new \LogicException('Cannot set a default value when using InputOption::VALUE_NONE mode.');
|
throw new LogicException('Cannot set a default value when using InputOption::VALUE_NONE mode.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->isArray()) {
|
if ($this->isArray()) {
|
||||||
if (null === $default) {
|
if (null === $default) {
|
||||||
$default = array();
|
$default = array();
|
||||||
} elseif (!is_array($default)) {
|
} elseif (!is_array($default)) {
|
||||||
throw new \LogicException('A default value for an array option must be an array.');
|
throw new LogicException('A default value for an array option must be an array.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Console\Input;
|
namespace Symfony\Component\Console\Input;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* StringInput represents an input provided as a string.
|
* StringInput represents an input provided as a string.
|
||||||
*
|
*
|
||||||
@ -59,7 +61,7 @@ class StringInput extends ArgvInput
|
|||||||
*
|
*
|
||||||
* @return array An array of tokens
|
* @return array An array of tokens
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException When unable to parse input (should never happen)
|
* @throws InvalidArgumentException When unable to parse input (should never happen)
|
||||||
*/
|
*/
|
||||||
private function tokenize($input)
|
private function tokenize($input)
|
||||||
{
|
{
|
||||||
@ -76,7 +78,7 @@ class StringInput extends ArgvInput
|
|||||||
$tokens[] = stripcslashes($match[1]);
|
$tokens[] = stripcslashes($match[1]);
|
||||||
} else {
|
} else {
|
||||||
// should never happen
|
// should never happen
|
||||||
throw new \InvalidArgumentException(sprintf('Unable to parse input near "... %s ..."', substr($input, $cursor, 10)));
|
throw new InvalidArgumentException(sprintf('Unable to parse input near "... %s ..."', substr($input, $cursor, 10)));
|
||||||
}
|
}
|
||||||
|
|
||||||
$cursor += strlen($match[0]);
|
$cursor += strlen($match[0]);
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Console\Output;
|
namespace Symfony\Component\Console\Output;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
||||||
|
use Symfony\Component\Console\Exception\RuntimeException;
|
||||||
use Symfony\Component\Console\Formatter\OutputFormatterInterface;
|
use Symfony\Component\Console\Formatter\OutputFormatterInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -40,14 +42,14 @@ class StreamOutput extends Output
|
|||||||
* @param bool|null $decorated Whether to decorate messages (null for auto-guessing)
|
* @param bool|null $decorated Whether to decorate messages (null for auto-guessing)
|
||||||
* @param OutputFormatterInterface|null $formatter Output formatter instance (null to use default OutputFormatter)
|
* @param OutputFormatterInterface|null $formatter Output formatter instance (null to use default OutputFormatter)
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException When first argument is not a real stream
|
* @throws InvalidArgumentException When first argument is not a real stream
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
public function __construct($stream, $verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null)
|
public function __construct($stream, $verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null)
|
||||||
{
|
{
|
||||||
if (!is_resource($stream) || 'stream' !== get_resource_type($stream)) {
|
if (!is_resource($stream) || 'stream' !== get_resource_type($stream)) {
|
||||||
throw new \InvalidArgumentException('The StreamOutput class needs a stream as its first argument.');
|
throw new InvalidArgumentException('The StreamOutput class needs a stream as its first argument.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->stream = $stream;
|
$this->stream = $stream;
|
||||||
@ -76,7 +78,7 @@ class StreamOutput extends Output
|
|||||||
{
|
{
|
||||||
if (false === @fwrite($this->stream, $message.($newline ? PHP_EOL : ''))) {
|
if (false === @fwrite($this->stream, $message.($newline ? PHP_EOL : ''))) {
|
||||||
// should never happen
|
// should never happen
|
||||||
throw new \RuntimeException('Unable to write output.');
|
throw new RuntimeException('Unable to write output.');
|
||||||
}
|
}
|
||||||
|
|
||||||
fflush($this->stream);
|
fflush($this->stream);
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Console\Question;
|
namespace Symfony\Component\Console\Question;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a choice question.
|
* Represents a choice question.
|
||||||
*
|
*
|
||||||
@ -126,7 +128,7 @@ class ChoiceQuestion extends Question
|
|||||||
if ($multiselect) {
|
if ($multiselect) {
|
||||||
// Check for a separated comma values
|
// Check for a separated comma values
|
||||||
if (!preg_match('/^[a-zA-Z0-9_-]+(?:,[a-zA-Z0-9_-]+)*$/', $selectedChoices, $matches)) {
|
if (!preg_match('/^[a-zA-Z0-9_-]+(?:,[a-zA-Z0-9_-]+)*$/', $selectedChoices, $matches)) {
|
||||||
throw new \InvalidArgumentException(sprintf($errorMessage, $selected));
|
throw new InvalidArgumentException(sprintf($errorMessage, $selected));
|
||||||
}
|
}
|
||||||
$selectedChoices = explode(',', $selectedChoices);
|
$selectedChoices = explode(',', $selectedChoices);
|
||||||
} else {
|
} else {
|
||||||
@ -143,7 +145,7 @@ class ChoiceQuestion extends Question
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (count($results) > 1) {
|
if (count($results) > 1) {
|
||||||
throw new \InvalidArgumentException(sprintf('The provided answer is ambiguous. Value should be one of %s.', implode(' or ', $results)));
|
throw new InvalidArgumentException(sprintf('The provided answer is ambiguous. Value should be one of %s.', implode(' or ', $results)));
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = array_search($value, $choices);
|
$result = array_search($value, $choices);
|
||||||
@ -159,7 +161,7 @@ class ChoiceQuestion extends Question
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (false === $result) {
|
if (false === $result) {
|
||||||
throw new \InvalidArgumentException(sprintf($errorMessage, $value));
|
throw new InvalidArgumentException(sprintf($errorMessage, $value));
|
||||||
}
|
}
|
||||||
|
|
||||||
$multiselectChoices[] = (string) $result;
|
$multiselectChoices[] = (string) $result;
|
||||||
|
@ -11,6 +11,9 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Console\Question;
|
namespace Symfony\Component\Console\Question;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
||||||
|
use Symfony\Component\Console\Exception\LogicException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a Question.
|
* Represents a Question.
|
||||||
*
|
*
|
||||||
@ -76,12 +79,12 @@ class Question
|
|||||||
*
|
*
|
||||||
* @return Question The current instance
|
* @return Question The current instance
|
||||||
*
|
*
|
||||||
* @throws \LogicException In case the autocompleter is also used
|
* @throws LogicException In case the autocompleter is also used
|
||||||
*/
|
*/
|
||||||
public function setHidden($hidden)
|
public function setHidden($hidden)
|
||||||
{
|
{
|
||||||
if ($this->autocompleterValues) {
|
if ($this->autocompleterValues) {
|
||||||
throw new \LogicException('A hidden question cannot use the autocompleter.');
|
throw new LogicException('A hidden question cannot use the autocompleter.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->hidden = (bool) $hidden;
|
$this->hidden = (bool) $hidden;
|
||||||
@ -130,8 +133,8 @@ class Question
|
|||||||
*
|
*
|
||||||
* @return Question The current instance
|
* @return Question The current instance
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
* @throws \LogicException
|
* @throws LogicException
|
||||||
*/
|
*/
|
||||||
public function setAutocompleterValues($values)
|
public function setAutocompleterValues($values)
|
||||||
{
|
{
|
||||||
@ -141,12 +144,12 @@ class Question
|
|||||||
|
|
||||||
if (null !== $values && !is_array($values)) {
|
if (null !== $values && !is_array($values)) {
|
||||||
if (!$values instanceof \Traversable || $values instanceof \Countable) {
|
if (!$values instanceof \Traversable || $values instanceof \Countable) {
|
||||||
throw new \InvalidArgumentException('Autocompleter values can be either an array, `null` or an object implementing both `Countable` and `Traversable` interfaces.');
|
throw new InvalidArgumentException('Autocompleter values can be either an array, `null` or an object implementing both `Countable` and `Traversable` interfaces.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->hidden) {
|
if ($this->hidden) {
|
||||||
throw new \LogicException('A hidden question cannot use the autocompleter.');
|
throw new LogicException('A hidden question cannot use the autocompleter.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->autocompleterValues = $values;
|
$this->autocompleterValues = $values;
|
||||||
@ -187,12 +190,12 @@ class Question
|
|||||||
*
|
*
|
||||||
* @return Question The current instance
|
* @return Question The current instance
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException In case the number of attempts is invalid.
|
* @throws InvalidArgumentException In case the number of attempts is invalid.
|
||||||
*/
|
*/
|
||||||
public function setMaxAttempts($attempts)
|
public function setMaxAttempts($attempts)
|
||||||
{
|
{
|
||||||
if (null !== $attempts && $attempts < 1) {
|
if (null !== $attempts && $attempts < 1) {
|
||||||
throw new \InvalidArgumentException('Maximum number of attempts must be a positive value.');
|
throw new InvalidArgumentException('Maximum number of attempts must be a positive value.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->attempts = $attempts;
|
$this->attempts = $attempts;
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Console;
|
namespace Symfony\Component\Console;
|
||||||
|
|
||||||
|
use Symfony\Component\Console\Exception\RuntimeException;
|
||||||
use Symfony\Component\Console\Input\StringInput;
|
use Symfony\Component\Console\Input\StringInput;
|
||||||
use Symfony\Component\Console\Output\ConsoleOutput;
|
use Symfony\Component\Console\Output\ConsoleOutput;
|
||||||
use Symfony\Component\Process\ProcessBuilder;
|
use Symfony\Component\Process\ProcessBuilder;
|
||||||
@ -222,7 +223,7 @@ EOF;
|
|||||||
$this->processIsolation = (bool) $processIsolation;
|
$this->processIsolation = (bool) $processIsolation;
|
||||||
|
|
||||||
if ($this->processIsolation && !class_exists('Symfony\\Component\\Process\\Process')) {
|
if ($this->processIsolation && !class_exists('Symfony\\Component\\Process\\Process')) {
|
||||||
throw new \RuntimeException('Unable to isolate processes as the Symfony Process Component is not installed.');
|
throw new RuntimeException('Unable to isolate processes as the Symfony Process Component is not installed.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
namespace Symfony\Component\Console\Style;
|
namespace Symfony\Component\Console\Style;
|
||||||
|
|
||||||
use Symfony\Component\Console\Application;
|
use Symfony\Component\Console\Application;
|
||||||
|
use Symfony\Component\Console\Exception\RuntimeException;
|
||||||
use Symfony\Component\Console\Formatter\OutputFormatter;
|
use Symfony\Component\Console\Formatter\OutputFormatter;
|
||||||
use Symfony\Component\Console\Helper\Helper;
|
use Symfony\Component\Console\Helper\Helper;
|
||||||
use Symfony\Component\Console\Helper\ProgressBar;
|
use Symfony\Component\Console\Helper\ProgressBar;
|
||||||
@ -361,7 +362,7 @@ class SymfonyStyle extends OutputStyle
|
|||||||
private function getProgressBar()
|
private function getProgressBar()
|
||||||
{
|
{
|
||||||
if (!$this->progressBar) {
|
if (!$this->progressBar) {
|
||||||
throw new \RuntimeException('The ProgressBar is not started.');
|
throw new RuntimeException('The ProgressBar is not started.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->progressBar;
|
return $this->progressBar;
|
||||||
|
@ -176,7 +176,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \InvalidArgumentException
|
* @expectedException Symfony\Component\Console\Exception\CommandNotFoundException
|
||||||
* @expectedExceptionMessage The command "foofoo" does not exist.
|
* @expectedExceptionMessage The command "foofoo" does not exist.
|
||||||
*/
|
*/
|
||||||
public function testGetInvalidCommand()
|
public function testGetInvalidCommand()
|
||||||
@ -212,7 +212,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \InvalidArgumentException
|
* @expectedException Symfony\Component\Console\Exception\CommandNotFoundException
|
||||||
* @expectedExceptionMessage The namespace "f" is ambiguous (foo, foo1).
|
* @expectedExceptionMessage The namespace "f" is ambiguous (foo, foo1).
|
||||||
*/
|
*/
|
||||||
public function testFindAmbiguousNamespace()
|
public function testFindAmbiguousNamespace()
|
||||||
@ -225,7 +225,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \InvalidArgumentException
|
* @expectedException Symfony\Component\Console\Exception\CommandNotFoundException
|
||||||
* @expectedExceptionMessage There are no commands defined in the "bar" namespace.
|
* @expectedExceptionMessage There are no commands defined in the "bar" namespace.
|
||||||
*/
|
*/
|
||||||
public function testFindInvalidNamespace()
|
public function testFindInvalidNamespace()
|
||||||
@ -235,7 +235,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \InvalidArgumentException
|
* @expectedException Symfony\Component\Console\Exception\CommandNotFoundException
|
||||||
* @expectedExceptionMessage Command "foo1" is not defined
|
* @expectedExceptionMessage Command "foo1" is not defined
|
||||||
*/
|
*/
|
||||||
public function testFindUniqueNameButNamespaceName()
|
public function testFindUniqueNameButNamespaceName()
|
||||||
@ -265,7 +265,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testFindWithAmbiguousAbbreviations($abbreviation, $expectedExceptionMessage)
|
public function testFindWithAmbiguousAbbreviations($abbreviation, $expectedExceptionMessage)
|
||||||
{
|
{
|
||||||
$this->setExpectedException('InvalidArgumentException', $expectedExceptionMessage);
|
$this->setExpectedException('Symfony\Component\Console\Exception\CommandNotFoundException', $expectedExceptionMessage);
|
||||||
|
|
||||||
$application = new Application();
|
$application = new Application();
|
||||||
$application->add(new \FooCommand());
|
$application->add(new \FooCommand());
|
||||||
@ -313,7 +313,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider provideInvalidCommandNamesSingle
|
* @dataProvider provideInvalidCommandNamesSingle
|
||||||
* @expectedException \InvalidArgumentException
|
* @expectedException Symfony\Component\Console\Exception\CommandNotFoundException
|
||||||
* @expectedExceptionMessage Did you mean this
|
* @expectedExceptionMessage Did you mean this
|
||||||
*/
|
*/
|
||||||
public function testFindAlternativeExceptionMessageSingle($name)
|
public function testFindAlternativeExceptionMessageSingle($name)
|
||||||
@ -341,10 +341,10 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
|
|||||||
// Command + plural
|
// Command + plural
|
||||||
try {
|
try {
|
||||||
$application->find('foo:baR');
|
$application->find('foo:baR');
|
||||||
$this->fail('->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
|
$this->fail('->find() throws a CommandNotFoundException if command does not exist, with alternatives');
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
|
$this->assertInstanceOf('Symfony\Component\Console\Exception\CommandNotFoundException', $e, '->find() throws a CommandNotFoundException if command does not exist, with alternatives');
|
||||||
$this->assertRegExp('/Did you mean one of these/', $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
|
$this->assertRegExp('/Did you mean one of these/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternatives');
|
||||||
$this->assertRegExp('/foo1:bar/', $e->getMessage());
|
$this->assertRegExp('/foo1:bar/', $e->getMessage());
|
||||||
$this->assertRegExp('/foo:bar/', $e->getMessage());
|
$this->assertRegExp('/foo:bar/', $e->getMessage());
|
||||||
}
|
}
|
||||||
@ -352,10 +352,10 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
|
|||||||
// Namespace + plural
|
// Namespace + plural
|
||||||
try {
|
try {
|
||||||
$application->find('foo2:bar');
|
$application->find('foo2:bar');
|
||||||
$this->fail('->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
|
$this->fail('->find() throws a CommandNotFoundException if command does not exist, with alternatives');
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
|
$this->assertInstanceOf('Symfony\Component\Console\Exception\CommandNotFoundException', $e, '->find() throws a CommandNotFoundException if command does not exist, with alternatives');
|
||||||
$this->assertRegExp('/Did you mean one of these/', $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
|
$this->assertRegExp('/Did you mean one of these/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternatives');
|
||||||
$this->assertRegExp('/foo1/', $e->getMessage());
|
$this->assertRegExp('/foo1/', $e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -365,9 +365,9 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
|
|||||||
// Subnamespace + plural
|
// Subnamespace + plural
|
||||||
try {
|
try {
|
||||||
$a = $application->find('foo3:');
|
$a = $application->find('foo3:');
|
||||||
$this->fail('->find() should throw an \InvalidArgumentException if a command is ambiguous because of a subnamespace, with alternatives');
|
$this->fail('->find() should throw an Symfony\Component\Console\Exception\CommandNotFoundException if a command is ambiguous because of a subnamespace, with alternatives');
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->assertInstanceOf('\InvalidArgumentException', $e);
|
$this->assertInstanceOf('Symfony\Component\Console\Exception\CommandNotFoundException', $e);
|
||||||
$this->assertRegExp('/foo3:bar/', $e->getMessage());
|
$this->assertRegExp('/foo3:bar/', $e->getMessage());
|
||||||
$this->assertRegExp('/foo3:bar:toh/', $e->getMessage());
|
$this->assertRegExp('/foo3:bar:toh/', $e->getMessage());
|
||||||
}
|
}
|
||||||
@ -383,23 +383,25 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$application->find($commandName = 'Unknown command');
|
$application->find($commandName = 'Unknown command');
|
||||||
$this->fail('->find() throws an \InvalidArgumentException if command does not exist');
|
$this->fail('->find() throws a CommandNotFoundException if command does not exist');
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if command does not exist');
|
$this->assertInstanceOf('Symfony\Component\Console\Exception\CommandNotFoundException', $e, '->find() throws a CommandNotFoundException if command does not exist');
|
||||||
$this->assertEquals(sprintf('Command "%s" is not defined.', $commandName), $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, without alternatives');
|
$this->assertSame(array(), $e->getAlternatives());
|
||||||
|
$this->assertEquals(sprintf('Command "%s" is not defined.', $commandName), $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, without alternatives');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test if "bar1" command throw an "\InvalidArgumentException" and does not contain
|
// Test if "bar1" command throw a "CommandNotFoundException" and does not contain
|
||||||
// "foo:bar" as alternative because "bar1" is too far from "foo:bar"
|
// "foo:bar" as alternative because "bar1" is too far from "foo:bar"
|
||||||
try {
|
try {
|
||||||
$application->find($commandName = 'bar1');
|
$application->find($commandName = 'bar1');
|
||||||
$this->fail('->find() throws an \InvalidArgumentException if command does not exist');
|
$this->fail('->find() throws a CommandNotFoundException if command does not exist');
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if command does not exist');
|
$this->assertInstanceOf('Symfony\Component\Console\Exception\CommandNotFoundException', $e, '->find() throws a CommandNotFoundException if command does not exist');
|
||||||
$this->assertRegExp(sprintf('/Command "%s" is not defined./', $commandName), $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with alternatives');
|
$this->assertSame(array('afoobar1', 'foo:bar1'), $e->getAlternatives());
|
||||||
$this->assertRegExp('/afoobar1/', $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with alternative : "afoobar1"');
|
$this->assertRegExp(sprintf('/Command "%s" is not defined./', $commandName), $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternatives');
|
||||||
$this->assertRegExp('/foo:bar1/', $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, with alternative : "foo:bar1"');
|
$this->assertRegExp('/afoobar1/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternative : "afoobar1"');
|
||||||
$this->assertNotRegExp('/foo:bar(?>!1)/', $e->getMessage(), '->find() throws an \InvalidArgumentException if command does not exist, without "foo:bar" alternative');
|
$this->assertRegExp('/foo:bar1/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, with alternative : "foo:bar1"');
|
||||||
|
$this->assertNotRegExp('/foo:bar(?>!1)/', $e->getMessage(), '->find() throws a CommandNotFoundException if command does not exist, without "foo:bar" alternative');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -427,21 +429,23 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$application->find('Unknown-namespace:Unknown-command');
|
$application->find('Unknown-namespace:Unknown-command');
|
||||||
$this->fail('->find() throws an \InvalidArgumentException if namespace does not exist');
|
$this->fail('->find() throws a CommandNotFoundException if namespace does not exist');
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if namespace does not exist');
|
$this->assertInstanceOf('Symfony\Component\Console\Exception\CommandNotFoundException', $e, '->find() throws a CommandNotFoundException if namespace does not exist');
|
||||||
$this->assertEquals('There are no commands defined in the "Unknown-namespace" namespace.', $e->getMessage(), '->find() throws an \InvalidArgumentException if namespace does not exist, without alternatives');
|
$this->assertSame(array(), $e->getAlternatives());
|
||||||
|
$this->assertEquals('There are no commands defined in the "Unknown-namespace" namespace.', $e->getMessage(), '->find() throws a CommandNotFoundException if namespace does not exist, without alternatives');
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$application->find('foo2:command');
|
$application->find('foo2:command');
|
||||||
$this->fail('->find() throws an \InvalidArgumentException if namespace does not exist');
|
$this->fail('->find() throws a CommandNotFoundException if namespace does not exist');
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->find() throws an \InvalidArgumentException if namespace does not exist');
|
$this->assertInstanceOf('Symfony\Component\Console\Exception\CommandNotFoundException', $e, '->find() throws a CommandNotFoundException if namespace does not exist');
|
||||||
$this->assertRegExp('/There are no commands defined in the "foo2" namespace./', $e->getMessage(), '->find() throws an \InvalidArgumentException if namespace does not exist, with alternative');
|
$this->assertSame(array('foo3', 'foo1', 'foo'), $e->getAlternatives());
|
||||||
$this->assertRegExp('/foo/', $e->getMessage(), '->find() throws an \InvalidArgumentException if namespace does not exist, with alternative : "foo"');
|
$this->assertRegExp('/There are no commands defined in the "foo2" namespace./', $e->getMessage(), '->find() throws a CommandNotFoundException if namespace does not exist, with alternative');
|
||||||
$this->assertRegExp('/foo1/', $e->getMessage(), '->find() throws an \InvalidArgumentException if namespace does not exist, with alternative : "foo1"');
|
$this->assertRegExp('/foo/', $e->getMessage(), '->find() throws a CommandNotFoundException if namespace does not exist, with alternative : "foo"');
|
||||||
$this->assertRegExp('/foo3/', $e->getMessage(), '->find() throws an \InvalidArgumentException if namespace does not exist, with alternative : "foo3"');
|
$this->assertRegExp('/foo1/', $e->getMessage(), '->find() throws a CommandNotFoundException if namespace does not exist, with alternative : "foo1"');
|
||||||
|
$this->assertRegExp('/foo3/', $e->getMessage(), '->find() throws a CommandNotFoundException if namespace does not exist, with alternative : "foo3"');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -456,7 +460,7 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \InvalidArgumentException
|
* @expectedException Symfony\Component\Console\Exception\CommandNotFoundException
|
||||||
* @expectedExceptionMessage Command "foo::bar" is not defined.
|
* @expectedExceptionMessage Command "foo::bar" is not defined.
|
||||||
*/
|
*/
|
||||||
public function testFindWithDoubleColonInNameThrowsException()
|
public function testFindWithDoubleColonInNameThrowsException()
|
||||||
|
@ -243,7 +243,7 @@ class CommandTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \InvalidArgumentException
|
* @expectedException Symfony\Component\Console\Exception\InvalidOptionException
|
||||||
* @expectedExceptionMessage The "--bar" option does not exist.
|
* @expectedExceptionMessage The "--bar" option does not exist.
|
||||||
*/
|
*/
|
||||||
public function testRunWithInvalidOption()
|
public function testRunWithInvalidOption()
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
[InvalidArgumentException]
|
[Symfony\Component\Console\Exception\CommandNotFoundException]
|
||||||
Command "foo" is not defined.
|
Command "foo" is not defined.
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
[InvalidArgumentException]
|
[Symfony\Component\Console\Exception\InvalidOptionException]
|
||||||
The "--foo" option does not exist.
|
The "--foo" option does not exist.
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
[InvalidArgumentException]
|
[Symfony\Component\Console\Exception\CommandNotFoundException]
|
||||||
Command "foo" is not define
|
Command "foo" is not define
|
||||||
d.
|
d.
|
||||||
|
|
||||||
|
@ -75,10 +75,11 @@ class HelperSetTest extends \PHPUnit_Framework_TestCase
|
|||||||
$helperset = new HelperSet();
|
$helperset = new HelperSet();
|
||||||
try {
|
try {
|
||||||
$helperset->get('foo');
|
$helperset->get('foo');
|
||||||
$this->fail('->get() throws \InvalidArgumentException when helper not found');
|
$this->fail('->get() throws InvalidArgumentException when helper not found');
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->assertInstanceOf('\InvalidArgumentException', $e, '->get() throws \InvalidArgumentException when helper not found');
|
$this->assertInstanceOf('\InvalidArgumentException', $e, '->get() throws InvalidArgumentException when helper not found');
|
||||||
$this->assertContains('The helper "foo" is not defined.', $e->getMessage(), '->get() throws \InvalidArgumentException when helper not found');
|
$this->assertInstanceOf('Symfony\Component\Console\Exception\ExceptionInterface', $e, '->get() throws domain specific exception when helper not found');
|
||||||
|
$this->assertContains('The helper "foo" is not defined.', $e->getMessage(), '->get() throws InvalidArgumentException when helper not found');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ use Symfony\Component\Console\Helper\DialogHelper;
|
|||||||
use Symfony\Component\Console\Helper\HelperSet;
|
use Symfony\Component\Console\Helper\HelperSet;
|
||||||
use Symfony\Component\Console\Helper\FormatterHelper;
|
use Symfony\Component\Console\Helper\FormatterHelper;
|
||||||
use Symfony\Component\Console\Output\StreamOutput;
|
use Symfony\Component\Console\Output\StreamOutput;
|
||||||
|
use Symfony\Component\Console\Exception\InvalidArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group legacy
|
* @group legacy
|
||||||
@ -141,7 +142,7 @@ class LegacyDialogHelperTest extends \PHPUnit_Framework_TestCase
|
|||||||
$error = 'This is not a color!';
|
$error = 'This is not a color!';
|
||||||
$validator = function ($color) use ($error) {
|
$validator = function ($color) use ($error) {
|
||||||
if (!in_array($color, array('white', 'black'))) {
|
if (!in_array($color, array('white', 'black'))) {
|
||||||
throw new \InvalidArgumentException($error);
|
throw new InvalidArgumentException($error);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $color;
|
return $color;
|
||||||
|
Reference in New Issue
Block a user