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

ApplicationDescription.php

Zuletzt modifiziert: 09.10.2024, 12:56 - Dateigröße: 3.75 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      /**
 028       * @var Application
 029       */
 030      private $application;
 031   
 032      /**
 033       * @var null|string
 034       */
 035      private $namespace;
 036   
 037      /**
 038       * @var array
 039       */
 040      private $namespaces;
 041   
 042      /**
 043       * @var Command[]
 044       */
 045      private $commands;
 046   
 047      /**
 048       * @var Command[]
 049       */
 050      private $aliases;
 051   
 052      /**
 053       * Constructor.
 054       *
 055       * @param Application $application
 056       * @param string|null $namespace
 057       */
 058      public function __construct(Application $application, $namespace = null)
 059      {
 060          $this->application = $application;
 061          $this->namespace = $namespace;
 062      }
 063   
 064      /**
 065       * @return array
 066       */
 067      public function getNamespaces()
 068      {
 069          if (null === $this->namespaces) {
 070              $this->inspectApplication();
 071          }
 072   
 073          return $this->namespaces;
 074      }
 075   
 076      /**
 077       * @return Command[]
 078       */
 079      public function getCommands()
 080      {
 081          if (null === $this->commands) {
 082              $this->inspectApplication();
 083          }
 084   
 085          return $this->commands;
 086      }
 087   
 088      /**
 089       * @param string $name
 090       *
 091       * @return Command
 092       *
 093       * @throws CommandNotFoundException
 094       */
 095      public function getCommand($name)
 096      {
 097          if (!isset($this->commands[$name]) && !isset($this->aliases[$name])) {
 098              throw new CommandNotFoundException(sprintf('Command %s does not exist.', $name));
 099          }
 100   
 101          return isset($this->commands[$name]) ? $this->commands[$name] : $this->aliases[$name];
 102      }
 103   
 104      private function inspectApplication()
 105      {
 106          $this->commands = array();
 107          $this->namespaces = array();
 108   
 109          $all = $this->application->all($this->namespace ? $this->application->findNamespace($this->namespace) : null);
 110          foreach ($this->sortCommands($all) as $namespace => $commands) {
 111              $names = array();
 112   
 113              /** @var Command $command */
 114              foreach ($commands as $name => $command) {
 115                  if (!$command->getName()) {
 116                      continue;
 117                  }
 118   
 119                  if ($command->getName() === $name) {
 120                      $this->commands[$name] = $command;
 121                  } else {
 122                      $this->aliases[$name] = $command;
 123                  }
 124   
 125                  $names[] = $name;
 126              }
 127   
 128              $this->namespaces[$namespace] = array('id' => $namespace, 'commands' => $names);
 129          }
 130      }
 131   
 132      /**
 133       * @param array $commands
 134       *
 135       * @return array
 136       */
 137      private function sortCommands(array $commands)
 138      {
 139          $namespacedCommands = array();
 140          $globalCommands = array();
 141          foreach ($commands as $name => $command) {
 142              $key = $this->application->extractNamespace($name, 1);
 143              if (!$key) {
 144                  $globalCommands['_global'][$name] = $command;
 145              } else {
 146                  $namespacedCommands[$key][$name] = $command;
 147              }
 148          }
 149          ksort($namespacedCommands);
 150          $namespacedCommands = array_merge($globalCommands, $namespacedCommands);
 151   
 152          foreach ($namespacedCommands as &$commandsSet) {
 153              ksort($commandsSet);
 154          }
 155          // unset reference to keep scope clear
 156          unset($commandsSet);
 157   
 158          return $namespacedCommands;
 159      }
 160  }
 161