@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | public function perform(KernelInterface $kernel, FilesInterface $files, DirectoriesInterface $dirs): void |
38 | 38 | { |
39 | 39 | $protoFile = $this->argument('proto'); |
40 | - if (!file_exists($protoFile)) { |
|
40 | + if (!file_exists($protoFile)){ |
|
41 | 41 | $this->sprintf('<error>File `%s` not found.</error>', $protoFile); |
42 | 42 | return; |
43 | 43 | } |
@@ -50,19 +50,19 @@ discard block |
||
50 | 50 | |
51 | 51 | $this->sprintf("<info>Compiling <fg=cyan>`%s`</fg=cyan>:</info>\n", $protoFile); |
52 | 52 | |
53 | - try { |
|
53 | + try{ |
|
54 | 54 | $result = $compiler->compile($protoFile); |
55 | - } catch (\Throwable $e) { |
|
55 | + }catch (\Throwable $e){ |
|
56 | 56 | $this->sprintf("<error>Error:</error> <fg=red>%s</fg=red>\n", $e->getMessage()); |
57 | 57 | return; |
58 | 58 | } |
59 | 59 | |
60 | - if ($result === []) { |
|
60 | + if ($result === []){ |
|
61 | 61 | $this->sprintf("<info>No files were generated.</info>\n", $protoFile); |
62 | 62 | return; |
63 | 63 | } |
64 | 64 | |
65 | - foreach ($result as $file) { |
|
65 | + foreach ($result as $file){ |
|
66 | 66 | $this->sprintf( |
67 | 67 | "<fg=green>•</fg=green> %s%s%s\n", |
68 | 68 | Color::LIGHT_WHITE, |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | protected function getPath(KernelInterface $kernel): string |
82 | 82 | { |
83 | 83 | $path = $this->argument('path'); |
84 | - if ($path !== 'auto') { |
|
84 | + if ($path !== 'auto'){ |
|
85 | 85 | return $path; |
86 | 86 | } |
87 | 87 | |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | protected function getNamespace(KernelInterface $kernel): string |
100 | 100 | { |
101 | 101 | $namespace = $this->argument('namespace'); |
102 | - if ($namespace !== 'auto') { |
|
102 | + if ($namespace !== 'auto'){ |
|
103 | 103 | return $namespace; |
104 | 104 | } |
105 | 105 |
@@ -37,7 +37,8 @@ discard block |
||
37 | 37 | public function perform(KernelInterface $kernel, FilesInterface $files, DirectoriesInterface $dirs): void |
38 | 38 | { |
39 | 39 | $protoFile = $this->argument('proto'); |
40 | - if (!file_exists($protoFile)) { |
|
40 | + if (!file_exists($protoFile)) |
|
41 | + { |
|
41 | 42 | $this->sprintf('<error>File `%s` not found.</error>', $protoFile); |
42 | 43 | return; |
43 | 44 | } |
@@ -50,19 +51,24 @@ discard block |
||
50 | 51 | |
51 | 52 | $this->sprintf("<info>Compiling <fg=cyan>`%s`</fg=cyan>:</info>\n", $protoFile); |
52 | 53 | |
53 | - try { |
|
54 | + try |
|
55 | + { |
|
54 | 56 | $result = $compiler->compile($protoFile); |
55 | - } catch (\Throwable $e) { |
|
57 | + } |
|
58 | + catch (\Throwable $e) |
|
59 | + { |
|
56 | 60 | $this->sprintf("<error>Error:</error> <fg=red>%s</fg=red>\n", $e->getMessage()); |
57 | 61 | return; |
58 | 62 | } |
59 | 63 | |
60 | - if ($result === []) { |
|
64 | + if ($result === []) |
|
65 | + { |
|
61 | 66 | $this->sprintf("<info>No files were generated.</info>\n", $protoFile); |
62 | 67 | return; |
63 | 68 | } |
64 | 69 | |
65 | - foreach ($result as $file) { |
|
70 | + foreach ($result as $file) |
|
71 | + { |
|
66 | 72 | $this->sprintf( |
67 | 73 | "<fg=green>•</fg=green> %s%s%s\n", |
68 | 74 | Color::LIGHT_WHITE, |
@@ -81,7 +87,8 @@ discard block |
||
81 | 87 | protected function getPath(KernelInterface $kernel): string |
82 | 88 | { |
83 | 89 | $path = $this->argument('path'); |
84 | - if ($path !== 'auto') { |
|
90 | + if ($path !== 'auto') |
|
91 | + { |
|
85 | 92 | return $path; |
86 | 93 | } |
87 | 94 | |
@@ -99,7 +106,8 @@ discard block |
||
99 | 106 | protected function getNamespace(KernelInterface $kernel): string |
100 | 107 | { |
101 | 108 | $namespace = $this->argument('namespace'); |
102 | - if ($namespace !== 'auto') { |
|
109 | + if ($namespace !== 'auto') |
|
110 | + { |
|
103 | 111 | return $namespace; |
104 | 112 | } |
105 | 113 |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | use Spiral\Core\Container\Autowire; |
13 | 13 | use Spiral\Debug\Dumper; |
14 | 14 | |
15 | -if (!function_exists('bind')) { |
|
15 | +if (!function_exists('bind')){ |
|
16 | 16 | /** |
17 | 17 | * Shortcut to container Autowire definition. |
18 | 18 | * |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | } |
31 | 31 | } |
32 | 32 | |
33 | -if (!function_exists('dumprr')) { |
|
33 | +if (!function_exists('dumprr')){ |
|
34 | 34 | /** |
35 | 35 | * Dumprr is similar to Dump function but always redirect output to STDERR. |
36 | 36 | * |
@@ -12,7 +12,8 @@ discard block |
||
12 | 12 | use Spiral\Core\Container\Autowire; |
13 | 13 | use Spiral\Debug\Dumper; |
14 | 14 | |
15 | -if (!function_exists('bind')) { |
|
15 | +if (!function_exists('bind')) |
|
16 | +{ |
|
16 | 17 | /** |
17 | 18 | * Shortcut to container Autowire definition. |
18 | 19 | * |
@@ -30,7 +31,8 @@ discard block |
||
30 | 31 | } |
31 | 32 | } |
32 | 33 | |
33 | -if (!function_exists('dumprr')) { |
|
34 | +if (!function_exists('dumprr')) |
|
35 | +{ |
|
34 | 36 | /** |
35 | 37 | * Dumprr is similar to Dump function but always redirect output to STDERR. |
36 | 38 | * |
@@ -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 | } |
@@ -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 | } |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | { |
53 | 53 | $permission = $this->getPermissions($controller, $action); |
54 | 54 | |
55 | - if ($permission !== null && !$this->guard->allows($permission[0], $parameters)) { |
|
55 | + if ($permission !== null && !$this->guard->allows($permission[0], $parameters)){ |
|
56 | 56 | throw new ControllerException($permission[2], $permission[1]); |
57 | 57 | } |
58 | 58 | |
@@ -71,14 +71,14 @@ discard block |
||
71 | 71 | private function getPermissions(string $controller, string $action): ?array |
72 | 72 | { |
73 | 73 | $key = sprintf('%s:%s', $controller, $action); |
74 | - if (array_key_exists($key, $this->cache)) { |
|
74 | + if (array_key_exists($key, $this->cache)){ |
|
75 | 75 | return $this->cache[$key]; |
76 | 76 | } |
77 | 77 | |
78 | 78 | $this->cache[$key] = null; |
79 | - try { |
|
79 | + try{ |
|
80 | 80 | $method = new \ReflectionMethod($controller, $action); |
81 | - } catch (\ReflectionException $e) { |
|
81 | + }catch (\ReflectionException $e){ |
|
82 | 82 | return null; |
83 | 83 | } |
84 | 84 | |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | Guarded::class |
97 | 97 | ); |
98 | 98 | |
99 | - if ($action === null) { |
|
99 | + if ($action === null){ |
|
100 | 100 | return null; |
101 | 101 | } |
102 | 102 | |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | $guarded->errorMessage ?? sprintf('Unauthorized access `%s`', $guarded->permission ?? $method->getName()) |
120 | 120 | ]; |
121 | 121 | |
122 | - if ($guarded->permission === null && $ns === null) { |
|
122 | + if ($guarded->permission === null && $ns === null){ |
|
123 | 123 | throw new InterceptorException( |
124 | 124 | sprintf( |
125 | 125 | 'Unable to apply @Guarded without name or @GuardNamespace on `%s`->`%s`', |
@@ -129,16 +129,16 @@ discard block |
||
129 | 129 | ); |
130 | 130 | } |
131 | 131 | |
132 | - if ($ns !== null) { |
|
132 | + if ($ns !== null){ |
|
133 | 133 | $permission[0] = sprintf('%s.%s', $ns->namespace, $permission[0]); |
134 | 134 | } |
135 | 135 | |
136 | - if ($this->namespace !== null) { |
|
136 | + if ($this->namespace !== null){ |
|
137 | 137 | // global namespace |
138 | 138 | $permission[0] = sprintf('%s.%s', $this->namespace, $permission[0]); |
139 | 139 | } |
140 | 140 | |
141 | - switch ($guarded->else) { |
|
141 | + switch ($guarded->else){ |
|
142 | 142 | case 'unauthorized': |
143 | 143 | $permission[1] = ControllerException::UNAUTHORIZED; |
144 | 144 | break; |
@@ -52,7 +52,8 @@ discard block |
||
52 | 52 | { |
53 | 53 | $permission = $this->getPermissions($controller, $action); |
54 | 54 | |
55 | - if ($permission !== null && !$this->guard->allows($permission[0], $parameters)) { |
|
55 | + if ($permission !== null && !$this->guard->allows($permission[0], $parameters)) |
|
56 | + { |
|
56 | 57 | throw new ControllerException($permission[2], $permission[1]); |
57 | 58 | } |
58 | 59 | |
@@ -71,14 +72,18 @@ discard block |
||
71 | 72 | private function getPermissions(string $controller, string $action): ?array |
72 | 73 | { |
73 | 74 | $key = sprintf('%s:%s', $controller, $action); |
74 | - if (array_key_exists($key, $this->cache)) { |
|
75 | + if (array_key_exists($key, $this->cache)) |
|
76 | + { |
|
75 | 77 | return $this->cache[$key]; |
76 | 78 | } |
77 | 79 | |
78 | 80 | $this->cache[$key] = null; |
79 | - try { |
|
81 | + try |
|
82 | + { |
|
80 | 83 | $method = new \ReflectionMethod($controller, $action); |
81 | - } catch (\ReflectionException $e) { |
|
84 | + } |
|
85 | + catch (\ReflectionException $e) |
|
86 | + { |
|
82 | 87 | return null; |
83 | 88 | } |
84 | 89 | |
@@ -96,7 +101,8 @@ discard block |
||
96 | 101 | Guarded::class |
97 | 102 | ); |
98 | 103 | |
99 | - if ($action === null) { |
|
104 | + if ($action === null) |
|
105 | + { |
|
100 | 106 | return null; |
101 | 107 | } |
102 | 108 | |
@@ -119,7 +125,8 @@ discard block |
||
119 | 125 | $guarded->errorMessage ?? sprintf('Unauthorized access `%s`', $guarded->permission ?? $method->getName()) |
120 | 126 | ]; |
121 | 127 | |
122 | - if ($guarded->permission === null && $ns === null) { |
|
128 | + if ($guarded->permission === null && $ns === null) |
|
129 | + { |
|
123 | 130 | throw new InterceptorException( |
124 | 131 | sprintf( |
125 | 132 | 'Unable to apply @Guarded without name or @GuardNamespace on `%s`->`%s`', |
@@ -129,16 +136,19 @@ discard block |
||
129 | 136 | ); |
130 | 137 | } |
131 | 138 | |
132 | - if ($ns !== null) { |
|
139 | + if ($ns !== null) |
|
140 | + { |
|
133 | 141 | $permission[0] = sprintf('%s.%s', $ns->namespace, $permission[0]); |
134 | 142 | } |
135 | 143 | |
136 | - if ($this->namespace !== null) { |
|
144 | + if ($this->namespace !== null) |
|
145 | + { |
|
137 | 146 | // global namespace |
138 | 147 | $permission[0] = sprintf('%s.%s', $this->namespace, $permission[0]); |
139 | 148 | } |
140 | 149 | |
141 | - switch ($guarded->else) { |
|
150 | + switch ($guarded->else) |
|
151 | + { |
|
142 | 152 | case 'unauthorized': |
143 | 153 | $permission[1] = ControllerException::UNAUTHORIZED; |
144 | 154 | break; |
@@ -38,15 +38,15 @@ |
||
38 | 38 | public function getServices(): array |
39 | 39 | { |
40 | 40 | $result = []; |
41 | - foreach ($this->classes->getClasses(ServiceInterface::class) as $service) { |
|
42 | - if (!$service->isInstantiable()) { |
|
41 | + foreach ($this->classes->getClasses(ServiceInterface::class) as $service){ |
|
42 | + if (!$service->isInstantiable()){ |
|
43 | 43 | continue; |
44 | 44 | } |
45 | 45 | |
46 | 46 | $instance = $this->container->get($service->getName()); |
47 | 47 | |
48 | - foreach ($service->getInterfaces() as $interface) { |
|
49 | - if ($interface->isSubclassOf(ServiceInterface::class)) { |
|
48 | + foreach ($service->getInterfaces() as $interface){ |
|
49 | + if ($interface->isSubclassOf(ServiceInterface::class)){ |
|
50 | 50 | $result[$interface->getName()] = $instance; |
51 | 51 | } |
52 | 52 | } |
@@ -38,15 +38,19 @@ |
||
38 | 38 | public function getServices(): array |
39 | 39 | { |
40 | 40 | $result = []; |
41 | - foreach ($this->classes->getClasses(ServiceInterface::class) as $service) { |
|
42 | - if (!$service->isInstantiable()) { |
|
41 | + foreach ($this->classes->getClasses(ServiceInterface::class) as $service) |
|
42 | + { |
|
43 | + if (!$service->isInstantiable()) |
|
44 | + { |
|
43 | 45 | continue; |
44 | 46 | } |
45 | 47 | |
46 | 48 | $instance = $this->container->get($service->getName()); |
47 | 49 | |
48 | - foreach ($service->getInterfaces() as $interface) { |
|
49 | - if ($interface->isSubclassOf(ServiceInterface::class)) { |
|
50 | + foreach ($service->getInterfaces() as $interface) |
|
51 | + { |
|
52 | + if ($interface->isSubclassOf(ServiceInterface::class)) |
|
53 | + { |
|
50 | 54 | $result[$interface->getName()] = $instance; |
51 | 55 | } |
52 | 56 | } |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | EnvironmentInterface $env, |
40 | 40 | FinalizerInterface $finalizer, |
41 | 41 | ContainerInterface $container |
42 | - ) { |
|
42 | + ){ |
|
43 | 43 | $this->env = $env; |
44 | 44 | $this->finalizer = $finalizer; |
45 | 45 | $this->container = $container; |
@@ -69,14 +69,14 @@ discard block |
||
69 | 69 | $worker = $this->container->get(Worker::class); |
70 | 70 | $locator = $this->container->get(LocatorInterface::class); |
71 | 71 | |
72 | - foreach ($locator->getServices() as $interface => $service) { |
|
72 | + foreach ($locator->getServices() as $interface => $service){ |
|
73 | 73 | $server->registerService($interface, $service); |
74 | 74 | } |
75 | 75 | |
76 | 76 | $server->serve( |
77 | 77 | $worker, |
78 | 78 | function (\Throwable $e = null): void { |
79 | - if ($e !== null) { |
|
79 | + if ($e !== null){ |
|
80 | 80 | $this->handleException($e); |
81 | 81 | } |
82 | 82 | |
@@ -90,9 +90,9 @@ discard block |
||
90 | 90 | */ |
91 | 91 | protected function handleException(\Throwable $e): void |
92 | 92 | { |
93 | - try { |
|
93 | + try{ |
|
94 | 94 | $this->container->get(SnapshotterInterface::class)->register($e); |
95 | - } catch (\Throwable | ContainerExceptionInterface $se) { |
|
95 | + }catch (\Throwable | ContainerExceptionInterface $se){ |
|
96 | 96 | // no need to notify when unable to register an exception |
97 | 97 | } |
98 | 98 | } |
@@ -69,14 +69,16 @@ discard block |
||
69 | 69 | $worker = $this->container->get(Worker::class); |
70 | 70 | $locator = $this->container->get(LocatorInterface::class); |
71 | 71 | |
72 | - foreach ($locator->getServices() as $interface => $service) { |
|
72 | + foreach ($locator->getServices() as $interface => $service) |
|
73 | + { |
|
73 | 74 | $server->registerService($interface, $service); |
74 | 75 | } |
75 | 76 | |
76 | 77 | $server->serve( |
77 | 78 | $worker, |
78 | 79 | function (\Throwable $e = null): void { |
79 | - if ($e !== null) { |
|
80 | + if ($e !== null) |
|
81 | + { |
|
80 | 82 | $this->handleException($e); |
81 | 83 | } |
82 | 84 | |
@@ -90,9 +92,12 @@ discard block |
||
90 | 92 | */ |
91 | 93 | protected function handleException(\Throwable $e): void |
92 | 94 | { |
93 | - try { |
|
95 | + try |
|
96 | + { |
|
94 | 97 | $this->container->get(SnapshotterInterface::class)->register($e); |
95 | - } catch (\Throwable | ContainerExceptionInterface $se) { |
|
98 | + } |
|
99 | + catch (\Throwable | ContainerExceptionInterface $se) |
|
100 | + { |
|
96 | 101 | // no need to notify when unable to register an exception |
97 | 102 | } |
98 | 103 | } |
@@ -63,14 +63,14 @@ discard block |
||
63 | 63 | |
64 | 64 | $output = trim(join("\n", $output), "\n ,"); |
65 | 65 | |
66 | - if ($output !== '') { |
|
66 | + if ($output !== ''){ |
|
67 | 67 | $this->files->deleteDirectory($tmpDir); |
68 | 68 | throw new CompileException($output); |
69 | 69 | } |
70 | 70 | |
71 | 71 | // copying files (using relative path and namespace) |
72 | 72 | $result = []; |
73 | - foreach ($this->files->getFiles($tmpDir) as $file) { |
|
73 | + foreach ($this->files->getFiles($tmpDir) as $file){ |
|
74 | 74 | $result[] = $this->copy($tmpDir, $file); |
75 | 75 | } |
76 | 76 | |
@@ -87,11 +87,11 @@ discard block |
||
87 | 87 | private function copy(string $tmpDir, string $file): string |
88 | 88 | { |
89 | 89 | $source = ltrim($this->files->relativePath($file, $tmpDir), '\\/'); |
90 | - if (strpos($source, $this->baseNamespace) === 0) { |
|
90 | + if (strpos($source, $this->baseNamespace) === 0){ |
|
91 | 91 | $source = ltrim(substr($source, strlen($this->baseNamespace)), '\\/'); |
92 | 92 | } |
93 | 93 | |
94 | - $target = $this->files->normalizePath($this->basePath . '/' . $source); |
|
94 | + $target = $this->files->normalizePath($this->basePath.'/'.$source); |
|
95 | 95 | |
96 | 96 | $this->files->ensureDirectory(dirname($target)); |
97 | 97 | $this->files->copy($file, $target); |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | */ |
105 | 105 | private function tmpDir(): string |
106 | 106 | { |
107 | - $directory = sys_get_temp_dir() . '/' . spl_object_hash($this); |
|
107 | + $directory = sys_get_temp_dir().'/'.spl_object_hash($this); |
|
108 | 108 | $this->files->ensureDirectory($directory); |
109 | 109 | |
110 | 110 | return $this->files->normalizePath($directory, true); |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | { |
121 | 121 | return array_filter( |
122 | 122 | $this->files->getFiles(dirname($protoFile)), |
123 | - function ($file) { |
|
123 | + function ($file){ |
|
124 | 124 | return strpos($file, '.proto') !== false; |
125 | 125 | } |
126 | 126 | ); |
@@ -63,14 +63,16 @@ discard block |
||
63 | 63 | |
64 | 64 | $output = trim(join("\n", $output), "\n ,"); |
65 | 65 | |
66 | - if ($output !== '') { |
|
66 | + if ($output !== '') |
|
67 | + { |
|
67 | 68 | $this->files->deleteDirectory($tmpDir); |
68 | 69 | throw new CompileException($output); |
69 | 70 | } |
70 | 71 | |
71 | 72 | // copying files (using relative path and namespace) |
72 | 73 | $result = []; |
73 | - foreach ($this->files->getFiles($tmpDir) as $file) { |
|
74 | + foreach ($this->files->getFiles($tmpDir) as $file) |
|
75 | + { |
|
74 | 76 | $result[] = $this->copy($tmpDir, $file); |
75 | 77 | } |
76 | 78 | |
@@ -87,7 +89,8 @@ discard block |
||
87 | 89 | private function copy(string $tmpDir, string $file): string |
88 | 90 | { |
89 | 91 | $source = ltrim($this->files->relativePath($file, $tmpDir), '\\/'); |
90 | - if (strpos($source, $this->baseNamespace) === 0) { |
|
92 | + if (strpos($source, $this->baseNamespace) === 0) |
|
93 | + { |
|
91 | 94 | $source = ltrim(substr($source, strlen($this->baseNamespace)), '\\/'); |
92 | 95 | } |
93 | 96 | |
@@ -120,7 +123,8 @@ discard block |
||
120 | 123 | { |
121 | 124 | return array_filter( |
122 | 125 | $this->files->getFiles(dirname($protoFile)), |
123 | - function ($file) { |
|
126 | + function ($file) |
|
127 | + { |
|
124 | 128 | return strpos($file, '.proto') !== false; |
125 | 129 | } |
126 | 130 | ); |
@@ -32,7 +32,7 @@ |
||
32 | 32 | |
33 | 33 | public function compile(string $path, ContextInterface $context): void |
34 | 34 | { |
35 | - if ($path === 'custom:error') { |
|
35 | + if ($path === 'custom:error'){ |
|
36 | 36 | throw new EngineException('Unable to compile custom:error'); |
37 | 37 | } |
38 | 38 | } |
@@ -32,7 +32,8 @@ |
||
32 | 32 | |
33 | 33 | public function compile(string $path, ContextInterface $context): void |
34 | 34 | { |
35 | - if ($path === 'custom:error') { |
|
35 | + if ($path === 'custom:error') |
|
36 | + { |
|
36 | 37 | throw new EngineException('Unable to compile custom:error'); |
37 | 38 | } |
38 | 39 | } |