comparison vendor/symfony/console/Input/StringInput.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 1fec387a4317
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
30 /** 30 /**
31 * @param string $input A string representing the parameters from the CLI 31 * @param string $input A string representing the parameters from the CLI
32 */ 32 */
33 public function __construct($input) 33 public function __construct($input)
34 { 34 {
35 parent::__construct(array()); 35 parent::__construct([]);
36 36
37 $this->setTokens($this->tokenize($input)); 37 $this->setTokens($this->tokenize($input));
38 } 38 }
39 39
40 /** 40 /**
46 * 46 *
47 * @throws InvalidArgumentException When unable to parse input (should never happen) 47 * @throws InvalidArgumentException When unable to parse input (should never happen)
48 */ 48 */
49 private function tokenize($input) 49 private function tokenize($input)
50 { 50 {
51 $tokens = array(); 51 $tokens = [];
52 $length = strlen($input); 52 $length = \strlen($input);
53 $cursor = 0; 53 $cursor = 0;
54 while ($cursor < $length) { 54 while ($cursor < $length) {
55 if (preg_match('/\s+/A', $input, $match, null, $cursor)) { 55 if (preg_match('/\s+/A', $input, $match, null, $cursor)) {
56 } elseif (preg_match('/([^="\'\s]+?)(=?)('.self::REGEX_QUOTED_STRING.'+)/A', $input, $match, null, $cursor)) { 56 } elseif (preg_match('/([^="\'\s]+?)(=?)('.self::REGEX_QUOTED_STRING.'+)/A', $input, $match, null, $cursor)) {
57 $tokens[] = $match[1].$match[2].stripcslashes(str_replace(array('"\'', '\'"', '\'\'', '""'), '', substr($match[3], 1, strlen($match[3]) - 2))); 57 $tokens[] = $match[1].$match[2].stripcslashes(str_replace(['"\'', '\'"', '\'\'', '""'], '', substr($match[3], 1, \strlen($match[3]) - 2)));
58 } elseif (preg_match('/'.self::REGEX_QUOTED_STRING.'/A', $input, $match, null, $cursor)) { 58 } elseif (preg_match('/'.self::REGEX_QUOTED_STRING.'/A', $input, $match, null, $cursor)) {
59 $tokens[] = stripcslashes(substr($match[0], 1, strlen($match[0]) - 2)); 59 $tokens[] = stripcslashes(substr($match[0], 1, \strlen($match[0]) - 2));
60 } elseif (preg_match('/'.self::REGEX_STRING.'/A', $input, $match, null, $cursor)) { 60 } elseif (preg_match('/'.self::REGEX_STRING.'/A', $input, $match, null, $cursor)) {
61 $tokens[] = stripcslashes($match[1]); 61 $tokens[] = stripcslashes($match[1]);
62 } else { 62 } else {
63 // should never happen 63 // should never happen
64 throw new InvalidArgumentException(sprintf('Unable to parse input near "... %s ..."', substr($input, $cursor, 10))); 64 throw new InvalidArgumentException(sprintf('Unable to parse input near "... %s ..."', substr($input, $cursor, 10)));
65 } 65 }
66 66
67 $cursor += strlen($match[0]); 67 $cursor += \strlen($match[0]);
68 } 68 }
69 69
70 return $tokens; 70 return $tokens;
71 } 71 }
72 } 72 }