1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace Symfony\Component\Console\Input;
13:
14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24:
25: class StringInput extends ArgvInput
26: {
27: const REGEX_STRING = '([^ ]+?)(?: |(?<!\\\\)"|(?<!\\\\)\'|$)';
28: const REGEX_QUOTED_STRING = '(?:"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\')';
29:
30: 31: 32: 33: 34: 35: 36: 37:
38: public function __construct($input, InputDefinition $definition = null)
39: {
40: parent::__construct(array(), $definition);
41:
42: $this->setTokens($this->tokenize($input));
43: }
44:
45: 46: 47: 48: 49: 50: 51:
52: private function tokenize($input)
53: {
54: $input = preg_replace('/(\r\n|\r|\n|\t)/', ' ', $input);
55:
56: $tokens = array();
57: $length = strlen($input);
58: $cursor = 0;
59: while ($cursor < $length) {
60: if (preg_match('/\s+/A', $input, $match, null, $cursor)) {
61: } elseif (preg_match('/([^="\' ]+?)(=?)('.self::REGEX_QUOTED_STRING.'+)/A', $input, $match, null, $cursor)) {
62: $tokens[] = $match[1].$match[2].stripcslashes(str_replace(array('"\'', '\'"', '\'\'', '""'), '', substr($match[3], 1, strlen($match[3]) - 2)));
63: } elseif (preg_match('/'.self::REGEX_QUOTED_STRING.'/A', $input, $match, null, $cursor)) {
64: $tokens[] = stripcslashes(substr($match[0], 1, strlen($match[0]) - 2));
65: } elseif (preg_match('/'.self::REGEX_STRING.'/A', $input, $match, null, $cursor)) {
66: $tokens[] = stripcslashes($match[1]);
67: } else {
68:
69:
70: throw new \InvalidArgumentException(sprintf('Unable to parse input near "... %s ..."', substr($input, $cursor, 10)));
71:
72: }
73:
74: $cursor += strlen($match[0]);
75: }
76:
77: return $tokens;
78: }
79: }
80: