MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
Command.php
Ir para a documentação deste ficheiro.
1
<?php
2
3
namespace
Symfony\Component\Console\Command
;
4
5
use
Symfony\Component\Console\Input\InputDefinition
;
6
use
Symfony\Component\Console\Input\InputOption
;
7
use
Symfony\Component\Console\Input\InputArgument
;
8
use
Symfony\Component\Console\Input\InputInterface
;
9
use
Symfony\Component\Console\Output\OutputInterface
;
10
use
Symfony\Component\Console\Application
;
11
12
/*
13
* This file is part of the Symfony framework.
14
*
15
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
16
*
17
* This source file is subject to the MIT license that is bundled
18
* with this source code in the file LICENSE.
19
*/
20
26
class
Command
27
{
28
protected
$name
;
29
protected
$namespace
;
30
protected
$aliases
;
31
protected
$definition
;
32
protected
$help
;
33
protected
$application
;
34
protected
$description
;
35
protected
$ignoreValidationErrors
;
36
protected
$applicationDefinitionMerged
;
37
protected
$code
;
38
46
public
function
__construct
(
$name
=
null
)
47
{
48
$this->definition =
new
InputDefinition
();
49
$this->ignoreValidationErrors =
false
;
50
$this->applicationDefinitionMerged =
false
;
51
$this->aliases = array();
52
53
if
(
null
!==
$name
) {
54
$this->
setName
(
$name
);
55
}
56
57
$this->
configure
();
58
59
if
(!$this->name) {
60
throw
new \LogicException(
'The command name cannot be empty.'
);
61
}
62
}
63
69
public
function
setApplication
(
Application
$application
=
null
)
70
{
71
$this->application =
$application
;
72
}
73
77
protected
function
configure
()
78
{
79
}
80
91
protected
function
execute
(
InputInterface
$input,
OutputInterface
$output)
92
{
93
throw
new \LogicException(
'You must override the execute() method in the concrete command class.'
);
94
}
95
102
protected
function
interact
(
InputInterface
$input,
OutputInterface
$output)
103
{
104
}
105
115
protected
function
initialize
(
InputInterface
$input,
OutputInterface
$output)
116
{
117
}
118
125
public
function
run
(
InputInterface
$input,
OutputInterface
$output)
126
{
127
// add the application arguments and options
128
$this->
mergeApplicationDefinition
();
129
130
// bind the input against the command specific arguments/options
131
try
{
132
$input->
bind
($this->definition);
133
}
catch
(\Exception $e) {
134
if
(!$this->ignoreValidationErrors) {
135
throw
$e;
136
}
137
}
138
139
$this->
initialize
($input, $output);
140
141
if
($input->isInteractive()) {
142
$this->
interact
($input, $output);
143
}
144
145
$input->
validate
();
146
147
if
($this->code) {
148
return
call_user_func($this->code, $input, $output);
149
}
else
{
150
return
$this->
execute
($input, $output);
151
}
152
}
153
161
public
function
setCode
(\Closure
$code
)
162
{
163
$this->code =
$code
;
164
165
return
$this;
166
}
167
171
protected
function
mergeApplicationDefinition
()
172
{
173
if
(
null
=== $this->application ||
true
=== $this->applicationDefinitionMerged) {
174
return
;
175
}
176
177
$this->definition->setArguments(array_merge(
178
$this->application->getDefinition()->getArguments(),
179
$this->definition->getArguments()
180
));
181
182
$this->definition->addOptions($this->application->getDefinition()->getOptions());
183
184
$this->applicationDefinitionMerged =
true
;
185
}
186
194
public
function
setDefinition
(
$definition
)
195
{
196
if
(
$definition
instanceof
InputDefinition
) {
197
$this->definition =
$definition
;
198
}
else
{
199
$this->definition->setDefinition(
$definition
);
200
}
201
202
$this->applicationDefinitionMerged =
false
;
203
204
return
$this;
205
}
206
212
public
function
getDefinition
()
213
{
214
return
$this->definition
;
215
}
216
227
public
function
addArgument
(
$name
, $mode =
null
,
$description
=
''
, $default =
null
)
228
{
229
$this->definition->addArgument(
new
InputArgument
(
$name
, $mode,
$description
, $default));
230
231
return
$this;
232
}
233
245
public
function
addOption
(
$name
, $shortcut =
null
, $mode =
null
,
$description
=
''
, $default =
null
)
246
{
247
$this->definition->addOption(
new
InputOption
(
$name
, $shortcut, $mode,
$description
, $default));
248
249
return
$this;
250
}
251
266
public
function
setName
(
$name
)
267
{
268
if
(
false
!== $pos = strrpos(
$name
,
':'
)) {
269
$namespace
= substr(
$name
, 0, $pos);
270
$name
= substr(
$name
, $pos + 1);
271
}
else
{
272
$namespace
=
$this->namespace
;
273
}
274
275
if
(!
$name
) {
276
throw
new \InvalidArgumentException(
'A command name cannot be empty.'
);
277
}
278
279
$this->
namespace
=
$namespace
;
280
$this->name =
$name
;
281
282
return
$this;
283
}
284
290
public
function
getNamespace
()
291
{
292
return
$this->namespace
;
293
}
294
300
public
function
getName
()
301
{
302
return
$this->name
;
303
}
304
310
public
function
getFullName
()
311
{
312
return
$this->
getNamespace
() ? $this->
getNamespace
().
':'
.$this->
getName
() : $this->
getName
();
313
}
314
322
public
function
setDescription
(
$description
)
323
{
324
$this->description =
$description
;
325
326
return
$this;
327
}
328
334
public
function
getDescription
()
335
{
336
return
$this->description
;
337
}
338
346
public
function
setHelp
(
$help
)
347
{
348
$this->help =
$help
;
349
350
return
$this;
351
}
352
358
public
function
getHelp
()
359
{
360
return
$this->help
;
361
}
362
369
public
function
getProcessedHelp
()
370
{
371
$name
= $this->
namespace
.
':'
.
$this->name
;
372
373
$placeholders = array(
374
'%command.name%'
,
375
'%command.full_name%'
376
);
377
$replacements = array(
378
$name
,
379
$_SERVER[
'PHP_SELF'
].
' '
.
$name
380
);
381
382
return
str_replace($placeholders, $replacements, $this->
getHelp
());
383
}
384
392
public
function
setAliases
(
$aliases
)
393
{
394
$this->aliases =
$aliases
;
395
396
return
$this;
397
}
398
404
public
function
getAliases
()
405
{
406
return
$this->aliases
;
407
}
408
414
public
function
getSynopsis
()
415
{
416
return
sprintf(
'%s %s'
, $this->
getFullName
(), $this->definition->getSynopsis());
417
}
418
428
protected
function
getHelper
(
$name
)
429
{
430
return
$this->application->getHelperSet()->get(
$name
);
431
}
432
442
public
function
__get
(
$name
)
443
{
444
return
$this->application->getHelperSet()->get(
$name
);
445
}
446
452
public
function
asText
()
453
{
454
$messages = array(
455
'<comment>Usage:</comment>'
,
456
' '
.$this->
getSynopsis
(),
457
''
,
458
);
459
460
if
($this->
getAliases
()) {
461
$messages[] =
'<comment>Aliases:</comment> <info>'
.implode(
', '
, $this->
getAliases
()).
'</info>'
;
462
}
463
464
$messages[] = $this->definition->asText();
465
466
if
(
$help
= $this->
getProcessedHelp
()) {
467
$messages[] =
'<comment>Help:</comment>'
;
468
$messages[] =
' '
.implode(
"\n "
, explode(
"\n"
,
$help
)).
"\n"
;
469
}
470
471
return
implode(
"\n"
, $messages);
472
}
473
481
public
function
asXml
($asDom =
false
)
482
{
483
$dom = new \DOMDocument(
'1.0'
,
'UTF-8'
);
484
$dom->formatOutput =
true
;
485
$dom->appendChild($commandXML = $dom->createElement(
'command'
));
486
$commandXML->setAttribute(
'id'
, $this->
getFullName
());
487
$commandXML->setAttribute(
'namespace'
, $this->
getNamespace
() ? $this->
getNamespace
() :
'_global'
);
488
$commandXML->setAttribute(
'name'
, $this->
getName
());
489
490
$commandXML->appendChild($usageXML = $dom->createElement(
'usage'
));
491
$usageXML->appendChild($dom->createTextNode(sprintf($this->
getSynopsis
(),
''
)));
492
493
$commandXML->appendChild($descriptionXML = $dom->createElement(
'description'
));
494
$descriptionXML->appendChild($dom->createTextNode(implode(
"\n "
, explode(
"\n"
, $this->
getDescription
()))));
495
496
$commandXML->appendChild($helpXML = $dom->createElement(
'help'
));
497
$help
=
$this->help
;
498
$helpXML->appendChild($dom->createTextNode(implode(
"\n "
, explode(
"\n"
,
$help
))));
499
500
$commandXML->appendChild($aliasesXML = $dom->createElement(
'aliases'
));
501
foreach
($this->
getAliases
() as $alias) {
502
$aliasesXML->appendChild($aliasXML = $dom->createElement(
'alias'
));
503
$aliasXML->appendChild($dom->createTextNode($alias));
504
}
505
506
$definition
= $this->definition->asXml(
true
);
507
$commandXML->appendChild($dom->importNode(
$definition
->getElementsByTagName(
'arguments'
)->item(0),
true
));
508
$commandXML->appendChild($dom->importNode(
$definition
->getElementsByTagName(
'options'
)->item(0),
true
));
509
510
return
$asDom ? $dom : $dom->saveXml();
511
}
512
}
Symfony\Component\Console\Application
Definição
Application.php:46
Symfony\Component\Console\Command\Command
Definição
Command.php:27
Symfony\Component\Console\Command\Command\addArgument
addArgument($name, $mode=null, $description='', $default=null)
Definição
Command.php:227
Symfony\Component\Console\Command\Command\$definition
$definition
Definição
Command.php:31
Symfony\Component\Console\Command\Command\getAliases
getAliases()
Definição
Command.php:404
Symfony\Component\Console\Command\Command\getNamespace
getNamespace()
Definição
Command.php:290
Symfony\Component\Console\Command\Command\getFullName
getFullName()
Definição
Command.php:310
Symfony\Component\Console\Command\Command\getDescription
getDescription()
Definição
Command.php:334
Symfony\Component\Console\Command\Command\setName
setName($name)
Definição
Command.php:266
Symfony\Component\Console\Command\Command\setDescription
setDescription($description)
Definição
Command.php:322
Symfony\Component\Console\Command\Command\$namespace
$namespace
Definição
Command.php:29
Symfony\Component\Console\Command\Command\getName
getName()
Definição
Command.php:300
Symfony\Component\Console\Command\Command\getHelp
getHelp()
Definição
Command.php:358
Symfony\Component\Console\Command\Command\setAliases
setAliases($aliases)
Definição
Command.php:392
Symfony\Component\Console\Command\Command\$application
$application
Definição
Command.php:33
Symfony\Component\Console\Command\Command\interact
interact(InputInterface $input, OutputInterface $output)
Definição
Command.php:102
Symfony\Component\Console\Command\Command\asXml
asXml($asDom=false)
Definição
Command.php:481
Symfony\Component\Console\Command\Command\setDefinition
setDefinition($definition)
Definição
Command.php:194
Symfony\Component\Console\Command\Command\getSynopsis
getSynopsis()
Definição
Command.php:414
Symfony\Component\Console\Command\Command\$code
$code
Definição
Command.php:37
Symfony\Component\Console\Command\Command\$aliases
$aliases
Definição
Command.php:30
Symfony\Component\Console\Command\Command\asText
asText()
Definição
Command.php:452
Symfony\Component\Console\Command\Command\$description
$description
Definição
Command.php:34
Symfony\Component\Console\Command\Command\setHelp
setHelp($help)
Definição
Command.php:346
Symfony\Component\Console\Command\Command\getProcessedHelp
getProcessedHelp()
Definição
Command.php:369
Symfony\Component\Console\Command\Command\mergeApplicationDefinition
mergeApplicationDefinition()
Definição
Command.php:171
Symfony\Component\Console\Command\Command\configure
configure()
Definição
Command.php:77
Symfony\Component\Console\Command\Command\setCode
setCode(\Closure $code)
Definição
Command.php:161
Symfony\Component\Console\Command\Command\__construct
__construct($name=null)
Definição
Command.php:46
Symfony\Component\Console\Command\Command\getHelper
getHelper($name)
Definição
Command.php:428
Symfony\Component\Console\Command\Command\$name
$name
Definição
Command.php:28
Symfony\Component\Console\Command\Command\execute
execute(InputInterface $input, OutputInterface $output)
Definição
Command.php:91
Symfony\Component\Console\Command\Command\__get
__get($name)
Definição
Command.php:442
Symfony\Component\Console\Command\Command\$ignoreValidationErrors
$ignoreValidationErrors
Definição
Command.php:35
Symfony\Component\Console\Command\Command\setApplication
setApplication(Application $application=null)
Definição
Command.php:69
Symfony\Component\Console\Command\Command\run
run(InputInterface $input, OutputInterface $output)
Definição
Command.php:125
Symfony\Component\Console\Command\Command\getDefinition
getDefinition()
Definição
Command.php:212
Symfony\Component\Console\Command\Command\$applicationDefinitionMerged
$applicationDefinitionMerged
Definição
Command.php:36
Symfony\Component\Console\Command\Command\initialize
initialize(InputInterface $input, OutputInterface $output)
Definição
Command.php:115
Symfony\Component\Console\Command\Command\$help
$help
Definição
Command.php:32
Symfony\Component\Console\Command\Command\addOption
addOption($name, $shortcut=null, $mode=null, $description='', $default=null)
Definição
Command.php:245
Symfony\Component\Console\Input\InputArgument
Definição
InputArgument.php:20
Symfony\Component\Console\Input\InputDefinition
Definição
InputDefinition.php:27
Symfony\Component\Console\Input\InputOption
Definição
InputOption.php:20
Symfony\Component\Console\Input\InputInterface
Definição
InputInterface.php:20
Symfony\Component\Console\Input\InputInterface\validate
validate()
Symfony\Component\Console\Input\InputInterface\bind
bind(InputDefinition $definition)
Symfony\Component\Console\Output\OutputInterface
Definição
OutputInterface.php:20
Symfony\Component\Console\Command
Definição
Command.php:3
classes
extensions
doctrine-dbal
Doctrine
Symfony
Component
Console
Command
Command.php
Gerado por
1.10.0