MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
ArrayInput.php
Ir para a documentação deste ficheiro.
1
<?php
2
3
namespace
Symfony\Component\Console\Input
;
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
23
class
ArrayInput
extends
Input
24
{
25
protected
$parameters
;
26
33
public
function
__construct
(array
$parameters
,
InputDefinition
$definition
=
null
)
34
{
35
$this->parameters =
$parameters
;
36
37
parent::__construct(
$definition
);
38
}
39
45
public
function
getFirstArgument
()
46
{
47
foreach
($this->parameters as $key => $value) {
48
if
($key &&
'-'
=== $key[0]) {
49
continue
;
50
}
51
52
return
$value;
53
}
54
}
55
66
public
function
hasParameterOption
($values)
67
{
68
if
(!is_array($values)) {
69
$values = array($values);
70
}
71
72
foreach
($this->parameters as $k => $v) {
73
if
(!is_int($k)) {
74
$v = $k;
75
}
76
77
if
(in_array($v, $values)) {
78
return
true
;
79
}
80
}
81
82
return
false
;
83
}
84
88
protected
function
parse
()
89
{
90
foreach
($this->parameters as $key => $value) {
91
if
(
'--'
=== substr($key, 0, 2)) {
92
$this->
addLongOption
(substr($key, 2), $value);
93
} elseif (
'-'
=== $key[0]) {
94
$this->
addShortOption
(substr($key, 1), $value);
95
}
else
{
96
$this->
addArgument
($key, $value);
97
}
98
}
99
}
100
109
protected
function
addShortOption
($shortcut, $value)
110
{
111
if
(!$this->definition->hasShortcut($shortcut)) {
112
throw
new \InvalidArgumentException(sprintf(
'The "-%s" option does not exist.'
, $shortcut));
113
}
114
115
$this->
addLongOption
($this->definition->getOptionForShortcut($shortcut)->getName(), $value);
116
}
117
127
protected
function
addLongOption
($name, $value)
128
{
129
if
(!$this->definition->hasOption($name)) {
130
throw
new \InvalidArgumentException(sprintf(
'The "--%s" option does not exist.'
, $name));
131
}
132
133
$option = $this->definition->getOption($name);
134
135
if
(
null
=== $value) {
136
if
($option->isValueRequired()) {
137
throw
new \InvalidArgumentException(sprintf(
'The "--%s" option requires a value.'
, $name));
138
}
139
140
$value = $option->isValueOptional() ? $option->getDefault() :
true
;
141
}
142
143
$this->options[$name] = $value;
144
}
145
154
protected
function
addArgument
($name, $value)
155
{
156
if
(!$this->definition->hasArgument($name)) {
157
throw
new \InvalidArgumentException(sprintf(
'The "%s" argument does not exist.'
, $name));
158
}
159
160
$this->arguments[$name] = $value;
161
}
162
}
Symfony\Component\Console\Input\ArrayInput
Definição
ArrayInput.php:24
Symfony\Component\Console\Input\ArrayInput\hasParameterOption
hasParameterOption($values)
Definição
ArrayInput.php:66
Symfony\Component\Console\Input\ArrayInput\parse
parse()
Definição
ArrayInput.php:88
Symfony\Component\Console\Input\ArrayInput\addArgument
addArgument($name, $value)
Definição
ArrayInput.php:154
Symfony\Component\Console\Input\ArrayInput\addShortOption
addShortOption($shortcut, $value)
Definição
ArrayInput.php:109
Symfony\Component\Console\Input\ArrayInput\addLongOption
addLongOption($name, $value)
Definição
ArrayInput.php:127
Symfony\Component\Console\Input\ArrayInput\$parameters
$parameters
Definição
ArrayInput.php:25
Symfony\Component\Console\Input\ArrayInput\__construct
__construct(array $parameters, InputDefinition $definition=null)
Definição
ArrayInput.php:33
Symfony\Component\Console\Input\ArrayInput\getFirstArgument
getFirstArgument()
Definição
ArrayInput.php:45
Symfony\Component\Console\Input\InputDefinition
Definição
InputDefinition.php:27
Symfony\Component\Console\Input\Input
Definição
Input.php:26
Symfony\Component\Console\Input\Input\$definition
$definition
Definição
Input.php:27
Symfony\Component\Console\Input
Definição
ArgvInput.php:3
classes
extensions
doctrine-dbal
Doctrine
Symfony
Component
Console
Input
ArrayInput.php
Gerado por
1.10.0