MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
Input.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
25abstract class Input implements InputInterface
26{
27 protected $definition;
28 protected $options;
29 protected $arguments;
30 protected $interactive = true;
31
37 public function __construct(InputDefinition $definition = null)
38 {
39 if (null === $definition) {
40 $this->definition = new InputDefinition();
41 } else {
42 $this->bind($definition);
43 $this->validate();
44 }
45 }
46
53 {
54 $this->arguments = array();
55 $this->options = array();
56 $this->definition = $definition;
57
58 $this->parse();
59 }
60
64 abstract protected function parse();
65
69 public function validate()
70 {
71 if (count($this->arguments) < $this->definition->getArgumentRequiredCount()) {
72 throw new \RuntimeException('Not enough arguments.');
73 }
74 }
75
76 public function isInteractive()
77 {
78 return $this->interactive;
79 }
80
82 {
83 $this->interactive = (Boolean) $interactive;
84 }
85
91 public function getArguments()
92 {
93 return array_merge($this->definition->getArgumentDefaults(), $this->arguments);
94 }
95
105 public function getArgument($name)
106 {
107 if (!$this->definition->hasArgument($name)) {
108 throw new \InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
109 }
110
111 return isset($this->arguments[$name]) ? $this->arguments[$name] : $this->definition->getArgument($name)->getDefault();
112 }
113
122 public function setArgument($name, $value)
123 {
124 if (!$this->definition->hasArgument($name)) {
125 throw new \InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
126 }
127
128 $this->arguments[$name] = $value;
129 }
130
138 public function hasArgument($name)
139 {
140 return $this->definition->hasArgument($name);
141 }
142
148 public function getOptions()
149 {
150 return array_merge($this->definition->getOptionDefaults(), $this->options);
151 }
152
162 public function getOption($name)
163 {
164 if (!$this->definition->hasOption($name)) {
165 throw new \InvalidArgumentException(sprintf('The "%s" option does not exist.', $name));
166 }
167
168 return isset($this->options[$name]) ? $this->options[$name] : $this->definition->getOption($name)->getDefault();
169 }
170
179 public function setOption($name, $value)
180 {
181 if (!$this->definition->hasOption($name)) {
182 throw new \InvalidArgumentException(sprintf('The "%s" option does not exist.', $name));
183 }
184
185 $this->options[$name] = $value;
186 }
187
195 public function hasOption($name)
196 {
197 return $this->definition->hasOption($name);
198 }
199}
__construct(InputDefinition $definition=null)
Definição Input.php:37
bind(InputDefinition $definition)
Definição Input.php:52