@@ -49,20 +49,20 @@ discard block |
||
| 49 | 49 | */ |
| 50 | 50 | public function process(string $controller, string $action, array $parameters, CoreInterface $core) |
| 51 | 51 | { |
| 52 | - foreach ($this->getDeclaredFilters($controller, $action) as $parameter => $filterClass) { |
|
| 53 | - if (isset($parameters[$parameter])) { |
|
| 52 | + foreach ($this->getDeclaredFilters($controller, $action) as $parameter => $filterClass){ |
|
| 53 | + if (isset($parameters[$parameter])){ |
|
| 54 | 54 | continue; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** @var FilterInterface $filter */ |
| 58 | 58 | $filter = $this->container->get($filterClass); |
| 59 | 59 | |
| 60 | - if (isset($parameters['@context'])) { |
|
| 60 | + if (isset($parameters['@context'])){ |
|
| 61 | 61 | // other interceptors can define the validation contex |
| 62 | 62 | $filter->setContext($parameters['@context']); |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - if (!$filter->isValid()) { |
|
| 65 | + if (!$filter->isValid()){ |
|
| 66 | 66 | return $this->renderInvalid($filter); |
| 67 | 67 | } |
| 68 | 68 | |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | */ |
| 81 | 81 | protected function renderInvalid(FilterInterface $filter) |
| 82 | 82 | { |
| 83 | - switch ($this->strategy) { |
|
| 83 | + switch ($this->strategy){ |
|
| 84 | 84 | case self::STRATEGY_JSON_RESPONSE: |
| 85 | 85 | return [ |
| 86 | 86 | 'status' => 400, |
@@ -99,23 +99,23 @@ discard block |
||
| 99 | 99 | private function getDeclaredFilters(string $controller, string $action): array |
| 100 | 100 | { |
| 101 | 101 | $key = sprintf('%s:%s', $controller, $action); |
| 102 | - if (array_key_exists($key, $this->cache)) { |
|
| 102 | + if (array_key_exists($key, $this->cache)){ |
|
| 103 | 103 | return $this->cache[$key]; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | $this->cache[$key] = []; |
| 107 | - try { |
|
| 107 | + try{ |
|
| 108 | 108 | $method = new \ReflectionMethod($controller, $action); |
| 109 | - } catch (\ReflectionException $e) { |
|
| 109 | + }catch (\ReflectionException $e){ |
|
| 110 | 110 | return []; |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - foreach ($method->getParameters() as $parameter) { |
|
| 114 | - if ($parameter->getClass() === null) { |
|
| 113 | + foreach ($method->getParameters() as $parameter){ |
|
| 114 | + if ($parameter->getClass() === null){ |
|
| 115 | 115 | continue; |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - if ($parameter->getClass()->implementsInterface(FilterInterface::class)) { |
|
| 118 | + if ($parameter->getClass()->implementsInterface(FilterInterface::class)){ |
|
| 119 | 119 | $this->cache[$key][$parameter->getName()] = $parameter->getClass()->getName(); |
| 120 | 120 | } |
| 121 | 121 | } |
@@ -46,17 +46,17 @@ discard block |
||
| 46 | 46 | $entities = $this->getDeclaredEntities($controller, $action); |
| 47 | 47 | |
| 48 | 48 | $contextCandidates = []; |
| 49 | - foreach ($entities as $parameter => $role) { |
|
| 49 | + foreach ($entities as $parameter => $role){ |
|
| 50 | 50 | $value = $this->getParameter($parameter, $parameters, count($entities) === 1); |
| 51 | - if ($value === null) { |
|
| 51 | + if ($value === null){ |
|
| 52 | 52 | throw new ControllerException( |
| 53 | 53 | "Entity `{$parameter}` can not be found", |
| 54 | 54 | ControllerException::NOT_FOUND |
| 55 | 55 | ); |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - if (is_object($value)) { |
|
| 59 | - if ($this->orm->getHeap()->has($value)) { |
|
| 58 | + if (is_object($value)){ |
|
| 59 | + if ($this->orm->getHeap()->has($value)){ |
|
| 60 | 60 | $contextCandidates[] = $value; |
| 61 | 61 | } |
| 62 | 62 | |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | $entity = $this->resolveEntity($role, $value); |
| 68 | - if ($entity === null) { |
|
| 68 | + if ($entity === null){ |
|
| 69 | 69 | throw new ControllerException( |
| 70 | 70 | "Entity `{$parameter}` can not be found", |
| 71 | 71 | ControllerException::NOT_FOUND |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | $contextCandidates[] = $value; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - if (!isset($parameters['@context']) && count($contextCandidates) === 1) { |
|
| 79 | + if (!isset($parameters['@context']) && count($contextCandidates) === 1){ |
|
| 80 | 80 | $parameters['@context'] = current($contextCandidates); |
| 81 | 81 | } |
| 82 | 82 | |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | */ |
| 92 | 92 | protected function getParameter(string $role, array $parameters, bool $useDefault = false) |
| 93 | 93 | { |
| 94 | - if (!$useDefault) { |
|
| 94 | + if (!$useDefault){ |
|
| 95 | 95 | return $parameters[$role] ?? null; |
| 96 | 96 | } |
| 97 | 97 | |
@@ -116,23 +116,23 @@ discard block |
||
| 116 | 116 | private function getDeclaredEntities(string $controller, string $action): array |
| 117 | 117 | { |
| 118 | 118 | $key = sprintf('%s:%s', $controller, $action); |
| 119 | - if (array_key_exists($key, $this->cache)) { |
|
| 119 | + if (array_key_exists($key, $this->cache)){ |
|
| 120 | 120 | return $this->cache[$key]; |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | $this->cache[$key] = []; |
| 124 | - try { |
|
| 124 | + try{ |
|
| 125 | 125 | $method = new \ReflectionMethod($controller, $action); |
| 126 | - } catch (\ReflectionException $e) { |
|
| 126 | + }catch (\ReflectionException $e){ |
|
| 127 | 127 | return []; |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - foreach ($method->getParameters() as $parameter) { |
|
| 131 | - if ($parameter->getClass() === null) { |
|
| 130 | + foreach ($method->getParameters() as $parameter){ |
|
| 131 | + if ($parameter->getClass() === null){ |
|
| 132 | 132 | continue; |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | - if ($this->orm->getSchema()->defines($parameter->getClass()->getName())) { |
|
| 135 | + if ($this->orm->getSchema()->defines($parameter->getClass()->getName())){ |
|
| 136 | 136 | $this->cache[$key][$parameter->getName()] = $this->orm->resolveRole($parameter->getClass()->getName()); |
| 137 | 137 | } |
| 138 | 138 | } |