Overview

Namespaces

  • Contrib
    • Bundle
      • CoverallsBundle
        • Console
        • Entity
      • CoverallsV1Bundle
        • Api
        • Collector
        • Command
        • Config
        • Entity
          • Git
    • Component
      • File
      • Log
      • System
        • Git
  • Guzzle
    • Batch
      • Exception
    • Cache
    • Common
      • Exception
    • Http
      • Curl
      • Exception
      • Message
      • QueryAggregator
    • Inflection
    • Iterator
    • Log
    • Parser
      • Cookie
      • Message
      • UriTemplate
      • Url
    • Plugin
      • Async
      • Backoff
      • Cache
      • Cookie
        • CookieJar
        • Exception
      • CurlAuth
      • ErrorResponse
        • Exception
      • History
      • Log
      • Md5
      • Mock
      • Oauth
    • Service
      • Builder
      • Command
        • Factory
        • LocationVisitor
          • Request
          • Response
      • Description
      • Exception
      • Resource
    • Stream
  • PHP
  • Psr
    • Log
  • Symfony
    • Component
      • Config
        • Definition
          • Builder
          • Exception
        • Exception
        • Loader
        • Resource
        • Util
      • Console
        • Command
        • Formatter
        • Helper
        • Input
        • Output
        • Tester
      • EventDispatcher
        • Debug
      • Finder
        • Adapter
        • Comparator
        • Exception
        • Expression
        • Iterator
        • Shell
      • Stopwatch
      • Yaml
        • Exception

Classes

  • ArgvInput
  • ArrayInput
  • Input
  • InputArgument
  • InputDefinition
  • InputOption
  • StringInput

Interfaces

  • InputInterface
  • Overview
  • Namespace
  • Class
  • Tree
  • Todo
 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: /**
15:  * StringInput represents an input provided as a string.
16:  *
17:  * Usage:
18:  *
19:  *     $input = new StringInput('foo --bar="foobar"');
20:  *
21:  * @author Fabien Potencier <fabien@symfony.com>
22:  *
23:  * @api
24:  */
25: class StringInput extends ArgvInput
26: {
27:     const REGEX_STRING = '([^ ]+?)(?: |(?<!\\\\)"|(?<!\\\\)\'|$)';
28:     const REGEX_QUOTED_STRING = '(?:"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\')';
29: 
30:     /**
31:      * Constructor.
32:      *
33:      * @param string          $input      An array of parameters from the CLI (in the argv format)
34:      * @param InputDefinition $definition A InputDefinition instance
35:      *
36:      * @deprecated The second argument is deprecated as it does not work (will be removed in 3.0), use 'bind' method instead
37:      *
38:      * @api
39:      */
40:     public function __construct($input, InputDefinition $definition = null)
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:         $input = preg_replace('/(\r\n|\r|\n|\t)/', ' ', $input);
63: 
64:         $tokens = array();
65:         $length = strlen($input);
66:         $cursor = 0;
67:         while ($cursor < $length) {
68:             if (preg_match('/\s+/A', $input, $match, null, $cursor)) {
69:             } elseif (preg_match('/([^="\' ]+?)(=?)('.self::REGEX_QUOTED_STRING.'+)/A', $input, $match, null, $cursor)) {
70:                 $tokens[] = $match[1].$match[2].stripcslashes(str_replace(array('"\'', '\'"', '\'\'', '""'), '', substr($match[3], 1, strlen($match[3]) - 2)));
71:             } elseif (preg_match('/'.self::REGEX_QUOTED_STRING.'/A', $input, $match, null, $cursor)) {
72:                 $tokens[] = stripcslashes(substr($match[0], 1, strlen($match[0]) - 2));
73:             } elseif (preg_match('/'.self::REGEX_STRING.'/A', $input, $match, null, $cursor)) {
74:                 $tokens[] = stripcslashes($match[1]);
75:             } else {
76:                 // should never happen
77:                 // @codeCoverageIgnoreStart
78:                 throw new \InvalidArgumentException(sprintf('Unable to parse input near "... %s ..."', substr($input, $cursor, 10)));
79:                 // @codeCoverageIgnoreEnd
80:             }
81: 
82:             $cursor += strlen($match[0]);
83:         }
84: 
85:         return $tokens;
86:     }
87: }
88: 
php-coveralls API documentation generated by ApiGen 2.8.0