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 |
Shell.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;
013
014 use Symfony\Component\Console\Exception\RuntimeException;
015 use Symfony\Component\Console\Input\StringInput;
016 use Symfony\Component\Console\Output\ConsoleOutput;
017 use Symfony\Component\Process\ProcessBuilder;
018 use Symfony\Component\Process\PhpExecutableFinder;
019
020 /**
021 * A Shell wraps an Application to add shell capabilities to it.
022 *
023 * Support for history and completion only works with a PHP compiled
024 * with readline support (either --with-readline or --with-libedit)
025 *
026 * @deprecated since version 2.8, to be removed in 3.0.
027 *
028 * @author Fabien Potencier <fabien@symfony.com>
029 * @author Martin Hasoň <martin.hason@gmail.com>
030 */
031 class Shell
032 {
033 private $application;
034 private $history;
035 private $output;
036 private $hasReadline;
037 private $processIsolation = false;
038
039 /**
040 * Constructor.
041 *
042 * If there is no readline support for the current PHP executable
043 * a \RuntimeException exception is thrown.
044 *
045 * @param Application $application An application instance
046 */
047 public function __construct(Application $application)
048 {
049 @trigger_error('The '.__CLASS__.' class is deprecated since Symfony 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
050
051 $this->hasReadline = function_exists('readline');
052 $this->application = $application;
053 $this->history = getenv('HOME').'/.history_'.$application->getName();
054 $this->output = new ConsoleOutput();
055 }
056
057 /**
058 * Runs the shell.
059 */
060 public function run()
061 {
062 $this->application->setAutoExit(false);
063 $this->application->setCatchExceptions(true);
064
065 if ($this->hasReadline) {
066 readline_read_history($this->history);
067 readline_completion_function(array($this, 'autocompleter'));
068 }
069
070 $this->output->writeln($this->getHeader());
071 $php = null;
072 if ($this->processIsolation) {
073 $finder = new PhpExecutableFinder();
074 $php = $finder->find();
075 $this->output->writeln(<<<'EOF'
076 <info>Running with process isolation, you should consider this:</info>
077 * each command is executed as separate process,
078 * commands don't support interactivity, all params must be passed explicitly,
079 * commands output is not colorized.
080
081 EOF
082 );
083 }
084
085 while (true) {
086 $command = $this->readline();
087
088 if (false === $command) {
089 $this->output->writeln("\n");
090
091 break;
092 }
093
094 if ($this->hasReadline) {
095 readline_add_history($command);
096 readline_write_history($this->history);
097 }
098
099 if ($this->processIsolation) {
100 $pb = new ProcessBuilder();
101
102 $process = $pb
103 ->add($php)
104 ->add($_SERVER['argv'][0])
105 ->add($command)
106 ->inheritEnvironmentVariables(true)
107 ->getProcess()
108 ;
109
110 $output = $this->output;
111 $process->run(function ($type, $data) use ($output) {
112 $output->writeln($data);
113 });
114
115 $ret = $process->getExitCode();
116 } else {
117 $ret = $this->application->run(new StringInput($command), $this->output);
118 }
119
120 if (0 !== $ret) {
121 $this->output->writeln(sprintf('<error>The command terminated with an error status (%s)</error>', $ret));
122 }
123 }
124 }
125
126 /**
127 * Returns the shell header.
128 *
129 * @return string The header string
130 */
131 protected function getHeader()
132 {
133 return <<<EOF
134
135 Welcome to the <info>{$this->application->getName()}</info> shell (<comment>{$this->application->getVersion()}</comment>).
136
137 At the prompt, type <comment>help</comment> for some help,
138 or <comment>list</comment> to get a list of available commands.
139
140 To exit the shell, type <comment>^D</comment>.
141
142 EOF;
143
144 }
145
146 /**
147 * Renders a prompt.
148 *
149 * @return string The prompt
150 */
151 protected function getPrompt()
152 {
153 // using the formatter here is required when using readline
154 return $this->output->getFormatter()->format($this->application->getName().' > ');
155 }
156
157 protected function getOutput()
158 {
159 return $this->output;
160 }
161
162 protected function getApplication()
163 {
164 return $this->application;
165 }
166
167 /**
168 * Tries to return autocompletion for the current entered text.
169 *
170 * @param string $text The last segment of the entered text
171 *
172 * @return bool|array A list of guessed strings or true
173 */
174 private function autocompleter($text)
175 {
176 $info = readline_info();
177 $text = substr($info['line_buffer'], 0, $info['end']);
178
179 if ($info['point'] !== $info['end']) {
180 return true;
181 }
182
183 // task name?
184 if (false === strpos($text, ' ') || !$text) {
185 return array_keys($this->application->all());
186 }
187
188 // options and arguments?
189 try {
190 $command = $this->application->find(substr($text, 0, strpos($text, ' ')));
191 } catch (\Exception $e) {
192 return true;
193 }
194
195 $list = array('--help');
196 foreach ($command->getDefinition()->getOptions() as $option) {
197 $list[] = '--'.$option->getName();
198 }
199
200 return $list;
201 }
202
203 /**
204 * Reads a single line from standard input.
205 *
206 * @return string The single line from standard input
207 */
208 private function readline()
209 {
210 if ($this->hasReadline) {
211 $line = readline($this->getPrompt());
212 } else {
213 $this->output->write($this->getPrompt());
214 $line = fgets(STDIN, 1024);
215 $line = (false === $line || '' === $line) ? false : rtrim($line);
216 }
217
218 return $line;
219 }
220
221 public function getProcessIsolation()
222 {
223 return $this->processIsolation;
224 }
225
226 public function setProcessIsolation($processIsolation)
227 {
228 $this->processIsolation = (bool) $processIsolation;
229
230 if ($this->processIsolation && !class_exists('Symfony\\Component\\Process\\Process')) {
231 throw new RuntimeException('Unable to isolate processes as the Symfony Process Component is not installed.');
232 }
233 }
234 }
235