@@ -48,15 +48,15 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | public function process(string $controller, string $action, array $parameters, CoreInterface $core) |
| 50 | 50 | { |
| 51 | - foreach ($this->getDeclaredFilters($controller, $action) as $parameter => $filterClass) { |
|
| 52 | - if (isset($parameters[$parameter])) { |
|
| 51 | + foreach ($this->getDeclaredFilters($controller, $action) as $parameter => $filterClass){ |
|
| 52 | + if (isset($parameters[$parameter])){ |
|
| 53 | 53 | continue; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** @var FilterInterface $filter */ |
| 57 | 57 | $filter = $this->container->get($filterClass); |
| 58 | 58 | |
| 59 | - if (!$filter->isValid()) { |
|
| 59 | + if (!$filter->isValid()){ |
|
| 60 | 60 | return $this->renderInvalid($filter); |
| 61 | 61 | } |
| 62 | 62 | |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | private function renderInvalid(FilterInterface $filter) |
| 74 | 74 | { |
| 75 | - switch ($this->strategy) { |
|
| 75 | + switch ($this->strategy){ |
|
| 76 | 76 | case self::STRATEGY_JSON_RESPONSE: |
| 77 | 77 | return [ |
| 78 | 78 | 'status' => 400, |
@@ -91,23 +91,23 @@ discard block |
||
| 91 | 91 | private function getDeclaredFilters(string $controller, string $action): array |
| 92 | 92 | { |
| 93 | 93 | $key = sprintf("%s:%s", $controller, $action); |
| 94 | - if (array_key_exists($key, $this->filterCache)) { |
|
| 94 | + if (array_key_exists($key, $this->filterCache)){ |
|
| 95 | 95 | return $this->filterCache[$key]; |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | $this->filterCache[$key] = []; |
| 99 | - try { |
|
| 99 | + try{ |
|
| 100 | 100 | $method = new \ReflectionMethod($controller, $action); |
| 101 | - } catch (\ReflectionException $e) { |
|
| 101 | + }catch (\ReflectionException $e){ |
|
| 102 | 102 | return []; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - foreach ($method->getParameters() as $parameter) { |
|
| 106 | - if ($parameter->getClass() === null) { |
|
| 105 | + foreach ($method->getParameters() as $parameter){ |
|
| 106 | + if ($parameter->getClass() === null){ |
|
| 107 | 107 | continue; |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - if ($parameter->getClass()->implementsInterface(FilterInterface::class)) { |
|
| 110 | + if ($parameter->getClass()->implementsInterface(FilterInterface::class)){ |
|
| 111 | 111 | $this->filterCache[$key][$parameter->getName()] = $parameter->getClass()->getName(); |
| 112 | 112 | } |
| 113 | 113 | } |
@@ -48,15 +48,18 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | public function process(string $controller, string $action, array $parameters, CoreInterface $core) |
| 50 | 50 | { |
| 51 | - foreach ($this->getDeclaredFilters($controller, $action) as $parameter => $filterClass) { |
|
| 52 | - if (isset($parameters[$parameter])) { |
|
| 51 | + foreach ($this->getDeclaredFilters($controller, $action) as $parameter => $filterClass) |
|
| 52 | + { |
|
| 53 | + if (isset($parameters[$parameter])) |
|
| 54 | + { |
|
| 53 | 55 | continue; |
| 54 | 56 | } |
| 55 | 57 | |
| 56 | 58 | /** @var FilterInterface $filter */ |
| 57 | 59 | $filter = $this->container->get($filterClass); |
| 58 | 60 | |
| 59 | - if (!$filter->isValid()) { |
|
| 61 | + if (!$filter->isValid()) |
|
| 62 | + { |
|
| 60 | 63 | return $this->renderInvalid($filter); |
| 61 | 64 | } |
| 62 | 65 | |
@@ -72,7 +75,8 @@ discard block |
||
| 72 | 75 | */ |
| 73 | 76 | private function renderInvalid(FilterInterface $filter) |
| 74 | 77 | { |
| 75 | - switch ($this->strategy) { |
|
| 78 | + switch ($this->strategy) |
|
| 79 | + { |
|
| 76 | 80 | case self::STRATEGY_JSON_RESPONSE: |
| 77 | 81 | return [ |
| 78 | 82 | 'status' => 400, |
@@ -91,23 +95,30 @@ discard block |
||
| 91 | 95 | private function getDeclaredFilters(string $controller, string $action): array |
| 92 | 96 | { |
| 93 | 97 | $key = sprintf("%s:%s", $controller, $action); |
| 94 | - if (array_key_exists($key, $this->filterCache)) { |
|
| 98 | + if (array_key_exists($key, $this->filterCache)) |
|
| 99 | + { |
|
| 95 | 100 | return $this->filterCache[$key]; |
| 96 | 101 | } |
| 97 | 102 | |
| 98 | 103 | $this->filterCache[$key] = []; |
| 99 | - try { |
|
| 104 | + try |
|
| 105 | + { |
|
| 100 | 106 | $method = new \ReflectionMethod($controller, $action); |
| 101 | - } catch (\ReflectionException $e) { |
|
| 107 | + } |
|
| 108 | + catch (\ReflectionException $e) |
|
| 109 | + { |
|
| 102 | 110 | return []; |
| 103 | 111 | } |
| 104 | 112 | |
| 105 | - foreach ($method->getParameters() as $parameter) { |
|
| 106 | - if ($parameter->getClass() === null) { |
|
| 113 | + foreach ($method->getParameters() as $parameter) |
|
| 114 | + { |
|
| 115 | + if ($parameter->getClass() === null) |
|
| 116 | + { |
|
| 107 | 117 | continue; |
| 108 | 118 | } |
| 109 | 119 | |
| 110 | - if ($parameter->getClass()->implementsInterface(FilterInterface::class)) { |
|
| 120 | + if ($parameter->getClass()->implementsInterface(FilterInterface::class)) |
|
| 121 | + { |
|
| 111 | 122 | $this->filterCache[$key][$parameter->getName()] = $parameter->getClass()->getName(); |
| 112 | 123 | } |
| 113 | 124 | } |