@@ -47,7 +47,8 @@ discard block |
||
47 | 47 | public function getPermission(string $controller, string $action): Permission |
48 | 48 | { |
49 | 49 | $key = sprintf('%s:%s', $controller, $action); |
50 | - if (!array_key_exists($key, $this->cache)) { |
|
50 | + if (!array_key_exists($key, $this->cache)) |
|
51 | + { |
|
51 | 52 | $this->cache[$key] = $this->generatePermission($controller, $action); |
52 | 53 | } |
53 | 54 | |
@@ -56,20 +57,25 @@ discard block |
||
56 | 57 | |
57 | 58 | private function generatePermission(string $controller, string $action): Permission |
58 | 59 | { |
59 | - try { |
|
60 | + try |
|
61 | + { |
|
60 | 62 | $method = new \ReflectionMethod($controller, $action); |
61 | - } catch (\ReflectionException $e) { |
|
63 | + } |
|
64 | + catch (\ReflectionException $e) |
|
65 | + { |
|
62 | 66 | return Permission::failed(); |
63 | 67 | } |
64 | 68 | |
65 | 69 | $guarded = $this->reader->firstFunctionMetadata($method, Guarded::class); |
66 | - if (!$guarded instanceof Guarded) { |
|
70 | + if (!$guarded instanceof Guarded) |
|
71 | + { |
|
67 | 72 | return Permission::failed(); |
68 | 73 | } |
69 | 74 | |
70 | 75 | $namespace = $this->reader->firstClassMetadata($method->getDeclaringClass(), GuardNamespace::class); |
71 | 76 | |
72 | - if ($guarded->permission || ($namespace instanceof GuardNamespace && $namespace->namespace)) { |
|
77 | + if ($guarded->permission || ($namespace instanceof GuardNamespace && $namespace->namespace)) |
|
78 | + { |
|
73 | 79 | return Permission::ok( |
74 | 80 | $this->makePermission($guarded, $method, $namespace), |
75 | 81 | $this->mapFailureException($guarded), |
@@ -92,11 +98,13 @@ discard block |
||
92 | 98 | private function makePermission(Guarded $guarded, \ReflectionMethod $method, ?GuardNamespace $ns): string |
93 | 99 | { |
94 | 100 | $permission = []; |
95 | - if ($this->namespace) { |
|
101 | + if ($this->namespace) |
|
102 | + { |
|
96 | 103 | $permission[] = $this->namespace; |
97 | 104 | } |
98 | 105 | |
99 | - if ($ns !== null && $ns->namespace) { |
|
106 | + if ($ns !== null && $ns->namespace) |
|
107 | + { |
|
100 | 108 | $permission[] = $ns->namespace; |
101 | 109 | } |
102 | 110 |
@@ -72,14 +72,17 @@ discard block |
||
72 | 72 | { |
73 | 73 | $result = $core->callAction($controller, $action, $parameters); |
74 | 74 | |
75 | - if (is_iterable($result)) { |
|
75 | + if (is_iterable($result)) |
|
76 | + { |
|
76 | 77 | $schema = $this->getSchema($controller, $action); |
77 | - if ($schema !== null) { |
|
78 | + if ($schema !== null) |
|
79 | + { |
|
78 | 80 | $grid = $this->makeFactory($schema) |
79 | 81 | ->withDefaults($schema['defaults']) |
80 | 82 | ->create($result, $schema['grid']); |
81 | 83 | |
82 | - if ($schema['view'] !== null) { |
|
84 | + if ($schema['view'] !== null) |
|
85 | + { |
|
83 | 86 | $grid = $grid->withView($schema['view']); |
84 | 87 | } |
85 | 88 | |
@@ -99,20 +102,25 @@ discard block |
||
99 | 102 | private function getSchema(string $controller, string $action): ?array |
100 | 103 | { |
101 | 104 | $key = sprintf('%s:%s', $controller, $action); |
102 | - if (array_key_exists($key, $this->cache)) { |
|
105 | + if (array_key_exists($key, $this->cache)) |
|
106 | + { |
|
103 | 107 | return $this->cache[$key]; |
104 | 108 | } |
105 | 109 | |
106 | 110 | $this->cache[$key] = null; |
107 | - try { |
|
111 | + try |
|
112 | + { |
|
108 | 113 | $method = new \ReflectionMethod($controller, $action); |
109 | - } catch (\ReflectionException $e) { |
|
114 | + } |
|
115 | + catch (\ReflectionException $e) |
|
116 | + { |
|
110 | 117 | return null; |
111 | 118 | } |
112 | 119 | |
113 | 120 | /** @var null|DataGrid $dataGrid */ |
114 | 121 | $dataGrid = $this->reader->firstFunctionMetadata($method, DataGrid::class); |
115 | - if ($dataGrid === null) { |
|
122 | + if ($dataGrid === null) |
|
123 | + { |
|
116 | 124 | return null; |
117 | 125 | } |
118 | 126 | |
@@ -133,19 +141,23 @@ discard block |
||
133 | 141 | 'factory' => $dataGrid->factory, |
134 | 142 | ]; |
135 | 143 | |
136 | - if (is_string($schema['view'])) { |
|
144 | + if (is_string($schema['view'])) |
|
145 | + { |
|
137 | 146 | $schema['view'] = $this->container->get($schema['view']); |
138 | 147 | } |
139 | 148 | |
140 | - if ($schema['defaults'] === [] && method_exists($schema['grid'], 'getDefaults')) { |
|
149 | + if ($schema['defaults'] === [] && method_exists($schema['grid'], 'getDefaults')) |
|
150 | + { |
|
141 | 151 | $schema['defaults'] = $schema['grid']->getDefaults(); |
142 | 152 | } |
143 | 153 | |
144 | - if ($schema['options'] === [] && method_exists($schema['grid'], 'getOptions')) { |
|
154 | + if ($schema['options'] === [] && method_exists($schema['grid'], 'getOptions')) |
|
155 | + { |
|
145 | 156 | $schema['options'] = $schema['grid']->getOptions(); |
146 | 157 | } |
147 | 158 | |
148 | - if ($schema['view'] === null && is_callable($schema['grid'])) { |
|
159 | + if ($schema['view'] === null && is_callable($schema['grid'])) |
|
160 | + { |
|
149 | 161 | $schema['view'] = $schema['grid']; |
150 | 162 | } |
151 | 163 | |
@@ -154,9 +166,11 @@ discard block |
||
154 | 166 | |
155 | 167 | private function makeFactory(array $schema): GridFactoryInterface |
156 | 168 | { |
157 | - if (!empty($schema['factory']) && $this->container->has($schema['factory'])) { |
|
169 | + if (!empty($schema['factory']) && $this->container->has($schema['factory'])) |
|
170 | + { |
|
158 | 171 | $factory = $this->container->get($schema['factory']); |
159 | - if ($factory instanceof GridFactoryInterface) { |
|
172 | + if ($factory instanceof GridFactoryInterface) |
|
173 | + { |
|
160 | 174 | return $factory; |
161 | 175 | } |
162 | 176 | } |
@@ -67,9 +67,11 @@ discard block |
||
67 | 67 | */ |
68 | 68 | public function findClasses(string $annotation): iterable |
69 | 69 | { |
70 | - foreach ($this->getTargets() as $target) { |
|
70 | + foreach ($this->getTargets() as $target) |
|
71 | + { |
|
71 | 72 | $found = $this->reader->firstClassMetadata($target, $annotation); |
72 | - if ($found !== null) { |
|
73 | + if ($found !== null) |
|
74 | + { |
|
73 | 75 | yield new AnnotatedClass($target, $found); |
74 | 76 | } |
75 | 77 | } |
@@ -83,10 +85,13 @@ discard block |
||
83 | 85 | */ |
84 | 86 | public function findMethods(string $annotation): iterable |
85 | 87 | { |
86 | - foreach ($this->getTargets() as $target) { |
|
87 | - foreach ($target->getMethods() as $method) { |
|
88 | + foreach ($this->getTargets() as $target) |
|
89 | + { |
|
90 | + foreach ($target->getMethods() as $method) |
|
91 | + { |
|
88 | 92 | $found = $this->reader->firstFunctionMetadata($method, $annotation); |
89 | - if ($found !== null) { |
|
93 | + if ($found !== null) |
|
94 | + { |
|
90 | 95 | yield new AnnotatedMethod($method, $found); |
91 | 96 | } |
92 | 97 | } |
@@ -101,10 +106,13 @@ discard block |
||
101 | 106 | */ |
102 | 107 | public function findProperties(string $annotation): iterable |
103 | 108 | { |
104 | - foreach ($this->getTargets() as $target) { |
|
105 | - foreach ($target->getProperties() as $property) { |
|
109 | + foreach ($this->getTargets() as $target) |
|
110 | + { |
|
111 | + foreach ($target->getProperties() as $property) |
|
112 | + { |
|
106 | 113 | $found = $this->reader->firstPropertyMetadata($property, $annotation); |
107 | - if ($found !== null) { |
|
114 | + if ($found !== null) |
|
115 | + { |
|
108 | 116 | yield new AnnotatedProperty($property, $found); |
109 | 117 | } |
110 | 118 | } |
@@ -116,12 +124,14 @@ discard block |
||
116 | 124 | */ |
117 | 125 | private function getTargets(): iterable |
118 | 126 | { |
119 | - if ($this->targets === []) { |
|
127 | + if ($this->targets === []) |
|
128 | + { |
|
120 | 129 | yield from $this->classLocator->getClasses(); |
121 | 130 | return; |
122 | 131 | } |
123 | 132 | |
124 | - foreach ($this->targets as $target) { |
|
133 | + foreach ($this->targets as $target) |
|
134 | + { |
|
125 | 135 | yield from $this->classLocator->getClasses($target); |
126 | 136 | } |
127 | 137 | } |
@@ -34,7 +34,8 @@ discard block |
||
34 | 34 | |
35 | 35 | $this->assertCount(1, $classes); |
36 | 36 | |
37 | - foreach ($classes as $class) { |
|
37 | + foreach ($classes as $class) |
|
38 | + { |
|
38 | 39 | $this->assertSame(TestClass::class, $class->getClass()->getName()); |
39 | 40 | $this->assertSame('abc', $class->getAnnotation()->value); |
40 | 41 | } |
@@ -45,7 +46,8 @@ discard block |
||
45 | 46 | |
46 | 47 | $this->assertCount(1, $classes); |
47 | 48 | |
48 | - foreach ($classes as $class) { |
|
49 | + foreach ($classes as $class) |
|
50 | + { |
|
49 | 51 | $this->assertSame(AttributeTestClass::class, $class->getClass()->getName()); |
50 | 52 | $this->assertSame('abc', $class->getAnnotation()->value); |
51 | 53 | } |
@@ -59,7 +61,8 @@ discard block |
||
59 | 61 | |
60 | 62 | $this->assertCount(1, $props); |
61 | 63 | |
62 | - foreach ($props as $prop) { |
|
64 | + foreach ($props as $prop) |
|
65 | + { |
|
63 | 66 | $this->assertSame(TestClass::class, $prop->getClass()->getName()); |
64 | 67 | $this->assertSame('name', $prop->getProperty()->getName()); |
65 | 68 | $this->assertSame('123', $prop->getAnnotation()->id); |
@@ -71,7 +74,8 @@ discard block |
||
71 | 74 | |
72 | 75 | $this->assertCount(1, $props); |
73 | 76 | |
74 | - foreach ($props as $prop) { |
|
77 | + foreach ($props as $prop) |
|
78 | + { |
|
75 | 79 | $this->assertSame(AttributeTestClass::class, $prop->getClass()->getName()); |
76 | 80 | $this->assertSame('name', $prop->getProperty()->getName()); |
77 | 81 | $this->assertSame('123', $prop->getAnnotation()->id); |
@@ -86,7 +90,8 @@ discard block |
||
86 | 90 | |
87 | 91 | $this->assertCount(1, $methods); |
88 | 92 | |
89 | - foreach ($methods as $m) { |
|
93 | + foreach ($methods as $m) |
|
94 | + { |
|
90 | 95 | $this->assertSame(TestClass::class, $m->getClass()->getName()); |
91 | 96 | $this->assertSame('testMethod', $m->getMethod()->getName()); |
92 | 97 | $this->assertSame('/', $m->getAnnotation()->path); |
@@ -98,7 +103,8 @@ discard block |
||
98 | 103 | |
99 | 104 | $this->assertCount(1, $methods); |
100 | 105 | |
101 | - foreach ($methods as $m) { |
|
106 | + foreach ($methods as $m) |
|
107 | + { |
|
102 | 108 | $this->assertSame(AttributeTestClass::class, $m->getClass()->getName()); |
103 | 109 | $this->assertSame('testMethod', $m->getMethod()->getName()); |
104 | 110 | $this->assertSame('/', $m->getAnnotation()->path); |
@@ -49,10 +49,12 @@ |
||
49 | 49 | * @Guarded("do") |
50 | 50 | * @return string |
51 | 51 | */ |
52 | - public function do() |
|
52 | + public function do{ |
|
53 | + () |
|
53 | 54 | { |
54 | 55 | return 'ok'; |
55 | 56 | } |
57 | + } |
|
56 | 58 | |
57 | 59 | /** |
58 | 60 | * @return string |