Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

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

ApplicationDescription.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 3.43 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\Descriptor;
013   
014  use Symfony\Component\Console\Application;
015  use Symfony\Component\Console\Command\Command;
016   
017  /**
018   * @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com>
019   */
020  class ApplicationDescription
021  {
022      const GLOBAL_NAMESPACE = '_global';
023   
024      /**
025       * @var Application
026       */
027      private $application;
028   
029      /**
030       * @var null|string
031       */
032      private $namespace;
033   
034      /**
035       * @var array
036       */
037      private $namespaces;
038   
039      /**
040       * @var Command[]
041       */
042      private $commands;
043   
044      /**
045       * @var Command[]
046       */
047      private $aliases;
048   
049      /**
050       * Constructor.
051       *
052       * @param Application $application
053       * @param string|null $namespace
054       */
055      public function __construct(Application $application, $namespace = null)
056      {
057          $this->application = $application;
058          $this->namespace = $namespace;
059      }
060   
061      /**
062       * @return array
063       */
064      public function getNamespaces()
065      {
066          if (null === $this->namespaces) {
067              $this->inspectApplication();
068          }
069   
070          return $this->namespaces;
071      }
072   
073      /**
074       * @return Command[]
075       */
076      public function getCommands()
077      {
078          if (null === $this->commands) {
079              $this->inspectApplication();
080          }
081   
082          return $this->commands;
083      }
084   
085      /**
086       * @param string $name
087       *
088       * @return Command
089       *
090       * @throws \InvalidArgumentException
091       */
092      public function getCommand($name)
093      {
094          if (!isset($this->commands[$name]) && !isset($this->aliases[$name])) {
095              throw new \InvalidArgumentException(sprintf('Command %s does not exist.', $name));
096          }
097   
098          return isset($this->commands[$name]) ? $this->commands[$name] : $this->aliases[$name];
099      }
100   
101      private function inspectApplication()
102      {
103          $this->commands = array();
104          $this->namespaces = array();
105   
106          $all = $this->application->all($this->namespace ? $this->application->findNamespace($this->namespace) : null);
107          foreach ($this->sortCommands($all) as $namespace => $commands) {
108              $names = array();
109   
110              /** @var Command $command */
111              foreach ($commands as $name => $command) {
112                  if (!$command->getName()) {
113                      continue;
114                  }
115   
116                  if ($command->getName() === $name) {
117                      $this->commands[$name] = $command;
118                  } else {
119                      $this->aliases[$name] = $command;
120                  }
121   
122                  $names[] = $name;
123              }
124   
125              $this->namespaces[$namespace] = array('id' => $namespace, 'commands' => $names);
126          }
127      }
128   
129      /**
130       * @param array $commands
131       *
132       * @return array
133       */
134      private function sortCommands(array $commands)
135      {
136          $namespacedCommands = array();
137          foreach ($commands as $name => $command) {
138              $key = $this->application->extractNamespace($name, 1);
139              if (!$key) {
140                  $key = '_global';
141              }
142   
143              $namespacedCommands[$key][$name] = $command;
144          }
145          ksort($namespacedCommands);
146   
147          foreach ($namespacedCommands as &$commands) {
148              ksort($commands);
149          }
150   
151          return $namespacedCommands;
152      }
153  }
154