@@ -50,20 +50,24 @@ discard block |
||
| 50 | 50 | */ |
| 51 | 51 | public function process(string $controller, string $action, array $parameters, CoreInterface $core) |
| 52 | 52 | { |
| 53 | - foreach ($this->getDeclaredFilters($controller, $action) as $parameter => $filterClass) { |
|
| 54 | - if (isset($parameters[$parameter])) { |
|
| 53 | + foreach ($this->getDeclaredFilters($controller, $action) as $parameter => $filterClass) |
|
| 54 | + { |
|
| 55 | + if (isset($parameters[$parameter])) |
|
| 56 | + { |
|
| 55 | 57 | continue; |
| 56 | 58 | } |
| 57 | 59 | |
| 58 | 60 | /** @var FilterInterface $filter */ |
| 59 | 61 | $filter = $this->container->get($filterClass); |
| 60 | 62 | |
| 61 | - if (isset($parameters['@context'])) { |
|
| 63 | + if (isset($parameters['@context'])) |
|
| 64 | + { |
|
| 62 | 65 | // other interceptors can define the validation contex |
| 63 | 66 | $filter->setContext($parameters['@context']); |
| 64 | 67 | } |
| 65 | 68 | |
| 66 | - if (!$filter->isValid()) { |
|
| 69 | + if (!$filter->isValid()) |
|
| 70 | + { |
|
| 67 | 71 | return $this->renderInvalid($filter); |
| 68 | 72 | } |
| 69 | 73 | |
@@ -81,11 +85,13 @@ discard block |
||
| 81 | 85 | */ |
| 82 | 86 | protected function renderInvalid(FilterInterface $filter) |
| 83 | 87 | { |
| 84 | - if ($filter instanceof ShouldRenderErrors) { |
|
| 88 | + if ($filter instanceof ShouldRenderErrors) |
|
| 89 | + { |
|
| 85 | 90 | return $filter->render(); |
| 86 | 91 | } |
| 87 | 92 | |
| 88 | - switch ($this->strategy) { |
|
| 93 | + switch ($this->strategy) |
|
| 94 | + { |
|
| 89 | 95 | case self::STRATEGY_JSON_RESPONSE: |
| 90 | 96 | return [ |
| 91 | 97 | 'status' => 400, |
@@ -104,25 +110,32 @@ discard block |
||
| 104 | 110 | private function getDeclaredFilters(string $controller, string $action): array |
| 105 | 111 | { |
| 106 | 112 | $key = sprintf('%s:%s', $controller, $action); |
| 107 | - if (array_key_exists($key, $this->cache)) { |
|
| 113 | + if (array_key_exists($key, $this->cache)) |
|
| 114 | + { |
|
| 108 | 115 | return $this->cache[$key]; |
| 109 | 116 | } |
| 110 | 117 | |
| 111 | 118 | $this->cache[$key] = []; |
| 112 | - try { |
|
| 119 | + try |
|
| 120 | + { |
|
| 113 | 121 | $method = new \ReflectionMethod($controller, $action); |
| 114 | - } catch (\ReflectionException $e) { |
|
| 122 | + } |
|
| 123 | + catch (\ReflectionException $e) |
|
| 124 | + { |
|
| 115 | 125 | return []; |
| 116 | 126 | } |
| 117 | 127 | |
| 118 | - foreach ($method->getParameters() as $parameter) { |
|
| 128 | + foreach ($method->getParameters() as $parameter) |
|
| 129 | + { |
|
| 119 | 130 | $class = $this->getParameterClass($parameter); |
| 120 | 131 | |
| 121 | - if ($class === null) { |
|
| 132 | + if ($class === null) |
|
| 133 | + { |
|
| 122 | 134 | continue; |
| 123 | 135 | } |
| 124 | 136 | |
| 125 | - if ($class->implementsInterface(FilterInterface::class)) { |
|
| 137 | + if ($class->implementsInterface(FilterInterface::class)) |
|
| 138 | + { |
|
| 126 | 139 | $this->cache[$key][$parameter->getName()] = $class->getName(); |
| 127 | 140 | } |
| 128 | 141 | } |
@@ -140,11 +153,13 @@ discard block |
||
| 140 | 153 | { |
| 141 | 154 | $type = $parameter->getType(); |
| 142 | 155 | |
| 143 | - if (!$type instanceof \ReflectionNamedType) { |
|
| 156 | + if (!$type instanceof \ReflectionNamedType) |
|
| 157 | + { |
|
| 144 | 158 | return null; |
| 145 | 159 | } |
| 146 | 160 | |
| 147 | - if ($type->isBuiltin()) { |
|
| 161 | + if ($type->isBuiltin()) |
|
| 162 | + { |
|
| 148 | 163 | return null; |
| 149 | 164 | } |
| 150 | 165 | |