diff options
author | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
---|---|---|
committer | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
commit | bf6655a534a6775d30cafa67bd801276bda1d98d (patch) | |
tree | c6381e3f6c81c33eab72508f410b165ba05f7e9c /vendor/symfony/console/Descriptor/ApplicationDescription.php | |
parent | 94d67a4b51f8e62e7d518cce26a526ae1ec48278 (diff) | |
download | AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.zip |
VERSION 0.2 doctrine ORM et entités
Diffstat (limited to 'vendor/symfony/console/Descriptor/ApplicationDescription.php')
-rw-r--r-- | vendor/symfony/console/Descriptor/ApplicationDescription.php | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/vendor/symfony/console/Descriptor/ApplicationDescription.php b/vendor/symfony/console/Descriptor/ApplicationDescription.php new file mode 100644 index 0000000..5149fde --- /dev/null +++ b/vendor/symfony/console/Descriptor/ApplicationDescription.php | |||
@@ -0,0 +1,136 @@ | |||
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 | public const GLOBAL_NAMESPACE = '_global'; | ||
26 | |||
27 | private array $namespaces; | ||
28 | |||
29 | /** | ||
30 | * @var array<string, Command> | ||
31 | */ | ||
32 | private array $commands; | ||
33 | |||
34 | /** | ||
35 | * @var array<string, Command> | ||
36 | */ | ||
37 | private array $aliases = []; | ||
38 | |||
39 | public function __construct( | ||
40 | private Application $application, | ||
41 | private ?string $namespace = null, | ||
42 | private bool $showHidden = false, | ||
43 | ) { | ||
44 | } | ||
45 | |||
46 | public function getNamespaces(): array | ||
47 | { | ||
48 | if (!isset($this->namespaces)) { | ||
49 | $this->inspectApplication(); | ||
50 | } | ||
51 | |||
52 | return $this->namespaces; | ||
53 | } | ||
54 | |||
55 | /** | ||
56 | * @return Command[] | ||
57 | */ | ||
58 | public function getCommands(): array | ||
59 | { | ||
60 | if (!isset($this->commands)) { | ||
61 | $this->inspectApplication(); | ||
62 | } | ||
63 | |||
64 | return $this->commands; | ||
65 | } | ||
66 | |||
67 | /** | ||
68 | * @throws CommandNotFoundException | ||
69 | */ | ||
70 | public function getCommand(string $name): Command | ||
71 | { | ||
72 | if (!isset($this->commands[$name]) && !isset($this->aliases[$name])) { | ||
73 | throw new CommandNotFoundException(sprintf('Command "%s" does not exist.', $name)); | ||
74 | } | ||
75 | |||
76 | return $this->commands[$name] ?? $this->aliases[$name]; | ||
77 | } | ||
78 | |||
79 | private function inspectApplication(): void | ||
80 | { | ||
81 | $this->commands = []; | ||
82 | $this->namespaces = []; | ||
83 | |||
84 | $all = $this->application->all($this->namespace ? $this->application->findNamespace($this->namespace) : null); | ||
85 | foreach ($this->sortCommands($all) as $namespace => $commands) { | ||
86 | $names = []; | ||
87 | |||
88 | /** @var Command $command */ | ||
89 | foreach ($commands as $name => $command) { | ||
90 | if (!$command->getName() || (!$this->showHidden && $command->isHidden())) { | ||
91 | continue; | ||
92 | } | ||
93 | |||
94 | if ($command->getName() === $name) { | ||
95 | $this->commands[$name] = $command; | ||
96 | } else { | ||
97 | $this->aliases[$name] = $command; | ||
98 | } | ||
99 | |||
100 | $names[] = $name; | ||
101 | } | ||
102 | |||
103 | $this->namespaces[$namespace] = ['id' => $namespace, 'commands' => $names]; | ||
104 | } | ||
105 | } | ||
106 | |||
107 | private function sortCommands(array $commands): array | ||
108 | { | ||
109 | $namespacedCommands = []; | ||
110 | $globalCommands = []; | ||
111 | $sortedCommands = []; | ||
112 | foreach ($commands as $name => $command) { | ||
113 | $key = $this->application->extractNamespace($name, 1); | ||
114 | if (\in_array($key, ['', self::GLOBAL_NAMESPACE], true)) { | ||
115 | $globalCommands[$name] = $command; | ||
116 | } else { | ||
117 | $namespacedCommands[$key][$name] = $command; | ||
118 | } | ||
119 | } | ||
120 | |||
121 | if ($globalCommands) { | ||
122 | ksort($globalCommands); | ||
123 | $sortedCommands[self::GLOBAL_NAMESPACE] = $globalCommands; | ||
124 | } | ||
125 | |||
126 | if ($namespacedCommands) { | ||
127 | ksort($namespacedCommands, \SORT_STRING); | ||
128 | foreach ($namespacedCommands as $key => $commandsSet) { | ||
129 | ksort($commandsSet); | ||
130 | $sortedCommands[$key] = $commandsSet; | ||
131 | } | ||
132 | } | ||
133 | |||
134 | return $sortedCommands; | ||
135 | } | ||
136 | } | ||