class StringInput in Zircon Profile 8.0
Same name and namespace in other branches
- 8 vendor/symfony/console/Input/StringInput.php \Symfony\Component\Console\Input\StringInput
StringInput represents an input provided as a string.
Usage:
$input = new StringInput('foo --bar="foobar"');
@author Fabien Potencier <fabien@symfony.com>
Hierarchy
- class \Symfony\Component\Console\Input\Input implements InputInterface
- class \Symfony\Component\Console\Input\ArgvInput
- class \Symfony\Component\Console\Input\StringInput
- class \Symfony\Component\Console\Input\ArgvInput
Expanded class hierarchy of StringInput
3 files declare their use of StringInput
- CommandTest.php in vendor/
symfony/ console/ Tests/ Command/ CommandTest.php - Shell.php in vendor/
symfony/ console/ Shell.php - StringInputTest.php in vendor/
symfony/ console/ Tests/ Input/ StringInputTest.php
File
- vendor/
symfony/ console/ Input/ StringInput.php, line 23
Namespace
Symfony\Component\Console\InputView source
class StringInput extends ArgvInput {
const REGEX_STRING = '([^\\s]+?)(?:\\s|(?<!\\\\)"|(?<!\\\\)\'|$)';
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
*
* @deprecated The second argument is deprecated as it does not work (will be removed in 3.0), use 'bind' method instead
*/
public function __construct($input, InputDefinition $definition = null) {
if ($definition) {
@trigger_error('The $definition argument of the ' . __METHOD__ . ' method is deprecated and will be removed in 3.0. Set this parameter with the bind() method instead.', E_USER_DEPRECATED);
}
parent::__construct(array(), null);
$this
->setTokens($this
->tokenize($input));
if (null !== $definition) {
$this
->bind($definition);
}
}
/**
* Tokenizes a string.
*
* @param string $input The input to tokenize
*
* @return array An array of tokens
*
* @throws \InvalidArgumentException When unable to parse input (should never happen)
*/
private function tokenize($input) {
$tokens = array();
$length = strlen($input);
$cursor = 0;
while ($cursor < $length) {
if (preg_match('/\\s+/A', $input, $match, null, $cursor)) {
}
elseif (preg_match('/([^="\'\\s]+?)(=?)(' . 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
throw new \InvalidArgumentException(sprintf('Unable to parse input near "... %s ..."', substr($input, $cursor, 10)));
}
$cursor += strlen($match[0]);
}
return $tokens;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ArgvInput:: |
private | property | ||
ArgvInput:: |
private | property | ||
ArgvInput:: |
private | function | Adds a long option value. | |
ArgvInput:: |
private | function | Adds a short option value. | |
ArgvInput:: |
public | function |
Returns the first argument from the raw parameters (not parsed). Overrides InputInterface:: |
|
ArgvInput:: |
public | function |
Returns the value of a raw option (not parsed). Overrides InputInterface:: |
|
ArgvInput:: |
public | function |
Returns true if the raw parameters (not parsed) contain a value. Overrides InputInterface:: |
|
ArgvInput:: |
protected | function |
Processes command line arguments. Overrides Input:: |
|
ArgvInput:: |
private | function | Parses an argument. | |
ArgvInput:: |
private | function | Parses a long option. | |
ArgvInput:: |
private | function | Parses a short option. | |
ArgvInput:: |
private | function | Parses a short option set. | |
ArgvInput:: |
protected | function | ||
ArgvInput:: |
public | function | Returns a stringified representation of the args passed to the command. | |
Input:: |
protected | property | ||
Input:: |
protected | property | ||
Input:: |
protected | property | ||
Input:: |
protected | property | ||
Input:: |
public | function |
Binds the current Input instance with the given arguments and options. Overrides InputInterface:: |
|
Input:: |
public | function | Escapes a token through escapeshellarg if it contains unsafe chars. | |
Input:: |
public | function |
Returns the argument value for a given argument name. Overrides InputInterface:: |
|
Input:: |
public | function |
Returns the argument values. Overrides InputInterface:: |
|
Input:: |
public | function |
Returns the option value for a given option name. Overrides InputInterface:: |
|
Input:: |
public | function |
Returns the options values. Overrides InputInterface:: |
|
Input:: |
public | function |
Returns true if an InputArgument object exists by name or position. Overrides InputInterface:: |
|
Input:: |
public | function |
Returns true if an InputOption object exists by name. Overrides InputInterface:: |
|
Input:: |
public | function |
Checks if the input is interactive. Overrides InputInterface:: |
|
Input:: |
public | function |
Sets an argument value by name. Overrides InputInterface:: |
|
Input:: |
public | function |
Sets the input interactivity. Overrides InputInterface:: |
|
Input:: |
public | function |
Sets an option value by name. Overrides InputInterface:: |
|
Input:: |
public | function |
Validates the input. Overrides InputInterface:: |
|
StringInput:: |
constant | |||
StringInput:: |
constant | |||
StringInput:: |
private | function | Tokenizes a string. | |
StringInput:: |
public | function |
Constructor. Overrides ArgvInput:: |