@@ -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 | } |
@@ -49,20 +49,24 @@ 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 | + { |
|
54 | + if (isset($parameters[$parameter])) |
|
55 | + { |
|
54 | 56 | continue; |
55 | 57 | } |
56 | 58 | |
57 | 59 | /** @var FilterInterface $filter */ |
58 | 60 | $filter = $this->container->get($filterClass); |
59 | 61 | |
60 | - if (isset($parameters['@context'])) { |
|
62 | + if (isset($parameters['@context'])) |
|
63 | + { |
|
61 | 64 | // other interceptors can define the validation contex |
62 | 65 | $filter->setContext($parameters['@context']); |
63 | 66 | } |
64 | 67 | |
65 | - if (!$filter->isValid()) { |
|
68 | + if (!$filter->isValid()) |
|
69 | + { |
|
66 | 70 | return $this->renderInvalid($filter); |
67 | 71 | } |
68 | 72 | |
@@ -80,7 +84,8 @@ discard block |
||
80 | 84 | */ |
81 | 85 | protected function renderInvalid(FilterInterface $filter) |
82 | 86 | { |
83 | - switch ($this->strategy) { |
|
87 | + switch ($this->strategy) |
|
88 | + { |
|
84 | 89 | case self::STRATEGY_JSON_RESPONSE: |
85 | 90 | return [ |
86 | 91 | 'status' => 400, |
@@ -99,23 +104,30 @@ discard block |
||
99 | 104 | private function getDeclaredFilters(string $controller, string $action): array |
100 | 105 | { |
101 | 106 | $key = sprintf('%s:%s', $controller, $action); |
102 | - if (array_key_exists($key, $this->cache)) { |
|
107 | + if (array_key_exists($key, $this->cache)) |
|
108 | + { |
|
103 | 109 | return $this->cache[$key]; |
104 | 110 | } |
105 | 111 | |
106 | 112 | $this->cache[$key] = []; |
107 | - try { |
|
113 | + try |
|
114 | + { |
|
108 | 115 | $method = new \ReflectionMethod($controller, $action); |
109 | - } catch (\ReflectionException $e) { |
|
116 | + } |
|
117 | + catch (\ReflectionException $e) |
|
118 | + { |
|
110 | 119 | return []; |
111 | 120 | } |
112 | 121 | |
113 | - foreach ($method->getParameters() as $parameter) { |
|
114 | - if ($parameter->getClass() === null) { |
|
122 | + foreach ($method->getParameters() as $parameter) |
|
123 | + { |
|
124 | + if ($parameter->getClass() === null) |
|
125 | + { |
|
115 | 126 | continue; |
116 | 127 | } |
117 | 128 | |
118 | - if ($parameter->getClass()->implementsInterface(FilterInterface::class)) { |
|
129 | + if ($parameter->getClass()->implementsInterface(FilterInterface::class)) |
|
130 | + { |
|
119 | 131 | $this->cache[$key][$parameter->getName()] = $parameter->getClass()->getName(); |
120 | 132 | } |
121 | 133 | } |
@@ -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 | } |
@@ -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[] = $value; |
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 | } |