@@ -38,15 +38,15 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function process(string $controller, string $action, array $parameters, CoreInterface $core) |
40 | 40 | { |
41 | - foreach ($this->getDeclaredFilters($controller, $action) as $parameter => $filterClass) { |
|
42 | - if (isset($parameters[$parameter])) { |
|
41 | + foreach ($this->getDeclaredFilters($controller, $action) as $parameter => $filterClass){ |
|
42 | + if (isset($parameters[$parameter])){ |
|
43 | 43 | continue; |
44 | 44 | } |
45 | 45 | |
46 | 46 | /** @var FilterInterface $filter */ |
47 | 47 | $filter = $this->container->get($filterClass); |
48 | 48 | |
49 | - if (!$filter->isValid()) { |
|
49 | + if (!$filter->isValid()){ |
|
50 | 50 | // add more options in future |
51 | 51 | return [ |
52 | 52 | 'status' => 400, |
@@ -68,23 +68,23 @@ discard block |
||
68 | 68 | private function getDeclaredFilters(string $controller, string $action): array |
69 | 69 | { |
70 | 70 | $key = sprintf("%s:%s", $controller, $action); |
71 | - if (array_key_exists($key, $this->filterCache)) { |
|
71 | + if (array_key_exists($key, $this->filterCache)){ |
|
72 | 72 | return $this->filterCache[$key]; |
73 | 73 | } |
74 | 74 | |
75 | 75 | $this->filterCache[$key] = []; |
76 | - try { |
|
76 | + try{ |
|
77 | 77 | $method = new \ReflectionMethod($controller, $action); |
78 | - } catch (\ReflectionException $e) { |
|
78 | + }catch (\ReflectionException $e){ |
|
79 | 79 | return []; |
80 | 80 | } |
81 | 81 | |
82 | - foreach ($method->getParameters() as $parameter) { |
|
83 | - if ($parameter->getClass() === null) { |
|
82 | + foreach ($method->getParameters() as $parameter){ |
|
83 | + if ($parameter->getClass() === null){ |
|
84 | 84 | continue; |
85 | 85 | } |
86 | 86 | |
87 | - if ($parameter->getClass()->implementsInterface(FilterInterface::class)) { |
|
87 | + if ($parameter->getClass()->implementsInterface(FilterInterface::class)){ |
|
88 | 88 | $this->filterCache[$key][$parameter->getName()] = $parameter->getClass()->getName(); |
89 | 89 | } |
90 | 90 | } |
@@ -38,15 +38,18 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function process(string $controller, string $action, array $parameters, CoreInterface $core) |
40 | 40 | { |
41 | - foreach ($this->getDeclaredFilters($controller, $action) as $parameter => $filterClass) { |
|
42 | - if (isset($parameters[$parameter])) { |
|
41 | + foreach ($this->getDeclaredFilters($controller, $action) as $parameter => $filterClass) |
|
42 | + { |
|
43 | + if (isset($parameters[$parameter])) |
|
44 | + { |
|
43 | 45 | continue; |
44 | 46 | } |
45 | 47 | |
46 | 48 | /** @var FilterInterface $filter */ |
47 | 49 | $filter = $this->container->get($filterClass); |
48 | 50 | |
49 | - if (!$filter->isValid()) { |
|
51 | + if (!$filter->isValid()) |
|
52 | + { |
|
50 | 53 | // add more options in future |
51 | 54 | return [ |
52 | 55 | 'status' => 400, |
@@ -68,23 +71,30 @@ discard block |
||
68 | 71 | private function getDeclaredFilters(string $controller, string $action): array |
69 | 72 | { |
70 | 73 | $key = sprintf("%s:%s", $controller, $action); |
71 | - if (array_key_exists($key, $this->filterCache)) { |
|
74 | + if (array_key_exists($key, $this->filterCache)) |
|
75 | + { |
|
72 | 76 | return $this->filterCache[$key]; |
73 | 77 | } |
74 | 78 | |
75 | 79 | $this->filterCache[$key] = []; |
76 | - try { |
|
80 | + try |
|
81 | + { |
|
77 | 82 | $method = new \ReflectionMethod($controller, $action); |
78 | - } catch (\ReflectionException $e) { |
|
83 | + } |
|
84 | + catch (\ReflectionException $e) |
|
85 | + { |
|
79 | 86 | return []; |
80 | 87 | } |
81 | 88 | |
82 | - foreach ($method->getParameters() as $parameter) { |
|
83 | - if ($parameter->getClass() === null) { |
|
89 | + foreach ($method->getParameters() as $parameter) |
|
90 | + { |
|
91 | + if ($parameter->getClass() === null) |
|
92 | + { |
|
84 | 93 | continue; |
85 | 94 | } |
86 | 95 | |
87 | - if ($parameter->getClass()->implementsInterface(FilterInterface::class)) { |
|
96 | + if ($parameter->getClass()->implementsInterface(FilterInterface::class)) |
|
97 | + { |
|
88 | 98 | $this->filterCache[$key][$parameter->getName()] = $parameter->getClass()->getName(); |
89 | 99 | } |
90 | 100 | } |
@@ -39,8 +39,8 @@ discard block |
||
39 | 39 | public function process(string $controller, string $action, array $parameters, CoreInterface $core) |
40 | 40 | { |
41 | 41 | // todo: support singular ID |
42 | - foreach ($this->getDeclaredEntities($controller, $action) as $parameter => $role) { |
|
43 | - if (!isset($parameters[$parameter])) { |
|
42 | + foreach ($this->getDeclaredEntities($controller, $action) as $parameter => $role){ |
|
43 | + if (!isset($parameters[$parameter])){ |
|
44 | 44 | throw new ControllerException( |
45 | 45 | "Entity `{$role}` can not be found", |
46 | 46 | ControllerException::NOT_FOUND |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | } |
49 | 49 | |
50 | 50 | $entity = $this->orm->getRepository($role)->findByPK($parameters[$parameter]); |
51 | - if ($entity === null) { |
|
51 | + if ($entity === null){ |
|
52 | 52 | throw new ControllerException( |
53 | 53 | "Entity `{$role}` can not be found", |
54 | 54 | ControllerException::NOT_FOUND |
@@ -69,23 +69,23 @@ discard block |
||
69 | 69 | private function getDeclaredEntities(string $controller, string $action): array |
70 | 70 | { |
71 | 71 | $key = sprintf("%s:%s", $controller, $action); |
72 | - if (array_key_exists($key, $this->entityCache)) { |
|
72 | + if (array_key_exists($key, $this->entityCache)){ |
|
73 | 73 | return $this->entityCache[$key]; |
74 | 74 | } |
75 | 75 | |
76 | 76 | $this->entityCache[$key] = []; |
77 | - try { |
|
77 | + try{ |
|
78 | 78 | $method = new \ReflectionMethod($controller, $action); |
79 | - } catch (\ReflectionException $e) { |
|
79 | + }catch (\ReflectionException $e){ |
|
80 | 80 | return []; |
81 | 81 | } |
82 | 82 | |
83 | - foreach ($method->getParameters() as $parameter) { |
|
84 | - if ($parameter->getClass() === null) { |
|
83 | + foreach ($method->getParameters() as $parameter){ |
|
84 | + if ($parameter->getClass() === null){ |
|
85 | 85 | continue; |
86 | 86 | } |
87 | 87 | |
88 | - if ($this->orm->getSchema()->defines($parameter->getClass()->getName())) { |
|
88 | + if ($this->orm->getSchema()->defines($parameter->getClass()->getName())){ |
|
89 | 89 | $this->entityCache[$key][$parameter->getName()] = $parameter->getClass()->getName(); |
90 | 90 | } |
91 | 91 | } |
@@ -39,8 +39,10 @@ discard block |
||
39 | 39 | public function process(string $controller, string $action, array $parameters, CoreInterface $core) |
40 | 40 | { |
41 | 41 | // todo: support singular ID |
42 | - foreach ($this->getDeclaredEntities($controller, $action) as $parameter => $role) { |
|
43 | - if (!isset($parameters[$parameter])) { |
|
42 | + foreach ($this->getDeclaredEntities($controller, $action) as $parameter => $role) |
|
43 | + { |
|
44 | + if (!isset($parameters[$parameter])) |
|
45 | + { |
|
44 | 46 | throw new ControllerException( |
45 | 47 | "Entity `{$role}` can not be found", |
46 | 48 | ControllerException::NOT_FOUND |
@@ -48,7 +50,8 @@ discard block |
||
48 | 50 | } |
49 | 51 | |
50 | 52 | $entity = $this->orm->getRepository($role)->findByPK($parameters[$parameter]); |
51 | - if ($entity === null) { |
|
53 | + if ($entity === null) |
|
54 | + { |
|
52 | 55 | throw new ControllerException( |
53 | 56 | "Entity `{$role}` can not be found", |
54 | 57 | ControllerException::NOT_FOUND |
@@ -69,23 +72,30 @@ discard block |
||
69 | 72 | private function getDeclaredEntities(string $controller, string $action): array |
70 | 73 | { |
71 | 74 | $key = sprintf("%s:%s", $controller, $action); |
72 | - if (array_key_exists($key, $this->entityCache)) { |
|
75 | + if (array_key_exists($key, $this->entityCache)) |
|
76 | + { |
|
73 | 77 | return $this->entityCache[$key]; |
74 | 78 | } |
75 | 79 | |
76 | 80 | $this->entityCache[$key] = []; |
77 | - try { |
|
81 | + try |
|
82 | + { |
|
78 | 83 | $method = new \ReflectionMethod($controller, $action); |
79 | - } catch (\ReflectionException $e) { |
|
84 | + } |
|
85 | + catch (\ReflectionException $e) |
|
86 | + { |
|
80 | 87 | return []; |
81 | 88 | } |
82 | 89 | |
83 | - foreach ($method->getParameters() as $parameter) { |
|
84 | - if ($parameter->getClass() === null) { |
|
90 | + foreach ($method->getParameters() as $parameter) |
|
91 | + { |
|
92 | + if ($parameter->getClass() === null) |
|
93 | + { |
|
85 | 94 | continue; |
86 | 95 | } |
87 | 96 | |
88 | - if ($this->orm->getSchema()->defines($parameter->getClass()->getName())) { |
|
97 | + if ($this->orm->getSchema()->defines($parameter->getClass()->getName())) |
|
98 | + { |
|
89 | 99 | $this->entityCache[$key][$parameter->getName()] = $parameter->getClass()->getName(); |
90 | 100 | } |
91 | 101 | } |