MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
Shell.php
Ir para a documentação deste ficheiro.
1
<?php
2
3
namespace
Symfony\Component\Console
;
4
5
use
Symfony\Component\Console\Application
;
6
use
Symfony\Component\Console\Input\StringInput
;
7
use
Symfony\Component\Console\Output\ConsoleOutput
;
8
9
/*
10
* This file is part of the Symfony framework.
11
*
12
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
13
*
14
* This source file is subject to the MIT license that is bundled
15
* with this source code in the file LICENSE.
16
*/
17
26
class
Shell
27
{
28
protected
$application
;
29
protected
$history
;
30
protected
$output
;
31
42
public
function
__construct
(
Application
$application
)
43
{
44
if
(!function_exists(
'readline'
)) {
45
throw
new \RuntimeException(
'Unable to start the shell as the Readline extension is not enabled.'
);
46
}
47
48
$this->application =
$application
;
49
$this->history = getenv(
'HOME'
).
'/.history_'
.
$application
->getName();
50
$this->output =
new
ConsoleOutput
();
51
}
52
56
public
function
run
()
57
{
58
$this->application->setAutoExit(
false
);
59
$this->application->setCatchExceptions(
true
);
60
61
readline_read_history($this->history);
62
readline_completion_function(array($this,
'autocompleter'
));
63
64
$this->output->writeln($this->
getHeader
());
65
while
(
true
) {
66
$command = readline($this->application->getName().
' > '
);
67
68
if
(
false
=== $command) {
69
$this->output->writeln(
"\n"
);
70
71
break
;
72
}
73
74
readline_add_history($command);
75
readline_write_history($this->history);
76
77
if
(0 !== $ret = $this->application->run(
new
StringInput
($command), $this->output)) {
78
$this->output->writeln(sprintf(
'<error>The command terminated with an error status (%s)</error>'
, $ret));
79
}
80
}
81
}
82
89
protected
function
autocompleter
($text, $position)
90
{
91
$info = readline_info();
92
$text = substr($info[
'line_buffer'
], 0, $info[
'end'
]);
93
94
if
($info[
'point'
] !== $info[
'end'
]) {
95
return
true
;
96
}
97
98
// task name?
99
if
(
false
=== strpos($text,
' '
) || !$text) {
100
return
array_keys($this->application->all());
101
}
102
103
// options and arguments?
104
try
{
105
$command = $this->application->findCommand(substr($text, 0, strpos($text,
' '
)));
106
}
catch
(\Exception $e) {
107
return
true
;
108
}
109
110
$list = array(
'--help'
);
111
foreach
($command->getDefinition()->getOptions() as $option) {
112
$list[] =
'--'
.$option->getName();
113
}
114
115
return
$list;
116
}
117
123
protected
function
getHeader
()
124
{
125
return
<<<EOF
126
127
Welcome to the <info>{$this->application->getName()}</info> shell (<comment>{$this->application->getVersion()}</comment>).
128
129
At the prompt, type <comment>help</comment>
for
some help,
130
or <comment>list</comment> to
get
a list available commands.
131
132
To exit the shell, type <comment>^D</comment>.
133
134
EOF;
135
}
136
}
Symfony\Component\Console\Application
Definição
Application.php:46
Symfony\Component\Console\Input\StringInput
Definição
StringInput.php:24
Symfony\Component\Console\Output\ConsoleOutput
Definição
ConsoleOutput.php:28
Symfony\Component\Console\Shell
Definição
Shell.php:27
Symfony\Component\Console\Shell\__construct
__construct(Application $application)
Definição
Shell.php:42
Symfony\Component\Console\Shell\autocompleter
autocompleter($text, $position)
Definição
Shell.php:89
Symfony\Component\Console\Shell\$application
$application
Definição
Shell.php:28
Symfony\Component\Console\Shell\getHeader
getHeader()
Definição
Shell.php:123
Symfony\Component\Console\Shell\$history
$history
Definição
Shell.php:29
Symfony\Component\Console\Shell\$output
$output
Definição
Shell.php:30
Symfony\Component\Console\Shell\run
run()
Definição
Shell.php:56
Symfony\Component\Console
Definição
Application.php:3
classes
extensions
doctrine-dbal
Doctrine
Symfony
Component
Console
Shell.php
Gerado por
1.10.0