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

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

CommandTester.php

Zuletzt modifiziert: 02.04.2025, 15:03 - Dateigröße: 4.48 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\Tester;
013   
014  use Symfony\Component\Console\Command\Command;
015  use Symfony\Component\Console\Input\ArrayInput;
016  use Symfony\Component\Console\Input\InputInterface;
017  use Symfony\Component\Console\Output\OutputInterface;
018  use Symfony\Component\Console\Output\StreamOutput;
019   
020  /**
021   * Eases the testing of console commands.
022   *
023   * @author Fabien Potencier <fabien@symfony.com>
024   * @author Robin Chalas <robin.chalas@gmail.com>
025   */
026  class CommandTester
027  {
028      private $command;
029      private $input;
030      private $output;
031      private $inputs = [];
032      private $statusCode;
033   
034      public function __construct(Command $command)
035      {
036          $this->command = $command;
037      }
038   
039      /**
040       * Executes the command.
041       *
042       * Available execution options:
043       *
044       *  * interactive: Sets the input interactive flag
045       *  * decorated:   Sets the output decorated flag
046       *  * verbosity:   Sets the output verbosity flag
047       *
048       * @param array $input   An array of command arguments and options
049       * @param array $options An array of execution options
050       *
051       * @return int The command exit code
052       */
053      public function execute(array $input, array $options = [])
054      {
055          // set the command name automatically if the application requires
056          // this argument and no command name was passed
057          if (!isset($input['command'])
058              && (null !== $application = $this->command->getApplication())
059              && $application->getDefinition()->hasArgument('command')
060          ) {
061              $input = array_merge(['command' => $this->command->getName()], $input);
062          }
063   
064          $this->input = new ArrayInput($input);
065          // Use an in-memory input stream even if no inputs are set so that QuestionHelper::ask() does not rely on the blocking STDIN.
066          $this->input->setStream(self::createStream($this->inputs));
067   
068          if (isset($options['interactive'])) {
069              $this->input->setInteractive($options['interactive']);
070          }
071   
072          $this->output = new StreamOutput(fopen('php://memory', 'w', false));
073          $this->output->setDecorated(isset($options['decorated']) ? $options['decorated'] : false);
074          if (isset($options['verbosity'])) {
075              $this->output->setVerbosity($options['verbosity']);
076          }
077   
078          return $this->statusCode = $this->command->run($this->input, $this->output);
079      }
080   
081      /**
082       * Gets the display returned by the last execution of the command.
083       *
084       * @param bool $normalize Whether to normalize end of lines to \n or not
085       *
086       * @return string The display
087       */
088      public function getDisplay($normalize = false)
089      {
090          if (null === $this->output) {
091              throw new \RuntimeException('Output not initialized, did you execute the command before requesting the display?');
092          }
093   
094          rewind($this->output->getStream());
095   
096          $display = stream_get_contents($this->output->getStream());
097   
098          if ($normalize) {
099              $display = str_replace(\PHP_EOL, "\n", $display);
100          }
101   
102          return $display;
103      }
104   
105      /**
106       * Gets the input instance used by the last execution of the command.
107       *
108       * @return InputInterface The current input instance
109       */
110      public function getInput()
111      {
112          return $this->input;
113      }
114   
115      /**
116       * Gets the output instance used by the last execution of the command.
117       *
118       * @return OutputInterface The current output instance
119       */
120      public function getOutput()
121      {
122          return $this->output;
123      }
124   
125      /**
126       * Gets the status code returned by the last execution of the application.
127       *
128       * @return int The status code
129       */
130      public function getStatusCode()
131      {
132          return $this->statusCode;
133      }
134   
135      /**
136       * Sets the user inputs.
137       *
138       * @param array $inputs An array of strings representing each input
139       *                      passed to the command input stream
140       *
141       * @return CommandTester
142       */
143      public function setInputs(array $inputs)
144      {
145          $this->inputs = $inputs;
146   
147          return $this;
148      }
149   
150      private static function createStream(array $inputs)
151      {
152          $stream = fopen('php://memory', 'r+', false);
153   
154          foreach ($inputs as $input) {
155              fwrite($stream, $input.\PHP_EOL);
156          }
157   
158          rewind($stream);
159   
160          return $stream;
161      }
162  }
163