[ Index ] |
PHP Cross Reference of phpBB-3.2.11-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* 4 * This file is part of the Symfony package. 5 * 6 * (c) Fabien Potencier <fabien@symfony.com> 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12 namespace Symfony\Component\Console\Descriptor; 13 14 use Symfony\Component\Console\Application; 15 use Symfony\Component\Console\Command\Command; 16 use Symfony\Component\Console\Exception\CommandNotFoundException; 17 18 /** 19 * @author Jean-François Simon <jeanfrancois.simon@sensiolabs.com> 20 * 21 * @internal 22 */ 23 class ApplicationDescription 24 { 25 const GLOBAL_NAMESPACE = '_global'; 26 27 private $application; 28 private $namespace; 29 30 /** 31 * @var array 32 */ 33 private $namespaces; 34 35 /** 36 * @var Command[] 37 */ 38 private $commands; 39 40 /** 41 * @var Command[] 42 */ 43 private $aliases; 44 45 public function __construct(Application $application, $namespace = null) 46 { 47 $this->application = $application; 48 $this->namespace = $namespace; 49 } 50 51 /** 52 * @return array 53 */ 54 public function getNamespaces() 55 { 56 if (null === $this->namespaces) { 57 $this->inspectApplication(); 58 } 59 60 return $this->namespaces; 61 } 62 63 /** 64 * @return Command[] 65 */ 66 public function getCommands() 67 { 68 if (null === $this->commands) { 69 $this->inspectApplication(); 70 } 71 72 return $this->commands; 73 } 74 75 /** 76 * @param string $name 77 * 78 * @return Command 79 * 80 * @throws CommandNotFoundException 81 */ 82 public function getCommand($name) 83 { 84 if (!isset($this->commands[$name]) && !isset($this->aliases[$name])) { 85 throw new CommandNotFoundException(sprintf('Command %s does not exist.', $name)); 86 } 87 88 return isset($this->commands[$name]) ? $this->commands[$name] : $this->aliases[$name]; 89 } 90 91 private function inspectApplication() 92 { 93 $this->commands = array(); 94 $this->namespaces = array(); 95 96 $all = $this->application->all($this->namespace ? $this->application->findNamespace($this->namespace) : null); 97 foreach ($this->sortCommands($all) as $namespace => $commands) { 98 $names = array(); 99 100 /** @var Command $command */ 101 foreach ($commands as $name => $command) { 102 if (!$command->getName()) { 103 continue; 104 } 105 106 if ($command->getName() === $name) { 107 $this->commands[$name] = $command; 108 } else { 109 $this->aliases[$name] = $command; 110 } 111 112 $names[] = $name; 113 } 114 115 $this->namespaces[$namespace] = array('id' => $namespace, 'commands' => $names); 116 } 117 } 118 119 /** 120 * @return array 121 */ 122 private function sortCommands(array $commands) 123 { 124 $namespacedCommands = array(); 125 $globalCommands = array(); 126 foreach ($commands as $name => $command) { 127 $key = $this->application->extractNamespace($name, 1); 128 if (!$key) { 129 $globalCommands['_global'][$name] = $command; 130 } else { 131 $namespacedCommands[$key][$name] = $command; 132 } 133 } 134 ksort($namespacedCommands); 135 $namespacedCommands = array_merge($globalCommands, $namespacedCommands); 136 137 foreach ($namespacedCommands as &$commandsSet) { 138 ksort($commandsSet); 139 } 140 // unset reference to keep scope clear 141 unset($commandsSet); 142 143 return $namespacedCommands; 144 } 145 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |