Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
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 |
ProcessHelper.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\Helper;
013
014 use Symfony\Component\Console\Output\ConsoleOutputInterface;
015 use Symfony\Component\Console\Output\OutputInterface;
016 use Symfony\Component\Process\Exception\ProcessFailedException;
017 use Symfony\Component\Process\Process;
018
019 /**
020 * The ProcessHelper class provides helpers to run external processes.
021 *
022 * @author Fabien Potencier <fabien@symfony.com>
023 */
024 class ProcessHelper extends Helper
025 {
026 /**
027 * Runs an external process.
028 *
029 * @param OutputInterface $output An OutputInterface instance
030 * @param string|array|Process $cmd An instance of Process or an array of arguments to escape and run or a command to run
031 * @param string|null $error An error message that must be displayed if something went wrong
032 * @param callable|null $callback A PHP callback to run whenever there is some
033 * output available on STDOUT or STDERR
034 * @param int $verbosity The threshold for verbosity
035 *
036 * @return Process The process that ran
037 */
038 public function run(OutputInterface $output, $cmd, $error = null, callable $callback = null, $verbosity = OutputInterface::VERBOSITY_VERY_VERBOSE)
039 {
040 if (!class_exists(Process::class)) {
041 throw new \LogicException('The ProcessHelper cannot be run as the Process component is not installed. Try running "compose require symfony/process".');
042 }
043
044 if ($output instanceof ConsoleOutputInterface) {
045 $output = $output->getErrorOutput();
046 }
047
048 $formatter = $this->getHelperSet()->get('debug_formatter');
049
050 if ($cmd instanceof Process) {
051 $process = $cmd;
052 } else {
053 $process = new Process($cmd);
054 }
055
056 if ($verbosity <= $output->getVerbosity()) {
057 $output->write($formatter->start(spl_object_hash($process), $this->escapeString($process->getCommandLine())));
058 }
059
060 if ($output->isDebug()) {
061 $callback = $this->wrapCallback($output, $process, $callback);
062 }
063
064 $process->run($callback);
065
066 if ($verbosity <= $output->getVerbosity()) {
067 $message = $process->isSuccessful() ? 'Command ran successfully' : sprintf('%s Command did not run successfully', $process->getExitCode());
068 $output->write($formatter->stop(spl_object_hash($process), $message, $process->isSuccessful()));
069 }
070
071 if (!$process->isSuccessful() && null !== $error) {
072 $output->writeln(sprintf('<error>%s</error>', $this->escapeString($error)));
073 }
074
075 return $process;
076 }
077
078 /**
079 * Runs the process.
080 *
081 * This is identical to run() except that an exception is thrown if the process
082 * exits with a non-zero exit code.
083 *
084 * @param OutputInterface $output An OutputInterface instance
085 * @param string|Process $cmd An instance of Process or a command to run
086 * @param string|null $error An error message that must be displayed if something went wrong
087 * @param callable|null $callback A PHP callback to run whenever there is some
088 * output available on STDOUT or STDERR
089 *
090 * @return Process The process that ran
091 *
092 * @throws ProcessFailedException
093 *
094 * @see run()
095 */
096 public function mustRun(OutputInterface $output, $cmd, $error = null, callable $callback = null)
097 {
098 $process = $this->run($output, $cmd, $error, $callback);
099
100 if (!$process->isSuccessful()) {
101 throw new ProcessFailedException($process);
102 }
103
104 return $process;
105 }
106
107 /**
108 * Wraps a Process callback to add debugging output.
109 *
110 * @param OutputInterface $output An OutputInterface interface
111 * @param Process $process The Process
112 * @param callable|null $callback A PHP callable
113 *
114 * @return callable
115 */
116 public function wrapCallback(OutputInterface $output, Process $process, callable $callback = null)
117 {
118 if ($output instanceof ConsoleOutputInterface) {
119 $output = $output->getErrorOutput();
120 }
121
122 $formatter = $this->getHelperSet()->get('debug_formatter');
123
124 return function ($type, $buffer) use ($output, $process, $callback, $formatter) {
125 $output->write($formatter->progress(spl_object_hash($process), $this->escapeString($buffer), Process::ERR === $type));
126
127 if (null !== $callback) {
128 \call_user_func($callback, $type, $buffer);
129 }
130 };
131 }
132
133 private function escapeString($str)
134 {
135 return str_replace('<', '\\<', $str);
136 }
137
138 /**
139 * {@inheritdoc}
140 */
141 public function getName()
142 {
143 return 'process';
144 }
145 }
146