Verzeichnisstruktur phpBB-3.2.0
- Veröffentlicht
- 06.01.2017
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
Input.php
001 <?php
002
003 /*
004 * This file is part of the Symfony package.
005 *
006 * (c) Fabien Potencier <fabien@symfony.com>
007 *
008 * For the full copyright and license information, please view the LICENSE
009 * file that was distributed with this source code.
010 */
011
012 namespace Symfony\Component\Console\Input;
013
014 use Symfony\Component\Console\Exception\InvalidArgumentException;
015 use Symfony\Component\Console\Exception\RuntimeException;
016
017 /**
018 * Input is the base class for all concrete Input classes.
019 *
020 * Three concrete classes are provided by default:
021 *
022 * * `ArgvInput`: The input comes from the CLI arguments (argv)
023 * * `StringInput`: The input is provided as a string
024 * * `ArrayInput`: The input is provided as an array
025 *
026 * @author Fabien Potencier <fabien@symfony.com>
027 */
028 abstract class Input implements InputInterface
029 {
030 /**
031 * @var InputDefinition
032 */
033 protected $definition;
034 protected $options = array();
035 protected $arguments = array();
036 protected $interactive = true;
037
038 /**
039 * Constructor.
040 *
041 * @param InputDefinition|null $definition A InputDefinition instance
042 */
043 public function __construct(InputDefinition $definition = null)
044 {
045 if (null === $definition) {
046 $this->definition = new InputDefinition();
047 } else {
048 $this->bind($definition);
049 $this->validate();
050 }
051 }
052
053 /**
054 * {@inheritdoc}
055 */
056 public function bind(InputDefinition $definition)
057 {
058 $this->arguments = array();
059 $this->options = array();
060 $this->definition = $definition;
061
062 $this->parse();
063 }
064
065 /**
066 * Processes command line arguments.
067 */
068 abstract protected function parse();
069
070 /**
071 * {@inheritdoc}
072 */
073 public function validate()
074 {
075 $definition = $this->definition;
076 $givenArguments = $this->arguments;
077
078 $missingArguments = array_filter(array_keys($definition->getArguments()), function ($argument) use ($definition, $givenArguments) {
079 return !array_key_exists($argument, $givenArguments) && $definition->getArgument($argument)->isRequired();
080 });
081
082 if (count($missingArguments) > 0) {
083 throw new RuntimeException(sprintf('Not enough arguments (missing: "%s").', implode(', ', $missingArguments)));
084 }
085 }
086
087 /**
088 * {@inheritdoc}
089 */
090 public function isInteractive()
091 {
092 return $this->interactive;
093 }
094
095 /**
096 * {@inheritdoc}
097 */
098 public function setInteractive($interactive)
099 {
100 $this->interactive = (bool) $interactive;
101 }
102
103 /**
104 * {@inheritdoc}
105 */
106 public function getArguments()
107 {
108 return array_merge($this->definition->getArgumentDefaults(), $this->arguments);
109 }
110
111 /**
112 * {@inheritdoc}
113 */
114 public function getArgument($name)
115 {
116 if (!$this->definition->hasArgument($name)) {
117 throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
118 }
119
120 return isset($this->arguments[$name]) ? $this->arguments[$name] : $this->definition->getArgument($name)->getDefault();
121 }
122
123 /**
124 * {@inheritdoc}
125 */
126 public function setArgument($name, $value)
127 {
128 if (!$this->definition->hasArgument($name)) {
129 throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
130 }
131
132 $this->arguments[$name] = $value;
133 }
134
135 /**
136 * {@inheritdoc}
137 */
138 public function hasArgument($name)
139 {
140 return $this->definition->hasArgument($name);
141 }
142
143 /**
144 * {@inheritdoc}
145 */
146 public function getOptions()
147 {
148 return array_merge($this->definition->getOptionDefaults(), $this->options);
149 }
150
151 /**
152 * {@inheritdoc}
153 */
154 public function getOption($name)
155 {
156 if (!$this->definition->hasOption($name)) {
157 throw new InvalidArgumentException(sprintf('The "%s" option does not exist.', $name));
158 }
159
160 return isset($this->options[$name]) ? $this->options[$name] : $this->definition->getOption($name)->getDefault();
161 }
162
163 /**
164 * {@inheritdoc}
165 */
166 public function setOption($name, $value)
167 {
168 if (!$this->definition->hasOption($name)) {
169 throw new InvalidArgumentException(sprintf('The "%s" option does not exist.', $name));
170 }
171
172 $this->options[$name] = $value;
173 }
174
175 /**
176 * {@inheritdoc}
177 */
178 public function hasOption($name)
179 {
180 return $this->definition->hasOption($name);
181 }
182
183 /**
184 * Escapes a token through escapeshellarg if it contains unsafe chars.
185 *
186 * @param string $token
187 *
188 * @return string
189 */
190 public function escapeToken($token)
191 {
192 return preg_match('{^[\w-]+$}', $token) ? $token : escapeshellarg($token);
193 }
194 }
195