MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
StringInput.php
Ir para a documentação deste ficheiro.
1<?php
2
4
5/*
6 * This file is part of the Symfony framework.
7 *
8 * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
9 *
10 * This source file is subject to the MIT license that is bundled
11 * with this source code in the file LICENSE.
12 */
13
24{
25 const REGEX_STRING = '([^ ]+?)(?: |(?<!\\\\)"|(?<!\\\\)\'|$)';
26 const REGEX_QUOTED_STRING = '(?:"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\')';
27
34 public function __construct($input, InputDefinition $definition = null)
35 {
36 parent::__construct(array(), $definition);
37
38 $this->tokens = $this->tokenize($input);
39 }
40
44 protected function tokenize($input)
45 {
46 $input = preg_replace('/(\r\n|\r|\n|\t)/', ' ', $input);
47
48 $tokens = array();
49 $length = strlen($input);
50 $cursor = 0;
51 while ($cursor < $length) {
52 if (preg_match('/\s+/A', $input, $match, null, $cursor)) {
53 } elseif (preg_match('/([^="\' ]+?)(=?)('.self::REGEX_QUOTED_STRING.'+)/A', $input, $match, null, $cursor)) {
54 $tokens[] = $match[1].$match[2].stripcslashes(str_replace(array('"\'', '\'"', '\'\'', '""'), '', substr($match[3], 1, strlen($match[3]) - 2)));
55 } elseif (preg_match('/'.self::REGEX_QUOTED_STRING.'/A', $input, $match, null, $cursor)) {
56 $tokens[] = stripcslashes(substr($match[0], 1, strlen($match[0]) - 2));
57 } elseif (preg_match('/'.self::REGEX_STRING.'/A', $input, $match, null, $cursor)) {
58 $tokens[] = stripcslashes($match[1]);
59 } else {
60 // should never happen
61 // @codeCoverageIgnoreStart
62 throw new \InvalidArgumentException(sprintf('Unable to parse input near "... %s ..."', substr($input, $cursor, 10)));
63 // @codeCoverageIgnoreEnd
64 }
65
66 $cursor += strlen($match[0]);
67 }
68
69 return $tokens;
70 }
71}
__construct($input, InputDefinition $definition=null)
Definição StringInput.php:34