1 | <?php |
||
19 | class DataCollector extends BaseDataCollector implements EventSubscriberInterface |
||
20 | { |
||
21 | const COLLECTOR_NAME = 'spiechu_symfony_commons.data_collector'; |
||
22 | |||
23 | /** |
||
24 | * @var RouterInterface |
||
25 | */ |
||
26 | protected $router; |
||
27 | |||
28 | /** |
||
29 | * @var Reader |
||
30 | */ |
||
31 | protected $reader; |
||
32 | |||
33 | /** |
||
34 | * @var Container |
||
35 | */ |
||
36 | protected $container; |
||
37 | |||
38 | 1 | public function __construct(RouterInterface $router, Reader $reader, Container $container) |
|
39 | { |
||
40 | 1 | $this->router = $router; |
|
41 | 1 | $this->reader = $reader; |
|
42 | 1 | $this->container = $container; |
|
43 | 1 | } |
|
44 | |||
45 | /** |
||
46 | * {@inheritdoc} |
||
47 | */ |
||
48 | 1 | public function collect(Request $request, Response $response, \Exception $exception = null): void |
|
49 | { |
||
50 | 1 | $this->data['known_response_schemas'] = $request->attributes->has(RequestSchemaValidatorListener::ATTRIBUTE_RESPONSE_SCHEMAS) |
|
51 | 1 | ? $request->attributes->get(RequestSchemaValidatorListener::ATTRIBUTE_RESPONSE_SCHEMAS) |
|
52 | : null; |
||
53 | |||
54 | 1 | $this->extractRoutesData(); |
|
55 | 1 | } |
|
56 | |||
57 | /** |
||
58 | * {@inheritdoc} |
||
59 | */ |
||
60 | 1 | public function getName(): string |
|
61 | { |
||
62 | 1 | return static::COLLECTOR_NAME; |
|
63 | } |
||
64 | |||
65 | public function getGlobalResponseSchemas(): array |
||
69 | |||
70 | /** |
||
71 | * {@inheritdoc} |
||
72 | */ |
||
73 | 2 | public static function getSubscribedEvents(): array |
|
79 | |||
80 | 1 | public function onCheckResult(CheckResult $checkResult): void |
|
81 | { |
||
82 | 1 | $this->data['validation_result'] = $checkResult->getValidationResult(); |
|
83 | 1 | } |
|
84 | |||
85 | public function getKnownResponseSchemas(): array |
||
89 | |||
90 | public function getKnownResponseSchemaNumber(): int |
||
100 | |||
101 | 1 | public function responseWasChecked(): bool |
|
102 | { |
||
103 | 1 | return array_key_exists('validation_result', $this->data); |
|
104 | } |
||
105 | |||
106 | /** |
||
107 | * @return ValidationViolation[] |
||
108 | */ |
||
109 | public function getValidationErrors(): array |
||
117 | |||
118 | 1 | protected function extractRoutesData(): void |
|
119 | { |
||
120 | 1 | $this->data['global_response_schemas'] = []; |
|
121 | |||
122 | 1 | foreach ($this->router->getRouteCollection() as $name => $route) { |
|
143 | |||
144 | 1 | protected function extractControllerResponseValidator(string $controllerDefinition): ?ResponseSchemaValidator |
|
156 | } |
||
157 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.