@@ -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[] = $entity; |
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 | } |
@@ -46,17 +46,21 @@ 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 | 51 | $value = $this->getParameter($parameter, $parameters, count($entities) === 1); |
51 | - if ($value === null) { |
|
52 | + if ($value === null) |
|
53 | + { |
|
52 | 54 | throw new ControllerException( |
53 | 55 | "Entity `{$parameter}` can not be found", |
54 | 56 | ControllerException::NOT_FOUND |
55 | 57 | ); |
56 | 58 | } |
57 | 59 | |
58 | - if (is_object($value)) { |
|
59 | - if ($this->orm->getHeap()->has($value)) { |
|
60 | + if (is_object($value)) |
|
61 | + { |
|
62 | + if ($this->orm->getHeap()->has($value)) |
|
63 | + { |
|
60 | 64 | $contextCandidates[] = $value; |
61 | 65 | } |
62 | 66 | |
@@ -65,7 +69,8 @@ discard block |
||
65 | 69 | } |
66 | 70 | |
67 | 71 | $entity = $this->resolveEntity($role, $value); |
68 | - if ($entity === null) { |
|
72 | + if ($entity === null) |
|
73 | + { |
|
69 | 74 | throw new ControllerException( |
70 | 75 | "Entity `{$parameter}` can not be found", |
71 | 76 | ControllerException::NOT_FOUND |
@@ -76,7 +81,8 @@ discard block |
||
76 | 81 | $contextCandidates[] = $entity; |
77 | 82 | } |
78 | 83 | |
79 | - if (!isset($parameters['@context']) && count($contextCandidates) === 1) { |
|
84 | + if (!isset($parameters['@context']) && count($contextCandidates) === 1) |
|
85 | + { |
|
80 | 86 | $parameters['@context'] = current($contextCandidates); |
81 | 87 | } |
82 | 88 | |
@@ -91,7 +97,8 @@ discard block |
||
91 | 97 | */ |
92 | 98 | protected function getParameter(string $role, array $parameters, bool $useDefault = false) |
93 | 99 | { |
94 | - if (!$useDefault) { |
|
100 | + if (!$useDefault) |
|
101 | + { |
|
95 | 102 | return $parameters[$role] ?? null; |
96 | 103 | } |
97 | 104 | |
@@ -116,23 +123,30 @@ discard block |
||
116 | 123 | private function getDeclaredEntities(string $controller, string $action): array |
117 | 124 | { |
118 | 125 | $key = sprintf('%s:%s', $controller, $action); |
119 | - if (array_key_exists($key, $this->cache)) { |
|
126 | + if (array_key_exists($key, $this->cache)) |
|
127 | + { |
|
120 | 128 | return $this->cache[$key]; |
121 | 129 | } |
122 | 130 | |
123 | 131 | $this->cache[$key] = []; |
124 | - try { |
|
132 | + try |
|
133 | + { |
|
125 | 134 | $method = new \ReflectionMethod($controller, $action); |
126 | - } catch (\ReflectionException $e) { |
|
135 | + } |
|
136 | + catch (\ReflectionException $e) |
|
137 | + { |
|
127 | 138 | return []; |
128 | 139 | } |
129 | 140 | |
130 | - foreach ($method->getParameters() as $parameter) { |
|
131 | - if ($parameter->getClass() === null) { |
|
141 | + foreach ($method->getParameters() as $parameter) |
|
142 | + { |
|
143 | + if ($parameter->getClass() === null) |
|
144 | + { |
|
132 | 145 | continue; |
133 | 146 | } |
134 | 147 | |
135 | - if ($this->orm->getSchema()->defines($parameter->getClass()->getName())) { |
|
148 | + if ($this->orm->getSchema()->defines($parameter->getClass()->getName())) |
|
149 | + { |
|
136 | 150 | $this->cache[$key][$parameter->getName()] = $this->orm->resolveRole($parameter->getClass()->getName()); |
137 | 151 | } |
138 | 152 | } |