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.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

ProcessHelper.php

Zuletzt modifiziert: 09.10.2024, 12:56 - Dateigröße: 5.00 KiB


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