@@ -45,22 +45,22 @@ discard block |
||
| 45 | 45 | { |
| 46 | 46 | $entities = $this->getDeclaredEntities($controller, $action); |
| 47 | 47 | |
| 48 | - foreach ($entities as $parameter => $role) { |
|
| 48 | + foreach ($entities as $parameter => $role){ |
|
| 49 | 49 | $value = $this->getParameter($parameter, $parameters, count($entities) === 1); |
| 50 | - if ($value === null) { |
|
| 50 | + if ($value === null){ |
|
| 51 | 51 | throw new ControllerException( |
| 52 | 52 | "Entity `{$parameter}` can not be found", |
| 53 | 53 | ControllerException::NOT_FOUND |
| 54 | 54 | ); |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - if (is_object($value)) { |
|
| 57 | + if (is_object($value)){ |
|
| 58 | 58 | // pre-filled |
| 59 | 59 | continue; |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | $entity = $this->resolveEntity($role, $value); |
| 63 | - if ($entity === null) { |
|
| 63 | + if ($entity === null){ |
|
| 64 | 64 | throw new ControllerException( |
| 65 | 65 | "Entity `{$parameter}` can not be found", |
| 66 | 66 | ControllerException::NOT_FOUND |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | */ |
| 82 | 82 | protected function getParameter(string $role, array $parameters, bool $useDefault = false) |
| 83 | 83 | { |
| 84 | - if (!$useDefault) { |
|
| 84 | + if (!$useDefault){ |
|
| 85 | 85 | return $parameters[$role] ?? null; |
| 86 | 86 | } |
| 87 | 87 | |
@@ -106,23 +106,23 @@ discard block |
||
| 106 | 106 | private function getDeclaredEntities(string $controller, string $action): array |
| 107 | 107 | { |
| 108 | 108 | $key = sprintf('%s:%s', $controller, $action); |
| 109 | - if (array_key_exists($key, $this->cache)) { |
|
| 109 | + if (array_key_exists($key, $this->cache)){ |
|
| 110 | 110 | return $this->cache[$key]; |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | $this->cache[$key] = []; |
| 114 | - try { |
|
| 114 | + try{ |
|
| 115 | 115 | $method = new \ReflectionMethod($controller, $action); |
| 116 | - } catch (\ReflectionException $e) { |
|
| 116 | + }catch (\ReflectionException $e){ |
|
| 117 | 117 | return []; |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - foreach ($method->getParameters() as $parameter) { |
|
| 121 | - if ($parameter->getClass() === null) { |
|
| 120 | + foreach ($method->getParameters() as $parameter){ |
|
| 121 | + if ($parameter->getClass() === null){ |
|
| 122 | 122 | continue; |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - if ($this->orm->getSchema()->defines($parameter->getClass()->getName())) { |
|
| 125 | + if ($this->orm->getSchema()->defines($parameter->getClass()->getName())){ |
|
| 126 | 126 | $this->cache[$key][$parameter->getName()] = $this->orm->resolveRole($parameter->getClass()->getName()); |
| 127 | 127 | } |
| 128 | 128 | } |
@@ -45,22 +45,26 @@ discard block |
||
| 45 | 45 | { |
| 46 | 46 | $entities = $this->getDeclaredEntities($controller, $action); |
| 47 | 47 | |
| 48 | - foreach ($entities as $parameter => $role) { |
|
| 48 | + foreach ($entities as $parameter => $role) |
|
| 49 | + { |
|
| 49 | 50 | $value = $this->getParameter($parameter, $parameters, count($entities) === 1); |
| 50 | - if ($value === null) { |
|
| 51 | + if ($value === null) |
|
| 52 | + { |
|
| 51 | 53 | throw new ControllerException( |
| 52 | 54 | "Entity `{$parameter}` can not be found", |
| 53 | 55 | ControllerException::NOT_FOUND |
| 54 | 56 | ); |
| 55 | 57 | } |
| 56 | 58 | |
| 57 | - if (is_object($value)) { |
|
| 59 | + if (is_object($value)) |
|
| 60 | + { |
|
| 58 | 61 | // pre-filled |
| 59 | 62 | continue; |
| 60 | 63 | } |
| 61 | 64 | |
| 62 | 65 | $entity = $this->resolveEntity($role, $value); |
| 63 | - if ($entity === null) { |
|
| 66 | + if ($entity === null) |
|
| 67 | + { |
|
| 64 | 68 | throw new ControllerException( |
| 65 | 69 | "Entity `{$parameter}` can not be found", |
| 66 | 70 | ControllerException::NOT_FOUND |
@@ -81,7 +85,8 @@ discard block |
||
| 81 | 85 | */ |
| 82 | 86 | protected function getParameter(string $role, array $parameters, bool $useDefault = false) |
| 83 | 87 | { |
| 84 | - if (!$useDefault) { |
|
| 88 | + if (!$useDefault) |
|
| 89 | + { |
|
| 85 | 90 | return $parameters[$role] ?? null; |
| 86 | 91 | } |
| 87 | 92 | |
@@ -106,23 +111,30 @@ discard block |
||
| 106 | 111 | private function getDeclaredEntities(string $controller, string $action): array |
| 107 | 112 | { |
| 108 | 113 | $key = sprintf('%s:%s', $controller, $action); |
| 109 | - if (array_key_exists($key, $this->cache)) { |
|
| 114 | + if (array_key_exists($key, $this->cache)) |
|
| 115 | + { |
|
| 110 | 116 | return $this->cache[$key]; |
| 111 | 117 | } |
| 112 | 118 | |
| 113 | 119 | $this->cache[$key] = []; |
| 114 | - try { |
|
| 120 | + try |
|
| 121 | + { |
|
| 115 | 122 | $method = new \ReflectionMethod($controller, $action); |
| 116 | - } catch (\ReflectionException $e) { |
|
| 123 | + } |
|
| 124 | + catch (\ReflectionException $e) |
|
| 125 | + { |
|
| 117 | 126 | return []; |
| 118 | 127 | } |
| 119 | 128 | |
| 120 | - foreach ($method->getParameters() as $parameter) { |
|
| 121 | - if ($parameter->getClass() === null) { |
|
| 129 | + foreach ($method->getParameters() as $parameter) |
|
| 130 | + { |
|
| 131 | + if ($parameter->getClass() === null) |
|
| 132 | + { |
|
| 122 | 133 | continue; |
| 123 | 134 | } |
| 124 | 135 | |
| 125 | - if ($this->orm->getSchema()->defines($parameter->getClass()->getName())) { |
|
| 136 | + if ($this->orm->getSchema()->defines($parameter->getClass()->getName())) |
|
| 137 | + { |
|
| 126 | 138 | $this->cache[$key][$parameter->getName()] = $this->orm->resolveRole($parameter->getClass()->getName()); |
| 127 | 139 | } |
| 128 | 140 | } |