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

ApplicationDescription.php

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