Commit 8cbebc3a authored by Benjamin Eberlei's avatar Benjamin Eberlei

DBAL-16 - Update Symfony\Component\Console to fix upstream bug

parent fd2e8fa0
......@@ -10,7 +10,7 @@ use Symfony\Component\Console\Output\Output;
use Symfony\Component\Console\Command\Command;
/*
* This file is part of the symfony framework.
* This file is part of the Symfony framework.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
......@@ -21,63 +21,57 @@ use Symfony\Component\Console\Command\Command;
/**
* HelpCommand displays the help for a given command.
*
* @package symfony
* @subpackage console
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
class HelpCommand extends Command
{
protected $command;
protected $command;
/**
* @see Command
*/
protected function configure()
{
$this->ignoreValidationErrors = true;
/**
* @see Command
*/
protected function configure()
{
$this->ignoreValidationErrors = true;
$this
->setDefinition(array(
new InputArgument('command_name', InputArgument::OPTIONAL, 'The command name', 'help'),
new InputOption('xml', null, InputOption::PARAMETER_NONE, 'To output help as XML'),
))
->setName('help')
->setAliases(array('?'))
->setDescription('Displays help for a command')
->setHelp(<<<EOF
$this
->setDefinition(array(
new InputArgument('command_name', InputArgument::OPTIONAL, 'The command name', 'help'),
new InputOption('xml', null, InputOption::PARAMETER_NONE, 'To output help as XML'),
))
->setName('help')
->setAliases(array('?'))
->setDescription('Displays help for a command')
->setHelp(<<<EOF
The <info>help</info> command displays help for a given command:
<info>./symfony help test:all</info>
<info>./symfony help list</info>
You can also output the help as XML by using the <comment>--xml</comment> option:
<info>./symfony help --xml test:all</info>
<info>./symfony help --xml list</info>
EOF
);
}
public function setCommand(Command $command)
{
$this->command = $command;
}
/**
* @see Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
if (null === $this->command)
{
$this->command = $this->application->getCommand($input->getArgument('command_name'));
);
}
if ($input->getOption('xml'))
public function setCommand(Command $command)
{
$output->writeln($this->command->asXml(), Output::OUTPUT_RAW);
$this->command = $command;
}
else
/**
* @see Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln($this->command->asText());
if (null === $this->command) {
$this->command = $this->application->getCommand($input->getArgument('command_name'));
}
if ($input->getOption('xml')) {
$output->writeln($this->command->asXml(), Output::OUTPUT_RAW);
} else {
$output->writeln($this->command->asText());
}
}
}
}
......@@ -10,7 +10,7 @@ use Symfony\Component\Console\Output\Output;
use Symfony\Component\Console\Command\Command;
/*
* This file is part of the symfony framework.
* This file is part of the Symfony framework.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
......@@ -21,25 +21,23 @@ use Symfony\Component\Console\Command\Command;
/**
* ListCommand displays the list of all available commands for the application.
*
* @package symfony
* @subpackage console
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
class ListCommand extends Command
{
/**
* @see Command
*/
protected function configure()
{
$this
->setDefinition(array(
new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name'),
new InputOption('xml', null, InputOption::PARAMETER_NONE, 'To output help as XML'),
))
->setName('list')
->setDescription('Lists commands')
->setHelp(<<<EOF
/**
* @see Command
*/
protected function configure()
{
$this
->setDefinition(array(
new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name'),
new InputOption('xml', null, InputOption::PARAMETER_NONE, 'To output help as XML'),
))
->setName('list')
->setDescription('Lists commands')
->setHelp(<<<EOF
The <info>list</info> command lists all commands:
<info>./symfony list</info>
......@@ -52,21 +50,18 @@ You can also output the information as XML by using the <comment>--xml</comment>
<info>./symfony list --xml</info>
EOF
);
}
/**
* @see Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
if ($input->getOption('xml'))
{
$output->writeln($this->application->asXml($input->getArgument('namespace')), Output::OUTPUT_RAW);
);
}
else
/**
* @see Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln($this->application->asText($input->getArgument('namespace')));
if ($input->getOption('xml')) {
$output->writeln($this->application->asXml($input->getArgument('namespace')), Output::OUTPUT_RAW);
} else {
$output->writeln($this->application->asText($input->getArgument('namespace')));
}
}
}
}
......@@ -5,7 +5,7 @@ namespace Symfony\Component\Console\Helper;
use Symfony\Component\Console\Output\OutputInterface;
/*
* This file is part of the symfony framework.
* This file is part of the Symfony framework.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
......@@ -16,104 +16,95 @@ use Symfony\Component\Console\Output\OutputInterface;
/**
* The Dialog class provides helpers to interact with the user.
*
* @package symfony
* @subpackage console
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
class DialogHelper extends Helper
{
/**
* Asks a question to the user.
*
* @param OutputInterface $output
* @param string|array $question The question to ask
* @param string $default The default answer if none is given by the user
*
* @param string The user answer
*/
public function ask(OutputInterface $output, $question, $default = null)
{
// @codeCoverageIgnoreStart
$output->writeln($question);
$ret = trim(fgets(STDIN));
/**
* Asks a question to the user.
*
* @param OutputInterface $output
* @param string|array $question The question to ask
* @param string $default The default answer if none is given by the user
*
* @return string The user answer
*/
public function ask(OutputInterface $output, $question, $default = null)
{
// @codeCoverageIgnoreStart
$output->writeln($question);
return $ret ? $ret : $default;
// @codeCoverageIgnoreEnd
}
$ret = trim(fgets(STDIN));
/**
* Asks a confirmation to the user.
*
* The question will be asked until the user answer by nothing, yes, or no.
*
* @param OutputInterface $output
* @param string|array $question The question to ask
* @param Boolean $default The default answer if the user enters nothing
*
* @param Boolean true if the user has confirmed, false otherwise
*/
public function askConfirmation(OutputInterface $output, $question, $default = true)
{
// @codeCoverageIgnoreStart
$answer = 'z';
while ($answer && !in_array(strtolower($answer[0]), array('y', 'n')))
{
$answer = $this->ask($output, $question);
return $ret ? $ret : $default;
// @codeCoverageIgnoreEnd
}
if (false === $default)
{
return $answer && 'y' == strtolower($answer[0]);
}
else
/**
* Asks a confirmation to the user.
*
* The question will be asked until the user answer by nothing, yes, or no.
*
* @param OutputInterface $output
* @param string|array $question The question to ask
* @param Boolean $default The default answer if the user enters nothing
*
* @return Boolean true if the user has confirmed, false otherwise
*/
public function askConfirmation(OutputInterface $output, $question, $default = true)
{
return !$answer || 'y' == strtolower($answer[0]);
// @codeCoverageIgnoreStart
$answer = 'z';
while ($answer && !in_array(strtolower($answer[0]), array('y', 'n'))) {
$answer = $this->ask($output, $question);
}
if (false === $default) {
return $answer && 'y' == strtolower($answer[0]);
} else {
return !$answer || 'y' == strtolower($answer[0]);
}
// @codeCoverageIgnoreEnd
}
// @codeCoverageIgnoreEnd
}
/**
* Asks for a value and validates the response.
*
* @param OutputInterface $output
* @param string|array $question
* @param Closure $validator
* @param integer $attempts Max number of times to ask before giving up (false by default, which means infinite)
*
* @return mixed
*/
public function askAndValidate(OutputInterface $output, $question, \Closure $validator, $attempts = false)
{
// @codeCoverageIgnoreStart
$error = null;
while (false === $attempts || $attempts--)
/**
* Asks for a value and validates the response.
*
* @param OutputInterface $output
* @param string|array $question
* @param Closure $validator
* @param integer $attempts Max number of times to ask before giving up (false by default, which means infinite)
*
* @return mixed
*
* @throws \Exception When any of the validator returns an error
*/
public function askAndValidate(OutputInterface $output, $question, \Closure $validator, $attempts = false)
{
if (null !== $error)
{
$output->writeln($this->getHelperSet()->get('formatter')->formatBlock($error->getMessage(), 'error'));
}
// @codeCoverageIgnoreStart
$error = null;
while (false === $attempts || $attempts--) {
if (null !== $error) {
$output->writeln($this->getHelperSet()->get('formatter')->formatBlock($error->getMessage(), 'error'));
}
$value = $this->ask($output, $question, null);
$value = $this->ask($output, $question, null);
try
{
return $validator($value);
}
catch (\Exception $error)
{
}
}
try {
return $validator($value);
} catch (\Exception $error) {
}
}
throw $error;
// @codeCoverageIgnoreEnd
}
throw $error;
// @codeCoverageIgnoreEnd
}
/**
* Returns the helper's canonical name
*/
public function getName()
{
return 'dialog';
}
/**
* Returns the helper's canonical name
*/
public function getName()
{
return 'dialog';
}
}
......@@ -3,7 +3,7 @@
namespace Symfony\Component\Console\Helper;
/*
* This file is part of the symfony framework.
* This file is part of the Symfony framework.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
......@@ -14,76 +14,69 @@ namespace Symfony\Component\Console\Helper;
/**
* The Formatter class provides helpers to format messages.
*
* @package symfony
* @subpackage console
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
class FormatterHelper extends Helper
{
/**
* Formats a message within a section.
*
* @param string $section The section name
* @param string $message The message
* @param string $style The style to apply to the section
*/
public function formatSection($section, $message, $style = 'info')
{
return sprintf("<%s>[%s]</%s> %s", $style, $section, $style, $message);
}
/**
* Formats a message as a block of text.
*
* @param string|array $messages The message to write in the block
* @param string $style The style to apply to the whole block
* @param Boolean $large Whether to return a large block
*
* @return string The formatter message
*/
public function formatBlock($messages, $style, $large = false)
{
if (!is_array($messages))
/**
* Formats a message within a section.
*
* @param string $section The section name
* @param string $message The message
* @param string $style The style to apply to the section
*/
public function formatSection($section, $message, $style = 'info')
{
$messages = array($messages);
return sprintf('<%s>[%s]</%s> %s', $style, $section, $style, $message);
}
$len = 0;
$lines = array();
foreach ($messages as $message)
/**
* Formats a message as a block of text.
*
* @param string|array $messages The message to write in the block
* @param string $style The style to apply to the whole block
* @param Boolean $large Whether to return a large block
*
* @return string The formatter message
*/
public function formatBlock($messages, $style, $large = false)
{
$lines[] = sprintf($large ? ' %s ' : ' %s ', $message);
$len = max($this->strlen($message) + ($large ? 4 : 2), $len);
}
if (!is_array($messages)) {
$messages = array($messages);
}
$messages = $large ? array(str_repeat(' ', $len)) : array();
foreach ($lines as $line)
{
$messages[] = $line.str_repeat(' ', $len - $this->strlen($line));
$len = 0;
$lines = array();
foreach ($messages as $message) {
$lines[] = sprintf($large ? ' %s ' : ' %s ', $message);
$len = max($this->strlen($message) + ($large ? 4 : 2), $len);
}
$messages = $large ? array(str_repeat(' ', $len)) : array();
foreach ($lines as $line) {
$messages[] = $line.str_repeat(' ', $len - $this->strlen($line));
}
if ($large) {
$messages[] = str_repeat(' ', $len);
}
foreach ($messages as &$message) {
$message = sprintf('<%s>%s</%s>', $style, $message, $style);
}
return implode("\n", $messages);
}
if ($large)
protected function strlen($string)
{
$messages[] = str_repeat(' ', $len);
return function_exists('mb_strlen') ? mb_strlen($string) : strlen($string);
}
foreach ($messages as &$message)
/**
* Returns the helper's canonical name
*/
public function getName()
{
$message = sprintf('<%s>%s</%s>', $style, $message, $style);
return 'formatter';
}
return implode("\n", $messages);
}
protected function strlen($string)
{
return function_exists('mb_strlen') ? mb_strlen($string) : strlen($string);
}
/**
* Returns the helper's canonical name
*/
public function getName()
{
return 'formatter';
}
}
......@@ -3,7 +3,7 @@
namespace Symfony\Component\Console\Helper;
/*
* This file is part of the symfony framework.
* This file is part of the Symfony framework.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
......@@ -14,32 +14,29 @@ namespace Symfony\Component\Console\Helper;
/**
* Helper is the base class for all helper classes.
*
* @package symfony
* @subpackage console
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
abstract class Helper implements HelperInterface
{
protected
$helperSet = null;
protected $helperSet = null;
/**
* Sets the helper set associated with this helper.
*
* @param HelperSet $helperSet A HelperSet instance
*/
public function setHelperSet(HelperSet $helperSet = null)
{
$this->helperSet = $helperSet;
}
/**
* Sets the helper set associated with this helper.
*
* @param HelperSet $helperSet A HelperSet instance
*/
public function setHelperSet(HelperSet $helperSet = null)
{
$this->helperSet = $helperSet;
}
/**
* Gets the helper set associated with this helper.
*
* @return HelperSet A HelperSet instance
*/
public function getHelperSet()
{
return $this->helperSet;
}
/**
* Gets the helper set associated with this helper.
*
* @return HelperSet A HelperSet instance
*/
public function getHelperSet()
{
return $this->helperSet;
}
}
......@@ -3,7 +3,7 @@
namespace Symfony\Component\Console\Helper;
/*
* This file is part of the symfony framework.
* This file is part of the Symfony framework.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
......@@ -14,30 +14,28 @@ namespace Symfony\Component\Console\Helper;
/**
* HelperInterface is the interface all helpers must implement.
*
* @package symfony
* @subpackage console
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
interface HelperInterface
{
/**
* Sets the helper set associated with this helper.
*
* @param HelperSet $helperSet A HelperSet instance
*/
function setHelperSet(HelperSet $helperSet = null);
/**
* Sets the helper set associated with this helper.
*
* @param HelperSet $helperSet A HelperSet instance
*/
function setHelperSet(HelperSet $helperSet = null);
/**
* Gets the helper set associated with this helper.
*
* @return HelperSet A HelperSet instance
*/
function getHelperSet();
/**
* Gets the helper set associated with this helper.
*
* @return HelperSet A HelperSet instance
*/
function getHelperSet();
/**
* Returns the canonical name of this helper.
*
* @return string The canonical name
*/
function getName();
/**
* Returns the canonical name of this helper.
*
* @return string The canonical name
*/
function getName();
}
......@@ -5,7 +5,7 @@ namespace Symfony\Component\Console\Helper;
use Symfony\Component\Console\Command\Command;
/*
* This file is part of the symfony framework.
* This file is part of the Symfony framework.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
......@@ -16,89 +16,87 @@ use Symfony\Component\Console\Command\Command;
/**
* HelperSet represents a set of helpers to be used with a command.
*
* @package symfony
* @subpackage console
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
class HelperSet
{
protected
$helpers = array(),
$command = null;
protected $helpers;
protected $command;
public function __construct(array $helpers = array())
{
foreach ($helpers as $alias => $helper)
/**
* @param Helper[] $helpers An array of helper.
*/
public function __construct(array $helpers = array())
{
$this->set($helper, is_int($alias) ? null : $alias);
$this->helpers = array();
foreach ($helpers as $alias => $helper) {
$this->set($helper, is_int($alias) ? null : $alias);
}
}
}
/**
* Sets a helper.
*
* @param HelperInterface $value The helper instance
* @param string $alias An alias
*/
public function set(HelperInterface $helper, $alias = null)
{
$this->helpers[$helper->getName()] = $helper;
if (null !== $alias)
/**
* Sets a helper.
*
* @param HelperInterface $value The helper instance
* @param string $alias An alias
*/
public function set(HelperInterface $helper, $alias = null)
{
$this->helpers[$alias] = $helper;
}
$helper->setHelperSet($this);
}
$this->helpers[$helper->getName()] = $helper;
if (null !== $alias) {
$this->helpers[$alias] = $helper;
}
/**
* Returns true if the helper if defined.
*
* @param string $name The helper name
*
* @return Boolean true if the helper is defined, false otherwise
*/
public function has($name)
{
return isset($this->helpers[$name]);
}
$helper->setHelperSet($this);
}
/**
* Gets a helper value.
*
* @param string $name The helper name
*
* @return HelperInterface The helper instance
*
* @throws \InvalidArgumentException if the helper is not defined
*/
public function get($name)
{
if (!$this->has($name))
/**
* Returns true if the helper if defined.
*
* @param string $name The helper name
*
* @return Boolean true if the helper is defined, false otherwise
*/
public function has($name)
{
throw new \InvalidArgumentException(sprintf('The helper "%s" is not defined.', $name));
return isset($this->helpers[$name]);
}
return $this->helpers[$name];
}
/**
* Gets a helper value.
*
* @param string $name The helper name
*
* @return HelperInterface The helper instance
*
* @throws \InvalidArgumentException if the helper is not defined
*/
public function get($name)
{
if (!$this->has($name)) {
throw new \InvalidArgumentException(sprintf('The helper "%s" is not defined.', $name));
}
return $this->helpers[$name];
}
/**
* Sets the command associated with this helper set.
*
* @param Command $command A Command instance
*/
public function setCommand(Command $command = null)
{
$this->command = $command;
}
/**
* Sets the command associated with this helper set.
*
* @param Command $command A Command instance
*/
public function setCommand(Command $command = null)
{
$this->command = $command;
}
/**
* Gets the command associated with this helper set.
*
* @return Command A Command instance
*/
public function getCommand()
{
return $this->command;
}
/**
* Gets the command associated with this helper set.
*
* @return Command A Command instance
*/
public function getCommand()
{
return $this->command;
}
}
......@@ -3,7 +3,7 @@
namespace Symfony\Component\Console\Input;
/*
* This file is part of the symfony framework.
* This file is part of the Symfony framework.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
......@@ -18,157 +18,145 @@ namespace Symfony\Component\Console\Input;
*
* $input = new ArrayInput(array('name' => 'foo', '--bar' => 'foobar'));
*
* @package symfony
* @subpackage console
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
class ArrayInput extends Input
{
protected $parameters;
/**
* Constructor.
*
* @param array $param An array of parameters
* @param InputDefinition $definition A InputDefinition instance
*/
public function __construct(array $parameters, InputDefinition $definition = null)
{
$this->parameters = $parameters;
parent::__construct($definition);
}
/**
* Returns the first argument from the raw parameters (not parsed).
*
* @return string The value of the first argument or null otherwise
*/
public function getFirstArgument()
{
foreach ($this->parameters as $key => $value)
protected $parameters;
/**
* Constructor.
*
* @param array $param An array of parameters
* @param InputDefinition $definition A InputDefinition instance
*/
public function __construct(array $parameters, InputDefinition $definition = null)
{
if ($key && '-' === $key[0])
{
continue;
}
$this->parameters = $parameters;
return $value;
parent::__construct($definition);
}
}
/**
* Returns true if the raw parameters (not parsed) contains a value.
*
* This method is to be used to introspect the input parameters
* before it has been validated. It must be used carefully.
*
* @param string|array $value The values to look for in the raw parameters (can be an array)
*
* @return Boolean true if the value is contained in the raw parameters
*/
public function hasParameterOption($values)
{
if (!is_array($values))
/**
* Returns the first argument from the raw parameters (not parsed).
*
* @return string The value of the first argument or null otherwise
*/
public function getFirstArgument()
{
$values = array($values);
foreach ($this->parameters as $key => $value) {
if ($key && '-' === $key[0]) {
continue;
}
return $value;
}
}
foreach ($this->parameters as $k => $v)
/**
* Returns true if the raw parameters (not parsed) contains a value.
*
* This method is to be used to introspect the input parameters
* before it has been validated. It must be used carefully.
*
* @param string|array $value The values to look for in the raw parameters (can be an array)
*
* @return Boolean true if the value is contained in the raw parameters
*/
public function hasParameterOption($values)
{
if (!is_int($k))
{
$v = $k;
}
if (in_array($v, $values))
{
return true;
}
}
if (!is_array($values)) {
$values = array($values);
}
return false;
}
foreach ($this->parameters as $k => $v) {
if (!is_int($k)) {
$v = $k;
}
/**
* Processes command line arguments.
*/
protected function parse()
{
foreach ($this->parameters as $key => $value)
{
if ('--' === substr($key, 0, 2))
{
$this->addLongOption(substr($key, 2), $value);
}
elseif ('-' === $key[0])
{
$this->addShortOption(substr($key, 1), $value);
}
else
{
$this->addArgument($key, $value);
}
if (in_array($v, $values)) {
return true;
}
}
return false;
}
}
/**
* Adds a short option value.
*
* @param string $shortcut The short option key
* @param mixed $value The value for the option
*/
protected function addShortOption($shortcut, $value)
{
if (!$this->definition->hasShortcut($shortcut))
/**
* Processes command line arguments.
*/
protected function parse()
{
throw new \RuntimeException(sprintf('The "-%s" option does not exist.', $shortcut));
foreach ($this->parameters as $key => $value) {
if ('--' === substr($key, 0, 2)) {
$this->addLongOption(substr($key, 2), $value);
} elseif ('-' === $key[0]) {
$this->addShortOption(substr($key, 1), $value);
} else {
$this->addArgument($key, $value);
}
}
}
$this->addLongOption($this->definition->getOptionForShortcut($shortcut)->getName(), $value);
}
/**
* Adds a long option value.
*
* @param string $name The long option key
* @param mixed $value The value for the option
*/
protected function addLongOption($name, $value)
{
if (!$this->definition->hasOption($name))
/**
* Adds a short option value.
*
* @param string $shortcut The short option key
* @param mixed $value The value for the option
*
* @throws \RuntimeException When option given doesn't exist
*/
protected function addShortOption($shortcut, $value)
{
throw new \RuntimeException(sprintf('The "--%s" option does not exist.', $name));
}
if (!$this->definition->hasShortcut($shortcut)) {
throw new \InvalidArgumentException(sprintf('The "-%s" option does not exist.', $shortcut));
}
$option = $this->definition->getOption($name);
$this->addLongOption($this->definition->getOptionForShortcut($shortcut)->getName(), $value);
}
if (null === $value)
/**
* Adds a long option value.
*
* @param string $name The long option key
* @param mixed $value The value for the option
*
* @throws \InvalidArgumentException When option given doesn't exist
* @throws \InvalidArgumentException When a required value is missing
*/
protected function addLongOption($name, $value)
{
if ($option->isParameterRequired())
{
throw new \RuntimeException(sprintf('The "--%s" option requires a value.', $name));
}
if (!$this->definition->hasOption($name)) {
throw new \InvalidArgumentException(sprintf('The "--%s" option does not exist.', $name));
}
$option = $this->definition->getOption($name);
if (null === $value) {
if ($option->isParameterRequired()) {
throw new \InvalidArgumentException(sprintf('The "--%s" option requires a value.', $name));
}
$value = $option->isParameterOptional() ? $option->getDefault() : true;
$value = $option->isParameterOptional() ? $option->getDefault() : true;
}
$this->options[$name] = $value;
}
$this->options[$name] = $value;
}
/**
* Adds an argument value.
*
* @param string $name The argument name
* @param mixed $value The value for the argument
*/
protected function addArgument($name, $value)
{
if (!$this->definition->hasArgument($name))
/**
* Adds an argument value.
*
* @param string $name The argument name
* @param mixed $value The value for the argument
*
* @throws \InvalidArgumentException When argument given doesn't exist
*/
protected function addArgument($name, $value)
{
throw new \RuntimeException(sprintf('The "%s" argument does not exist.', $name));
}
if (!$this->definition->hasArgument($name)) {
throw new \InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
}
$this->arguments[$name] = $value;
}
$this->arguments[$name] = $value;
}
}
......@@ -3,7 +3,7 @@
namespace Symfony\Component\Console\Input;
/*
* This file is part of the symfony framework.
* This file is part of the Symfony framework.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
......@@ -20,179 +20,180 @@ namespace Symfony\Component\Console\Input;
* * `StringInput`: The input is provided as a string
* * `ArrayInput`: The input is provided as an array
*
* @package symfony
* @subpackage console
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
abstract class Input implements InputInterface
{
protected $definition;
protected $options;
protected $arguments;
protected $interactive = true;
/**
* Constructor.
*
* @param InputDefinition $definition A InputDefinition instance
*/
public function __construct(InputDefinition $definition = null)
{
if (null === $definition)
protected $definition;
protected $options;
protected $arguments;
protected $interactive = true;
/**
* Constructor.
*
* @param InputDefinition $definition A InputDefinition instance
*/
public function __construct(InputDefinition $definition = null)
{
$this->definition = new InputDefinition();
if (null === $definition) {
$this->definition = new InputDefinition();
} else {
$this->bind($definition);
$this->validate();
}
}
else
/**
* Binds the current Input instance with the given arguments and options.
*
* @param InputDefinition $definition A InputDefinition instance
*/
public function bind(InputDefinition $definition)
{
$this->arguments = array();
$this->options = array();
$this->definition = $definition;
$this->parse();
}
/**
* Processes command line arguments.
*/
abstract protected function parse();
/**
* @throws \RuntimeException When not enough arguments are given
*/
public function validate()
{
if (count($this->arguments) < $this->definition->getArgumentRequiredCount()) {
throw new \RuntimeException('Not enough arguments.');
}
}
public function isInteractive()
{
return $this->interactive;
}
public function setInteractive($interactive)
{
$this->interactive = (Boolean) $interactive;
}
/**
* Returns the argument values.
*
* @return array An array of argument values
*/
public function getArguments()
{
$this->bind($definition);
$this->validate();
return array_merge($this->definition->getArgumentDefaults(), $this->arguments);
}
}
/**
* Binds the current Input instance with the given arguments and options.
*
* @param InputDefinition $definition A InputDefinition instance
*/
public function bind(InputDefinition $definition)
{
$this->arguments = array();
$this->options = array();
$this->definition = $definition;
$this->parse();
}
/**
* Processes command line arguments.
*/
abstract protected function parse();
public function validate()
{
if (count($this->arguments) < $this->definition->getArgumentRequiredCount())
/**
* Returns the argument value for a given argument name.
*
* @param string $name The argument name
*
* @return mixed The argument value
*
* @throws \InvalidArgumentException When argument given doesn't exist
*/
public function getArgument($name)
{
throw new \RuntimeException('Not enough arguments.');
if (!$this->definition->hasArgument($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();
}
}
public function isInteractive()
{
return $this->interactive;
}
public function setInteractive($interactive)
{
$this->interactive = (Boolean) $interactive;
}
/**
* Returns the argument values.
*
* @return array An array of argument values
*/
public function getArguments()
{
return array_merge($this->definition->getArgumentDefaults(), $this->arguments);
}
/**
* Returns the argument value for a given argument name.
*
* @param string $name The argument name
*
* @return mixed The argument value
*/
public function getArgument($name)
{
if (!$this->definition->hasArgument($name))
/**
* Sets an argument value by name.
*
* @param string $name The argument name
* @param string $value The argument value
*
* @throws \InvalidArgumentException When argument given doesn't exist
*/
public function setArgument($name, $value)
{
throw new \InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
if (!$this->definition->hasArgument($name)) {
throw new \InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
}
$this->arguments[$name] = $value;
}
return isset($this->arguments[$name]) ? $this->arguments[$name] : $this->definition->getArgument($name)->getDefault();
}
/**
* Sets an argument value by name.
*
* @param string $name The argument name
* @param string $value The argument value
*/
public function setArgument($name, $value)
{
if (!$this->definition->hasArgument($name))
/**
* Returns true if an InputArgument object exists by name or position.
*
* @param string|integer $name The InputArgument name or position
*
* @return Boolean true if the InputArgument object exists, false otherwise
*/
public function hasArgument($name)
{
throw new \InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
return $this->definition->hasArgument($name);
}
$this->arguments[$name] = $value;
}
/**
* Returns true if an InputArgument object exists by name or position.
*
* @param string|integer $name The InputArgument name or position
*
* @return Boolean true if the InputArgument object exists, false otherwise
*/
public function hasArgument($name)
{
return $this->definition->hasArgument($name);
}
/**
* Returns the options values.
*
* @return array An array of option values
*/
public function getOptions()
{
return array_merge($this->definition->getOptionDefaults(), $this->options);
}
/**
* Returns the option value for a given option name.
*
* @param string $name The option name
*
* @return mixed The option value
*/
public function getOption($name)
{
if (!$this->definition->hasOption($name))
/**
* Returns the options values.
*
* @return array An array of option values
*/
public function getOptions()
{
throw new \InvalidArgumentException(sprintf('The "%s" option does not exist.', $name));
return array_merge($this->definition->getOptionDefaults(), $this->options);
}
return isset($this->options[$name]) ? $this->options[$name] : $this->definition->getOption($name)->getDefault();
}
/**
* Sets an option value by name.
*
* @param string $name The option name
* @param string $value The option value
*/
public function setOption($name, $value)
{
if (!$this->definition->hasOption($name))
/**
* Returns the option value for a given option name.
*
* @param string $name The option name
*
* @return mixed The option value
*
* @throws \InvalidArgumentException When option given doesn't exist
*/
public function getOption($name)
{
throw new \InvalidArgumentException(sprintf('The "%s" option does not exist.', $name));
if (!$this->definition->hasOption($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();
}
$this->options[$name] = $value;
}
/**
* Returns true if an InputOption object exists by name.
*
* @param string $name The InputOption name
*
* @return Boolean true if the InputOption object exists, false otherwise
*/
public function hasOption($name)
{
return $this->definition->hasOption($name);
}
/**
* Sets an option value by name.
*
* @param string $name The option name
* @param string $value The option value
*
* @throws \InvalidArgumentException When option given doesn't exist
*/
public function setOption($name, $value)
{
if (!$this->definition->hasOption($name)) {
throw new \InvalidArgumentException(sprintf('The "%s" option does not exist.', $name));
}
$this->options[$name] = $value;
}
/**
* Returns true if an InputOption object exists by name.
*
* @param string $name The InputOption name
*
* @return Boolean true if the InputOption object exists, false otherwise
*/
public function hasOption($name)
{
return $this->definition->hasOption($name);
}
}
......@@ -3,7 +3,7 @@
namespace Symfony\Component\Console\Input;
/*
* This file is part of the symfony framework.
* This file is part of the Symfony framework.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
......@@ -14,121 +14,115 @@ namespace Symfony\Component\Console\Input;
/**
* Represents a command line argument.
*
* @package symfony
* @subpackage console
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
class InputArgument
{
const REQUIRED = 1;
const OPTIONAL = 2;
const IS_ARRAY = 4;
const REQUIRED = 1;
const OPTIONAL = 2;
const IS_ARRAY = 4;
protected $name;
protected $mode;
protected $default;
protected $description;
protected $name;
protected $mode;
protected $default;
protected $description;
/**
* Constructor.
*
* @param string $name The argument name
* @param integer $mode The argument mode: self::REQUIRED or self::OPTIONAL
* @param string $description A description text
* @param mixed $default The default value (for self::OPTIONAL mode only)
*/
public function __construct($name, $mode = null, $description = '', $default = null)
{
if (null === $mode)
/**
* Constructor.
*
* @param string $name The argument name
* @param integer $mode The argument mode: self::REQUIRED or self::OPTIONAL
* @param string $description A description text
* @param mixed $default The default value (for self::OPTIONAL mode only)
*
* @throws \InvalidArgumentException When argument mode is not valid
*/
public function __construct($name, $mode = null, $description = '', $default = null)
{
$mode = self::OPTIONAL;
if (null === $mode) {
$mode = self::OPTIONAL;
} else if (is_string($mode) || $mode > 7) {
throw new \InvalidArgumentException(sprintf('Argument mode "%s" is not valid.', $mode));
}
$this->name = $name;
$this->mode = $mode;
$this->description = $description;
$this->setDefault($default);
}
else if (is_string($mode) || $mode > 7)
/**
* Returns the argument name.
*
* @return string The argument name
*/
public function getName()
{
throw new \InvalidArgumentException(sprintf('Argument mode "%s" is not valid.', $mode));
return $this->name;
}
$this->name = $name;
$this->mode = $mode;
$this->description = $description;
/**
* Returns true if the argument is required.
*
* @return Boolean true if parameter mode is self::REQUIRED, false otherwise
*/
public function isRequired()
{
return self::REQUIRED === (self::REQUIRED & $this->mode);
}
$this->setDefault($default);
}
/**
* Returns true if the argument can take multiple values.
*
* @return Boolean true if mode is self::IS_ARRAY, false otherwise
*/
public function isArray()
{
return self::IS_ARRAY === (self::IS_ARRAY & $this->mode);
}
/**
* Returns the argument name.
*
* @return string The argument name
*/
public function getName()
{
return $this->name;
}
/**
* Sets the default value.
*
* @param mixed $default The default value
*
* @throws \LogicException When incorrect default value is given
*/
public function setDefault($default = null)
{
if (self::REQUIRED === $this->mode && null !== $default) {
throw new \LogicException('Cannot set a default value except for Parameter::OPTIONAL mode.');
}
/**
* Returns true if the argument is required.
*
* @return Boolean true if parameter mode is self::REQUIRED, false otherwise
*/
public function isRequired()
{
return self::REQUIRED === (self::REQUIRED & $this->mode);
}
if ($this->isArray()) {
if (null === $default) {
$default = array();
} else if (!is_array($default)) {
throw new \LogicException('A default value for an array argument must be an array.');
}
}
/**
* Returns true if the argument can take multiple values.
*
* @return Boolean true if mode is self::IS_ARRAY, false otherwise
*/
public function isArray()
{
return self::IS_ARRAY === (self::IS_ARRAY & $this->mode);
}
$this->default = $default;
}
/**
* Sets the default value.
*
* @param mixed $default The default value
*/
public function setDefault($default = null)
{
if (self::REQUIRED === $this->mode && null !== $default)
/**
* Returns the default value.
*
* @return mixed The default value
*/
public function getDefault()
{
throw new \LogicException('Cannot set a default value except for Parameter::OPTIONAL mode.');
return $this->default;
}
if ($this->isArray())
/**
* Returns the description text.
*
* @return string The description text
*/
public function getDescription()
{
if (null === $default)
{
$default = array();
}
else if (!is_array($default))
{
throw new \LogicException('A default value for an array argument must be an array.');
}
return $this->description;
}
$this->default = $default;
}
/**
* Returns the default value.
*
* @return mixed The default value
*/
public function getDefault()
{
return $this->default;
}
/**
* Returns the description text.
*
* @return string The description text
*/
public function getDescription()
{
return $this->description;
}
}
......@@ -3,7 +3,7 @@
namespace Symfony\Component\Console\Input;
/*
* This file is part of the symfony framework.
* This file is part of the Symfony framework.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
......@@ -14,45 +14,43 @@ namespace Symfony\Component\Console\Input;
/**
* InputInterface is the interface implemented by all input classes.
*
* @package symfony
* @subpackage console
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
interface InputInterface
{
/**
* Returns the first argument from the raw parameters (not parsed).
*
* @return string The value of the first argument or null otherwise
*/
function getFirstArgument();
/**
* Returns true if the raw parameters (not parsed) contains a value.
*
* This method is to be used to introspect the input parameters
* before it has been validated. It must be used carefully.
*
* @param string $value The value to look for in the raw parameters
*
* @return Boolean true if the value is contained in the raw parameters
*/
function hasParameterOption($value);
/**
* Binds the current Input instance with the given arguments and options.
*
* @param InputDefinition $definition A InputDefinition instance
*/
function bind(InputDefinition $definition);
function validate();
function getArguments();
function getArgument($name);
function getOptions();
function getOption($name);
/**
* Returns the first argument from the raw parameters (not parsed).
*
* @return string The value of the first argument or null otherwise
*/
function getFirstArgument();
/**
* Returns true if the raw parameters (not parsed) contains a value.
*
* This method is to be used to introspect the input parameters
* before it has been validated. It must be used carefully.
*
* @param string $value The value to look for in the raw parameters
*
* @return Boolean true if the value is contained in the raw parameters
*/
function hasParameterOption($value);
/**
* Binds the current Input instance with the given arguments and options.
*
* @param InputDefinition $definition A InputDefinition instance
*/
function bind(InputDefinition $definition);
function validate();
function getArguments();
function getArgument($name);
function getOptions();
function getOption($name);
}
......@@ -3,7 +3,7 @@
namespace Symfony\Component\Console\Input;
/*
* This file is part of the symfony framework.
* This file is part of the Symfony framework.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
......@@ -14,178 +14,165 @@ namespace Symfony\Component\Console\Input;
/**
* Represents a command line option.
*
* @package symfony
* @subpackage console
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
class InputOption
{
const PARAMETER_NONE = 1;
const PARAMETER_REQUIRED = 2;
const PARAMETER_OPTIONAL = 4;
const PARAMETER_IS_ARRAY = 8;
protected $name;
protected $shortcut;
protected $mode;
protected $default;
protected $description;
/**
* Constructor.
*
* @param string $name The option name
* @param string $shortcut The shortcut (can be null)
* @param integer $mode The option mode: self::PARAMETER_REQUIRED, self::PARAMETER_NONE or self::PARAMETER_OPTIONAL
* @param string $description A description text
* @param mixed $default The default value (must be null for self::PARAMETER_REQUIRED or self::PARAMETER_NONE)
*/
public function __construct($name, $shortcut = null, $mode = null, $description = '', $default = null)
{
if ('--' === substr($name, 0, 2))
const PARAMETER_NONE = 1;
const PARAMETER_REQUIRED = 2;
const PARAMETER_OPTIONAL = 4;
const PARAMETER_IS_ARRAY = 8;
protected $name;
protected $shortcut;
protected $mode;
protected $default;
protected $description;
/**
* Constructor.
*
* @param string $name The option name
* @param string $shortcut The shortcut (can be null)
* @param integer $mode The option mode: self::PARAMETER_REQUIRED, self::PARAMETER_NONE or self::PARAMETER_OPTIONAL
* @param string $description A description text
* @param mixed $default The default value (must be null for self::PARAMETER_REQUIRED or self::PARAMETER_NONE)
*
* @throws \InvalidArgumentException If option mode is invalid or incompatible
*/
public function __construct($name, $shortcut = null, $mode = null, $description = '', $default = null)
{
$name = substr($name, 2);
if ('--' === substr($name, 0, 2)) {
$name = substr($name, 2);
}
if (empty($shortcut)) {
$shortcut = null;
}
if (null !== $shortcut) {
if ('-' === $shortcut[0]) {
$shortcut = substr($shortcut, 1);
}
}
if (null === $mode) {
$mode = self::PARAMETER_NONE;
} else if (!is_int($mode) || $mode > 15) {
throw new \InvalidArgumentException(sprintf('Option mode "%s" is not valid.', $mode));
}
$this->name = $name;
$this->shortcut = $shortcut;
$this->mode = $mode;
$this->description = $description;
if ($this->isArray() && !$this->acceptParameter()) {
throw new \InvalidArgumentException('Impossible to have an option mode PARAMETER_IS_ARRAY if the option does not accept a parameter.');
}
$this->setDefault($default);
}
if (empty($shortcut))
/**
* Returns the shortcut.
*
* @return string The shortcut
*/
public function getShortcut()
{
$shortcut = null;
return $this->shortcut;
}
if (null !== $shortcut)
/**
* Returns the name.
*
* @return string The name
*/
public function getName()
{
if ('-' === $shortcut[0])
{
$shortcut = substr($shortcut, 1);
}
return $this->name;
}
if (null === $mode)
/**
* Returns true if the option accept a parameter.
*
* @return Boolean true if parameter mode is not self::PARAMETER_NONE, false otherwise
*/
public function acceptParameter()
{
$mode = self::PARAMETER_NONE;
return $this->isParameterRequired() || $this->isParameterOptional();
}
else if (!is_int($mode) || $mode > 15)
/**
* Returns true if the option requires a parameter.
*
* @return Boolean true if parameter mode is self::PARAMETER_REQUIRED, false otherwise
*/
public function isParameterRequired()
{
throw new \InvalidArgumentException(sprintf('Option mode "%s" is not valid.', $mode));
return self::PARAMETER_REQUIRED === (self::PARAMETER_REQUIRED & $this->mode);
}
$this->name = $name;
$this->shortcut = $shortcut;
$this->mode = $mode;
$this->description = $description;
/**
* Returns true if the option takes an optional parameter.
*
* @return Boolean true if parameter mode is self::PARAMETER_OPTIONAL, false otherwise
*/
public function isParameterOptional()
{
return self::PARAMETER_OPTIONAL === (self::PARAMETER_OPTIONAL & $this->mode);
}
if ($this->isArray() && !$this->acceptParameter())
/**
* Returns true if the option can take multiple values.
*
* @return Boolean true if mode is self::PARAMETER_IS_ARRAY, false otherwise
*/
public function isArray()
{
throw new \InvalidArgumentException('Impossible to have an option mode PARAMETER_IS_ARRAY if the option does not accept a parameter.');
return self::PARAMETER_IS_ARRAY === (self::PARAMETER_IS_ARRAY & $this->mode);
}
$this->setDefault($default);
}
/**
* Returns the shortcut.
*
* @return string The shortcut
*/
public function getShortcut()
{
return $this->shortcut;
}
/**
* Returns the name.
*
* @return string The name
*/
public function getName()
{
return $this->name;
}
/**
* Returns true if the option accept a parameter.
*
* @return Boolean true if parameter mode is not self::PARAMETER_NONE, false otherwise
*/
public function acceptParameter()
{
return $this->isParameterRequired() || $this->isParameterOptional();
}
/**
* Returns true if the option requires a parameter.
*
* @return Boolean true if parameter mode is self::PARAMETER_REQUIRED, false otherwise
*/
public function isParameterRequired()
{
return self::PARAMETER_REQUIRED === (self::PARAMETER_REQUIRED & $this->mode);
}
/**
* Returns true if the option takes an optional parameter.
*
* @return Boolean true if parameter mode is self::PARAMETER_OPTIONAL, false otherwise
*/
public function isParameterOptional()
{
return self::PARAMETER_OPTIONAL === (self::PARAMETER_OPTIONAL & $this->mode);
}
/**
* Returns true if the option can take multiple values.
*
* @return Boolean true if mode is self::PARAMETER_IS_ARRAY, false otherwise
*/
public function isArray()
{
return self::PARAMETER_IS_ARRAY === (self::PARAMETER_IS_ARRAY & $this->mode);
}
/**
* Sets the default value.
*
* @param mixed $default The default value
*/
public function setDefault($default = null)
{
if (self::PARAMETER_NONE === (self::PARAMETER_NONE & $this->mode) && null !== $default)
/**
* Sets the default value.
*
* @param mixed $default The default value
*/
public function setDefault($default = null)
{
throw new \LogicException('Cannot set a default value when using Option::PARAMETER_NONE mode.');
if (self::PARAMETER_NONE === (self::PARAMETER_NONE & $this->mode) && null !== $default) {
throw new \LogicException('Cannot set a default value when using Option::PARAMETER_NONE mode.');
}
if ($this->isArray()) {
if (null === $default) {
$default = array();
} elseif (!is_array($default)) {
throw new \LogicException('A default value for an array option must be an array.');
}
}
$this->default = $this->acceptParameter() ? $default : false;
}
if ($this->isArray())
/**
* Returns the default value.
*
* @return mixed The default value
*/
public function getDefault()
{
if (null === $default)
{
$default = array();
}
elseif (!is_array($default))
{
throw new \LogicException('A default value for an array option must be an array.');
}
return $this->default;
}
$this->default = $this->acceptParameter() ? $default : false;
}
/**
* Returns the default value.
*
* @return mixed The default value
*/
public function getDefault()
{
return $this->default;
}
/**
* Returns the description text.
*
* @return string The description text
*/
public function getDescription()
{
return $this->description;
}
/**
* Returns the description text.
*
* @return string The description text
*/
public function getDescription()
{
return $this->description;
}
}
......@@ -3,7 +3,7 @@
namespace Symfony\Component\Console\Input;
/*
* This file is part of the symfony framework.
* This file is part of the Symfony framework.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
......@@ -18,63 +18,54 @@ namespace Symfony\Component\Console\Input;
*
* $input = new StringInput('foo --bar="foobar"');
*
* @package symfony
* @subpackage console
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
class StringInput extends ArgvInput
{
const REGEX_STRING = '([^ ]+?)(?: |(?<!\\\\)"|(?<!\\\\)\'|$)';
const REGEX_QUOTED_STRING = '(?:"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\')';
const REGEX_STRING = '([^ ]+?)(?: |(?<!\\\\)"|(?<!\\\\)\'|$)';
const REGEX_QUOTED_STRING = '(?:"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\')';
/**
* Constructor.
*
* @param string $input An array of parameters from the CLI (in the argv format)
* @param InputDefinition $definition A InputDefinition instance
*/
public function __construct($input, InputDefinition $definition = null)
{
parent::__construct(array(), $definition);
$this->tokens = $this->tokenize($input);
}
/**
* Constructor.
*
* @param string $input An array of parameters from the CLI (in the argv format)
* @param InputDefinition $definition A InputDefinition instance
*/
public function __construct($input, InputDefinition $definition = null)
{
parent::__construct(array(), $definition);
protected function tokenize($input)
{
$input = preg_replace('/(\r\n|\r|\n|\t)/', ' ', $input);
$this->tokens = $this->tokenize($input);
}
$tokens = array();
$length = strlen($input);
$cursor = 0;
while ($cursor < $length)
/**
* @throws \InvalidArgumentException When unable to parse input (should never happen)
*/
protected function tokenize($input)
{
if (preg_match('/\s+/A', $input, $match, null, $cursor))
{
}
elseif (preg_match('/([^="\' ]+?)(=?)('.self::REGEX_QUOTED_STRING.'+)/A', $input, $match, null, $cursor))
{
$tokens[] = $match[1].$match[2].stripcslashes(str_replace(array('"\'', '\'"', '\'\'', '""'), '', substr($match[3], 1, strlen($match[3]) - 2)));
}
elseif (preg_match('/'.self::REGEX_QUOTED_STRING.'/A', $input, $match, null, $cursor))
{
$tokens[] = stripcslashes(substr($match[0], 1, strlen($match[0]) - 2));
}
elseif (preg_match('/'.self::REGEX_STRING.'/A', $input, $match, null, $cursor))
{
$tokens[] = stripcslashes($match[1]);
}
else
{
// should never happen
// @codeCoverageIgnoreStart
throw new \InvalidArgumentException(sprintf('Unable to parse input near "... %s ..."', substr($input, $cursor, 10)));
// @codeCoverageIgnoreEnd
}
$input = preg_replace('/(\r\n|\r|\n|\t)/', ' ', $input);
$cursor += strlen($match[0]);
}
$tokens = array();
$length = strlen($input);
$cursor = 0;
while ($cursor < $length) {
if (preg_match('/\s+/A', $input, $match, null, $cursor)) {
} elseif (preg_match('/([^="\' ]+?)(=?)('.self::REGEX_QUOTED_STRING.'+)/A', $input, $match, null, $cursor)) {
$tokens[] = $match[1].$match[2].stripcslashes(str_replace(array('"\'', '\'"', '\'\'', '""'), '', substr($match[3], 1, strlen($match[3]) - 2)));
} elseif (preg_match('/'.self::REGEX_QUOTED_STRING.'/A', $input, $match, null, $cursor)) {
$tokens[] = stripcslashes(substr($match[0], 1, strlen($match[0]) - 2));
} elseif (preg_match('/'.self::REGEX_STRING.'/A', $input, $match, null, $cursor)) {
$tokens[] = stripcslashes($match[1]);
} else {
// should never happen
// @codeCoverageIgnoreStart
throw new \InvalidArgumentException(sprintf('Unable to parse input near "... %s ..."', substr($input, $cursor, 10)));
// @codeCoverageIgnoreEnd
}
$cursor += strlen($match[0]);
}
return $tokens;
}
return $tokens;
}
}
......@@ -3,7 +3,7 @@
namespace Symfony\Component\Console\Output;
/*
* This file is part of the symfony framework.
* This file is part of the Symfony framework.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
......@@ -22,20 +22,18 @@ namespace Symfony\Component\Console\Output;
*
* $output = new StreamOutput(fopen('php://stdout', 'w'));
*
* @package symfony
* @subpackage console
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
class ConsoleOutput extends StreamOutput
{
/**
* Constructor.
*
* @param integer $verbosity The verbosity level (self::VERBOSITY_QUIET, self::VERBOSITY_NORMAL, self::VERBOSITY_VERBOSE)
* @param Boolean $decorated Whether to decorate messages or not (null for auto-guessing)
*/
public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = null)
{
parent::__construct(fopen('php://stdout', 'w'), $verbosity, $decorated);
}
/**
* Constructor.
*
* @param integer $verbosity The verbosity level (self::VERBOSITY_QUIET, self::VERBOSITY_NORMAL, self::VERBOSITY_VERBOSE)
* @param Boolean $decorated Whether to decorate messages or not (null for auto-guessing)
*/
public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = null)
{
parent::__construct(fopen('php://stdout', 'w'), $verbosity, $decorated);
}
}
......@@ -3,7 +3,7 @@
namespace Symfony\Component\Console\Output;
/*
* This file is part of the symfony framework.
* This file is part of the Symfony framework.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
......@@ -16,19 +16,17 @@ namespace Symfony\Component\Console\Output;
*
* $output = new NullOutput();
*
* @package symfony
* @subpackage console
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
* @author Fabien Potencier <fabien.potencier@symfony-project.com>
*/
class NullOutput extends Output
{
/**
* Writes a message to the output.
*
* @param string $message A message to write to the output
* @param Boolean $newline Whether to add a newline or not
*/
public function doWrite($message, $newline)
{
}
/**
* Writes a message to the output.
*
* @param string $message A message to write to the output
* @param Boolean $newline Whether to add a newline or not
*/
public function doWrite($message, $newline)
{
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment