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/DataCollector | |
parent | 94d67a4b51f8e62e7d518cce26a526ae1ec48278 (diff) | |
download | AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.zip |
VERSION 0.2 doctrine ORM et entités
Diffstat (limited to 'vendor/symfony/console/DataCollector')
-rw-r--r-- | vendor/symfony/console/DataCollector/CommandDataCollector.php | 234 |
1 files changed, 234 insertions, 0 deletions
diff --git a/vendor/symfony/console/DataCollector/CommandDataCollector.php b/vendor/symfony/console/DataCollector/CommandDataCollector.php new file mode 100644 index 0000000..45138c7 --- /dev/null +++ b/vendor/symfony/console/DataCollector/CommandDataCollector.php | |||
@@ -0,0 +1,234 @@ | |||
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\DataCollector; | ||
13 | |||
14 | use Symfony\Component\Console\Command\Command; | ||
15 | use Symfony\Component\Console\Debug\CliRequest; | ||
16 | use Symfony\Component\Console\Output\OutputInterface; | ||
17 | use Symfony\Component\Console\SignalRegistry\SignalMap; | ||
18 | use Symfony\Component\HttpFoundation\Request; | ||
19 | use Symfony\Component\HttpFoundation\Response; | ||
20 | use Symfony\Component\HttpKernel\DataCollector\DataCollector; | ||
21 | use Symfony\Component\VarDumper\Cloner\Data; | ||
22 | |||
23 | /** | ||
24 | * @internal | ||
25 | * | ||
26 | * @author Jules Pietri <jules@heahprod.com> | ||
27 | */ | ||
28 | final class CommandDataCollector extends DataCollector | ||
29 | { | ||
30 | public function collect(Request $request, Response $response, ?\Throwable $exception = null): void | ||
31 | { | ||
32 | if (!$request instanceof CliRequest) { | ||
33 | return; | ||
34 | } | ||
35 | |||
36 | $command = $request->command; | ||
37 | $application = $command->getApplication(); | ||
38 | |||
39 | $this->data = [ | ||
40 | 'command' => $this->cloneVar($command->command), | ||
41 | 'exit_code' => $command->exitCode, | ||
42 | 'interrupted_by_signal' => $command->interruptedBySignal, | ||
43 | 'duration' => $command->duration, | ||
44 | 'max_memory_usage' => $command->maxMemoryUsage, | ||
45 | 'verbosity_level' => match ($command->output->getVerbosity()) { | ||
46 | OutputInterface::VERBOSITY_QUIET => 'quiet', | ||
47 | OutputInterface::VERBOSITY_NORMAL => 'normal', | ||
48 | OutputInterface::VERBOSITY_VERBOSE => 'verbose', | ||
49 | OutputInterface::VERBOSITY_VERY_VERBOSE => 'very verbose', | ||
50 | OutputInterface::VERBOSITY_DEBUG => 'debug', | ||
51 | }, | ||
52 | 'interactive' => $command->isInteractive, | ||
53 | 'validate_input' => !$command->ignoreValidation, | ||
54 | 'enabled' => $command->isEnabled(), | ||
55 | 'visible' => !$command->isHidden(), | ||
56 | 'input' => $this->cloneVar($command->input), | ||
57 | 'output' => $this->cloneVar($command->output), | ||
58 | 'interactive_inputs' => array_map($this->cloneVar(...), $command->interactiveInputs), | ||
59 | 'signalable' => $command->getSubscribedSignals(), | ||
60 | 'handled_signals' => $command->handledSignals, | ||
61 | 'helper_set' => array_map($this->cloneVar(...), iterator_to_array($command->getHelperSet())), | ||
62 | ]; | ||
63 | |||
64 | $baseDefinition = $application->getDefinition(); | ||
65 | |||
66 | foreach ($command->arguments as $argName => $argValue) { | ||
67 | if ($baseDefinition->hasArgument($argName)) { | ||
68 | $this->data['application_inputs'][$argName] = $this->cloneVar($argValue); | ||
69 | } else { | ||
70 | $this->data['arguments'][$argName] = $this->cloneVar($argValue); | ||
71 | } | ||
72 | } | ||
73 | |||
74 | foreach ($command->options as $optName => $optValue) { | ||
75 | if ($baseDefinition->hasOption($optName)) { | ||
76 | $this->data['application_inputs']['--'.$optName] = $this->cloneVar($optValue); | ||
77 | } else { | ||
78 | $this->data['options'][$optName] = $this->cloneVar($optValue); | ||
79 | } | ||
80 | } | ||
81 | } | ||
82 | |||
83 | public function getName(): string | ||
84 | { | ||
85 | return 'command'; | ||
86 | } | ||
87 | |||
88 | /** | ||
89 | * @return array{ | ||
90 | * class?: class-string, | ||
91 | * executor?: string, | ||
92 | * file: string, | ||
93 | * line: int, | ||
94 | * } | ||
95 | */ | ||
96 | public function getCommand(): array | ||
97 | { | ||
98 | $class = $this->data['command']->getType(); | ||
99 | $r = new \ReflectionMethod($class, 'execute'); | ||
100 | |||
101 | if (Command::class !== $r->getDeclaringClass()) { | ||
102 | return [ | ||
103 | 'executor' => $class.'::'.$r->name, | ||
104 | 'file' => $r->getFileName(), | ||
105 | 'line' => $r->getStartLine(), | ||
106 | ]; | ||
107 | } | ||
108 | |||
109 | $r = new \ReflectionClass($class); | ||
110 | |||
111 | return [ | ||
112 | 'class' => $class, | ||
113 | 'file' => $r->getFileName(), | ||
114 | 'line' => $r->getStartLine(), | ||
115 | ]; | ||
116 | } | ||
117 | |||
118 | public function getInterruptedBySignal(): ?string | ||
119 | { | ||
120 | if (isset($this->data['interrupted_by_signal'])) { | ||
121 | return sprintf('%s (%d)', SignalMap::getSignalName($this->data['interrupted_by_signal']), $this->data['interrupted_by_signal']); | ||
122 | } | ||
123 | |||
124 | return null; | ||
125 | } | ||
126 | |||
127 | public function getDuration(): string | ||
128 | { | ||
129 | return $this->data['duration']; | ||
130 | } | ||
131 | |||
132 | public function getMaxMemoryUsage(): string | ||
133 | { | ||
134 | return $this->data['max_memory_usage']; | ||
135 | } | ||
136 | |||
137 | public function getVerbosityLevel(): string | ||
138 | { | ||
139 | return $this->data['verbosity_level']; | ||
140 | } | ||
141 | |||
142 | public function getInteractive(): bool | ||
143 | { | ||
144 | return $this->data['interactive']; | ||
145 | } | ||
146 | |||
147 | public function getValidateInput(): bool | ||
148 | { | ||
149 | return $this->data['validate_input']; | ||
150 | } | ||
151 | |||
152 | public function getEnabled(): bool | ||
153 | { | ||
154 | return $this->data['enabled']; | ||
155 | } | ||
156 | |||
157 | public function getVisible(): bool | ||
158 | { | ||
159 | return $this->data['visible']; | ||
160 | } | ||
161 | |||
162 | public function getInput(): Data | ||
163 | { | ||
164 | return $this->data['input']; | ||
165 | } | ||
166 | |||
167 | public function getOutput(): Data | ||
168 | { | ||
169 | return $this->data['output']; | ||
170 | } | ||
171 | |||
172 | /** | ||
173 | * @return Data[] | ||
174 | */ | ||
175 | public function getArguments(): array | ||
176 | { | ||
177 | return $this->data['arguments'] ?? []; | ||
178 | } | ||
179 | |||
180 | /** | ||
181 | * @return Data[] | ||
182 | */ | ||
183 | public function getOptions(): array | ||
184 | { | ||
185 | return $this->data['options'] ?? []; | ||
186 | } | ||
187 | |||
188 | /** | ||
189 | * @return Data[] | ||
190 | */ | ||
191 | public function getApplicationInputs(): array | ||
192 | { | ||
193 | return $this->data['application_inputs'] ?? []; | ||
194 | } | ||
195 | |||
196 | /** | ||
197 | * @return Data[] | ||
198 | */ | ||
199 | public function getInteractiveInputs(): array | ||
200 | { | ||
201 | return $this->data['interactive_inputs'] ?? []; | ||
202 | } | ||
203 | |||
204 | public function getSignalable(): array | ||
205 | { | ||
206 | return array_map( | ||
207 | static fn (int $signal): string => sprintf('%s (%d)', SignalMap::getSignalName($signal), $signal), | ||
208 | $this->data['signalable'] | ||
209 | ); | ||
210 | } | ||
211 | |||
212 | public function getHandledSignals(): array | ||
213 | { | ||
214 | $keys = array_map( | ||
215 | static fn (int $signal): string => sprintf('%s (%d)', SignalMap::getSignalName($signal), $signal), | ||
216 | array_keys($this->data['handled_signals']) | ||
217 | ); | ||
218 | |||
219 | return array_combine($keys, array_values($this->data['handled_signals'])); | ||
220 | } | ||
221 | |||
222 | /** | ||
223 | * @return Data[] | ||
224 | */ | ||
225 | public function getHelperSet(): array | ||
226 | { | ||
227 | return $this->data['helper_set'] ?? []; | ||
228 | } | ||
229 | |||
230 | public function reset(): void | ||
231 | { | ||
232 | $this->data = []; | ||
233 | } | ||
234 | } | ||