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

Command.php

Zuletzt modifiziert: 09.10.2024, 12:56 - Dateigröße: 6.36 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\Finder\Shell;
 013   
 014  @trigger_error('The '.__NAMESPACE__.'\Command class is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
 015   
 016  /**
 017   * @author Jean-François Simon <contact@jfsimon.fr>
 018   *
 019   * @deprecated since 2.8, to be removed in 3.0.
 020   */
 021  class Command
 022  {
 023      /**
 024       * @var Command|null
 025       */
 026      private $parent;
 027   
 028      /**
 029       * @var array
 030       */
 031      private $bits = array();
 032   
 033      /**
 034       * @var array
 035       */
 036      private $labels = array();
 037   
 038      /**
 039       * @var \Closure|null
 040       */
 041      private $errorHandler;
 042   
 043      /**
 044       * Constructor.
 045       *
 046       * @param Command|null $parent Parent command
 047       */
 048      public function __construct(Command $parent = null)
 049      {
 050          $this->parent = $parent;
 051      }
 052   
 053      /**
 054       * Returns command as string.
 055       *
 056       * @return string
 057       */
 058      public function __toString()
 059      {
 060          return $this->join();
 061      }
 062   
 063      /**
 064       * Creates a new Command instance.
 065       *
 066       * @param Command|null $parent Parent command
 067       *
 068       * @return Command New Command instance
 069       */
 070      public static function create(Command $parent = null)
 071      {
 072          return new self($parent);
 073      }
 074   
 075      /**
 076       * Escapes special chars from input.
 077       *
 078       * @param string $input A string to escape
 079       *
 080       * @return string The escaped string
 081       */
 082      public static function escape($input)
 083      {
 084          return escapeshellcmd($input);
 085      }
 086   
 087      /**
 088       * Quotes input.
 089       *
 090       * @param string $input An argument string
 091       *
 092       * @return string The quoted string
 093       */
 094      public static function quote($input)
 095      {
 096          return escapeshellarg($input);
 097      }
 098   
 099      /**
 100       * Appends a string or a Command instance.
 101       *
 102       * @param string|Command $bit
 103       *
 104       * @return Command The current Command instance
 105       */
 106      public function add($bit)
 107      {
 108          $this->bits[] = $bit;
 109   
 110          return $this;
 111      }
 112   
 113      /**
 114       * Prepends a string or a command instance.
 115       *
 116       * @param string|Command $bit
 117       *
 118       * @return Command The current Command instance
 119       */
 120      public function top($bit)
 121      {
 122          array_unshift($this->bits, $bit);
 123   
 124          foreach ($this->labels as $label => $index) {
 125              $this->labels[$label] += 1;
 126          }
 127   
 128          return $this;
 129      }
 130   
 131      /**
 132       * Appends an argument, will be quoted.
 133       *
 134       * @param string $arg
 135       *
 136       * @return Command The current Command instance
 137       */
 138      public function arg($arg)
 139      {
 140          $this->bits[] = self::quote($arg);
 141   
 142          return $this;
 143      }
 144   
 145      /**
 146       * Appends escaped special command chars.
 147       *
 148       * @param string $esc
 149       *
 150       * @return Command The current Command instance
 151       */
 152      public function cmd($esc)
 153      {
 154          $this->bits[] = self::escape($esc);
 155   
 156          return $this;
 157      }
 158   
 159      /**
 160       * Inserts a labeled command to feed later.
 161       *
 162       * @param string $label The unique label
 163       *
 164       * @return Command The current Command instance
 165       *
 166       * @throws \RuntimeException If label already exists
 167       */
 168      public function ins($label)
 169      {
 170          if (isset($this->labels[$label])) {
 171              throw new \RuntimeException(sprintf('Label "%s" already exists.', $label));
 172          }
 173   
 174          $this->bits[] = self::create($this);
 175          $this->labels[$label] = count($this->bits) - 1;
 176   
 177          return $this->bits[$this->labels[$label]];
 178      }
 179   
 180      /**
 181       * Retrieves a previously labeled command.
 182       *
 183       * @param string $label
 184       *
 185       * @return Command The labeled command
 186       *
 187       * @throws \RuntimeException
 188       */
 189      public function get($label)
 190      {
 191          if (!isset($this->labels[$label])) {
 192              throw new \RuntimeException(sprintf('Label "%s" does not exist.', $label));
 193          }
 194   
 195          return $this->bits[$this->labels[$label]];
 196      }
 197   
 198      /**
 199       * Returns parent command (if any).
 200       *
 201       * @return Command Parent command
 202       *
 203       * @throws \RuntimeException If command has no parent
 204       */
 205      public function end()
 206      {
 207          if (null === $this->parent) {
 208              throw new \RuntimeException('Calling end on root command doesn\'t make sense.');
 209          }
 210   
 211          return $this->parent;
 212      }
 213   
 214      /**
 215       * Counts bits stored in command.
 216       *
 217       * @return int The bits count
 218       */
 219      public function length()
 220      {
 221          return count($this->bits);
 222      }
 223   
 224      /**
 225       * @param \Closure $errorHandler
 226       *
 227       * @return Command
 228       */
 229      public function setErrorHandler(\Closure $errorHandler)
 230      {
 231          $this->errorHandler = $errorHandler;
 232   
 233          return $this;
 234      }
 235   
 236      /**
 237       * @return \Closure|null
 238       */
 239      public function getErrorHandler()
 240      {
 241          return $this->errorHandler;
 242      }
 243   
 244      /**
 245       * Executes current command.
 246       *
 247       * @return array The command result
 248       *
 249       * @throws \RuntimeException
 250       */
 251      public function execute()
 252      {
 253          if (null === $errorHandler = $this->errorHandler) {
 254              exec($this->join(), $output);
 255          } else {
 256              $process = proc_open($this->join(), array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w')), $pipes);
 257              $output = preg_split('~(\r\n|\r|\n)~', stream_get_contents($pipes[1]), -1, PREG_SPLIT_NO_EMPTY);
 258   
 259              if ($error = stream_get_contents($pipes[2])) {
 260                  $errorHandler($error);
 261              }
 262   
 263              proc_close($process);
 264          }
 265   
 266          return $output ?: array();
 267      }
 268   
 269      /**
 270       * Joins bits.
 271       *
 272       * @return string
 273       */
 274      public function join()
 275      {
 276          return implode(' ', array_filter(
 277              array_map(function ($bit) {
 278                  return $bit instanceof Command ? $bit->join() : ($bit ?: null);
 279              }, $this->bits),
 280              function ($bit) { return null !== $bit; }
 281          ));
 282      }
 283   
 284      /**
 285       * Insert a string or a Command instance before the bit at given position $index (index starts from 0).
 286       *
 287       * @param string|Command $bit
 288       * @param int            $index
 289       *
 290       * @return Command The current Command instance
 291       */
 292      public function addAtIndex($bit, $index)
 293      {
 294          array_splice($this->bits, $index, 0, $bit instanceof self ? array($bit) : $bit);
 295   
 296          return $this;
 297      }
 298  }
 299