[ Index ] |
PHP Cross Reference of phpBB-3.2.11-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* 4 * This file is part of the Symfony package. 5 * 6 * (c) Fabien Potencier <fabien@symfony.com> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12 namespace Symfony\Component\Console\Input; 13 14 use Symfony\Component\Console\Exception\InvalidArgumentException; 15 16 /** 17 * StringInput represents an input provided as a string. 18 * 19 * Usage: 20 * 21 * $input = new StringInput('foo --bar="foobar"'); 22 * 23 * @author Fabien Potencier <fabien@symfony.com> 24 */ 25 class StringInput extends ArgvInput 26 { 27 const REGEX_STRING = '([^\s]+?)(?:\s|(?<!\\\\)"|(?<!\\\\)\'|$)'; 28 const REGEX_QUOTED_STRING = '(?:"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\')'; 29 30 /** 31 * @param string $input A string representing the parameters from the CLI 32 * @param InputDefinition $definition A InputDefinition instance 33 * 34 * @deprecated The second argument is deprecated as it does not work (will be removed in 3.0), use 'bind' method instead 35 */ 36 public function __construct($input, InputDefinition $definition = null) 37 { 38 if ($definition) { 39 @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); 40 } 41 42 parent::__construct(array(), null); 43 44 $this->setTokens($this->tokenize($input)); 45 46 if (null !== $definition) { 47 $this->bind($definition); 48 } 49 } 50 51 /** 52 * Tokenizes a string. 53 * 54 * @param string $input The input to tokenize 55 * 56 * @return array An array of tokens 57 * 58 * @throws InvalidArgumentException When unable to parse input (should never happen) 59 */ 60 private function tokenize($input) 61 { 62 $tokens = array(); 63 $length = \strlen($input); 64 $cursor = 0; 65 while ($cursor < $length) { 66 if (preg_match('/\s+/A', $input, $match, null, $cursor)) { 67 } elseif (preg_match('/([^="\'\s]+?)(=?)('.self::REGEX_QUOTED_STRING.'+)/A', $input, $match, null, $cursor)) { 68 $tokens[] = $match[1].$match[2].stripcslashes(str_replace(array('"\'', '\'"', '\'\'', '""'), '', substr($match[3], 1, \strlen($match[3]) - 2))); 69 } elseif (preg_match('/'.self::REGEX_QUOTED_STRING.'/A', $input, $match, null, $cursor)) { 70 $tokens[] = stripcslashes(substr($match[0], 1, \strlen($match[0]) - 2)); 71 } elseif (preg_match('/'.self::REGEX_STRING.'/A', $input, $match, null, $cursor)) { 72 $tokens[] = stripcslashes($match[1]); 73 } else { 74 // should never happen 75 throw new InvalidArgumentException(sprintf('Unable to parse input near "... %s ..."', substr($input, $cursor, 10))); 76 } 77 78 $cursor += \strlen($match[0]); 79 } 80 81 return $tokens; 82 } 83 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |