@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | ['view' => $view, 'source' => $source] = $this->applySorters($view, $source, $schema); |
| 109 | 109 | ['view' => $view, 'source' => $source] = $this->applyPaginator($view, $source, $schema); |
| 110 | 110 | |
| 111 | - if (!is_iterable($source)) { |
|
| 111 | + if (!is_iterable($source)){ |
|
| 112 | 112 | throw new GridViewException('GridView expects the source to be iterable after all.'); |
| 113 | 113 | } |
| 114 | 114 | |
@@ -126,11 +126,11 @@ discard block |
||
| 126 | 126 | protected function getFilters($source, GridSchema $schema): array |
| 127 | 127 | { |
| 128 | 128 | $filters = []; |
| 129 | - foreach ($this->getOptionArray(static::KEY_FILTER) ?? [] as $name => $value) { |
|
| 130 | - if ($schema->hasFilter($name)) { |
|
| 129 | + foreach ($this->getOptionArray(static::KEY_FILTER) ?? [] as $name => $value){ |
|
| 130 | + if ($schema->hasFilter($name)){ |
|
| 131 | 131 | $filter = $schema->getFilter($name)->withValue($value); |
| 132 | 132 | |
| 133 | - if ($filter !== null) { |
|
| 133 | + if ($filter !== null){ |
|
| 134 | 134 | $source = $this->compiler->compile($source, $filter); |
| 135 | 135 | $filters[$name] = $filter->getValue(); |
| 136 | 136 | } |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | |
| 143 | 143 | protected function applyCounter(GridInterface $view, $source, GridSchema $schema): array |
| 144 | 144 | { |
| 145 | - if (is_countable($source) && $this->getOption(static::KEY_FETCH_COUNT)) { |
|
| 145 | + if (is_countable($source) && $this->getOption(static::KEY_FETCH_COUNT)){ |
|
| 146 | 146 | $view = $view->withOption(GridInterface::COUNT, ($this->count)($source)); |
| 147 | 147 | } |
| 148 | 148 | |
@@ -160,11 +160,11 @@ discard block |
||
| 160 | 160 | protected function getSorters($source, GridSchema $schema): array |
| 161 | 161 | { |
| 162 | 162 | $sorters = []; |
| 163 | - foreach ($this->getOptionArray(static::KEY_SORT) ?? [] as $name => $value) { |
|
| 164 | - if ($schema->hasSorter($name)) { |
|
| 163 | + foreach ($this->getOptionArray(static::KEY_SORT) ?? [] as $name => $value){ |
|
| 164 | + if ($schema->hasSorter($name)){ |
|
| 165 | 165 | $sorter = $schema->getSorter($name)->withDirection($value); |
| 166 | 166 | |
| 167 | - if ($sorter !== null) { |
|
| 167 | + if ($sorter !== null){ |
|
| 168 | 168 | $source = $this->compiler->compile($source, $sorter); |
| 169 | 169 | $sorters[$name] = $sorter->getValue(); |
| 170 | 170 | } |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | |
| 177 | 177 | protected function applyPaginator(GridInterface $view, $source, GridSchema $schema): array |
| 178 | 178 | { |
| 179 | - if ($schema->getPaginator() !== null) { |
|
| 179 | + if ($schema->getPaginator() !== null){ |
|
| 180 | 180 | ['source' => $source, 'paginator' => $paginator] = $this->getPaginator($source, $schema); |
| 181 | 181 | $view = $view->withOption(GridInterface::PAGINATOR, $paginator); |
| 182 | 182 | } |
@@ -187,12 +187,12 @@ discard block |
||
| 187 | 187 | protected function getPaginator($source, GridSchema $schema): array |
| 188 | 188 | { |
| 189 | 189 | $paginator = $schema->getPaginator(); |
| 190 | - if (!$paginator instanceof FilterInterface) { |
|
| 190 | + if (!$paginator instanceof FilterInterface){ |
|
| 191 | 191 | throw new CompilerException('Paginator can not be null'); |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | $withValue = $paginator->withValue($this->getOption(static::KEY_PAGINATE)); |
| 195 | - if ($withValue === null) { |
|
| 195 | + if ($withValue === null){ |
|
| 196 | 196 | throw new CompilerException('Paginator can not be null'); |
| 197 | 197 | } |
| 198 | 198 | |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | protected function getOptionArray(string $option): array |
| 212 | 212 | { |
| 213 | 213 | $result = $this->getOption($option); |
| 214 | - if (!is_array($result)) { |
|
| 214 | + if (!is_array($result)){ |
|
| 215 | 215 | return []; |
| 216 | 216 | } |
| 217 | 217 | |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | */ |
| 227 | 227 | protected function getOption(string $option) |
| 228 | 228 | { |
| 229 | - if ($this->input->hasValue($option)) { |
|
| 229 | + if ($this->input->hasValue($option)){ |
|
| 230 | 230 | return $this->input->getValue($option); |
| 231 | 231 | } |
| 232 | 232 | |
@@ -108,7 +108,8 @@ discard block |
||
| 108 | 108 | ['view' => $view, 'source' => $source] = $this->applySorters($view, $source, $schema); |
| 109 | 109 | ['view' => $view, 'source' => $source] = $this->applyPaginator($view, $source, $schema); |
| 110 | 110 | |
| 111 | - if (!is_iterable($source)) { |
|
| 111 | + if (!is_iterable($source)) |
|
| 112 | + { |
|
| 112 | 113 | throw new GridViewException('GridView expects the source to be iterable after all.'); |
| 113 | 114 | } |
| 114 | 115 | |
@@ -126,11 +127,14 @@ discard block |
||
| 126 | 127 | protected function getFilters($source, GridSchema $schema): array |
| 127 | 128 | { |
| 128 | 129 | $filters = []; |
| 129 | - foreach ($this->getOptionArray(static::KEY_FILTER) ?? [] as $name => $value) { |
|
| 130 | - if ($schema->hasFilter($name)) { |
|
| 130 | + foreach ($this->getOptionArray(static::KEY_FILTER) ?? [] as $name => $value) |
|
| 131 | + { |
|
| 132 | + if ($schema->hasFilter($name)) |
|
| 133 | + { |
|
| 131 | 134 | $filter = $schema->getFilter($name)->withValue($value); |
| 132 | 135 | |
| 133 | - if ($filter !== null) { |
|
| 136 | + if ($filter !== null) |
|
| 137 | + { |
|
| 134 | 138 | $source = $this->compiler->compile($source, $filter); |
| 135 | 139 | $filters[$name] = $filter->getValue(); |
| 136 | 140 | } |
@@ -142,7 +146,8 @@ discard block |
||
| 142 | 146 | |
| 143 | 147 | protected function applyCounter(GridInterface $view, $source, GridSchema $schema): array |
| 144 | 148 | { |
| 145 | - if (is_countable($source) && $this->getOption(static::KEY_FETCH_COUNT)) { |
|
| 149 | + if (is_countable($source) && $this->getOption(static::KEY_FETCH_COUNT)) |
|
| 150 | + { |
|
| 146 | 151 | $view = $view->withOption(GridInterface::COUNT, ($this->count)($source)); |
| 147 | 152 | } |
| 148 | 153 | |
@@ -160,11 +165,14 @@ discard block |
||
| 160 | 165 | protected function getSorters($source, GridSchema $schema): array |
| 161 | 166 | { |
| 162 | 167 | $sorters = []; |
| 163 | - foreach ($this->getOptionArray(static::KEY_SORT) ?? [] as $name => $value) { |
|
| 164 | - if ($schema->hasSorter($name)) { |
|
| 168 | + foreach ($this->getOptionArray(static::KEY_SORT) ?? [] as $name => $value) |
|
| 169 | + { |
|
| 170 | + if ($schema->hasSorter($name)) |
|
| 171 | + { |
|
| 165 | 172 | $sorter = $schema->getSorter($name)->withDirection($value); |
| 166 | 173 | |
| 167 | - if ($sorter !== null) { |
|
| 174 | + if ($sorter !== null) |
|
| 175 | + { |
|
| 168 | 176 | $source = $this->compiler->compile($source, $sorter); |
| 169 | 177 | $sorters[$name] = $sorter->getValue(); |
| 170 | 178 | } |
@@ -176,7 +184,8 @@ discard block |
||
| 176 | 184 | |
| 177 | 185 | protected function applyPaginator(GridInterface $view, $source, GridSchema $schema): array |
| 178 | 186 | { |
| 179 | - if ($schema->getPaginator() !== null) { |
|
| 187 | + if ($schema->getPaginator() !== null) |
|
| 188 | + { |
|
| 180 | 189 | ['source' => $source, 'paginator' => $paginator] = $this->getPaginator($source, $schema); |
| 181 | 190 | $view = $view->withOption(GridInterface::PAGINATOR, $paginator); |
| 182 | 191 | } |
@@ -187,12 +196,14 @@ discard block |
||
| 187 | 196 | protected function getPaginator($source, GridSchema $schema): array |
| 188 | 197 | { |
| 189 | 198 | $paginator = $schema->getPaginator(); |
| 190 | - if (!$paginator instanceof FilterInterface) { |
|
| 199 | + if (!$paginator instanceof FilterInterface) |
|
| 200 | + { |
|
| 191 | 201 | throw new CompilerException('Paginator can not be null'); |
| 192 | 202 | } |
| 193 | 203 | |
| 194 | 204 | $withValue = $paginator->withValue($this->getOption(static::KEY_PAGINATE)); |
| 195 | - if ($withValue === null) { |
|
| 205 | + if ($withValue === null) |
|
| 206 | + { |
|
| 196 | 207 | throw new CompilerException('Paginator can not be null'); |
| 197 | 208 | } |
| 198 | 209 | |
@@ -211,7 +222,8 @@ discard block |
||
| 211 | 222 | protected function getOptionArray(string $option): array |
| 212 | 223 | { |
| 213 | 224 | $result = $this->getOption($option); |
| 214 | - if (!is_array($result)) { |
|
| 225 | + if (!is_array($result)) |
|
| 226 | + { |
|
| 215 | 227 | return []; |
| 216 | 228 | } |
| 217 | 229 | |
@@ -226,7 +238,8 @@ discard block |
||
| 226 | 238 | */ |
| 227 | 239 | protected function getOption(string $option) |
| 228 | 240 | { |
| 229 | - if ($this->input->hasValue($option)) { |
|
| 241 | + if ($this->input->hasValue($option)) |
|
| 242 | + { |
|
| 230 | 243 | return $this->input->getValue($option); |
| 231 | 244 | } |
| 232 | 245 | |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | GridResponseInterface $response, |
| 49 | 49 | ContainerInterface $container, |
| 50 | 50 | GridFactory $gridFactory |
| 51 | - ) { |
|
| 51 | + ){ |
|
| 52 | 52 | $this->response = $response; |
| 53 | 53 | $this->container = $container; |
| 54 | 54 | $this->gridFactory = $gridFactory; |
@@ -66,14 +66,14 @@ discard block |
||
| 66 | 66 | { |
| 67 | 67 | $result = $core->callAction($controller, $action, $parameters); |
| 68 | 68 | |
| 69 | - if (is_iterable($result)) { |
|
| 69 | + if (is_iterable($result)){ |
|
| 70 | 70 | $schema = $this->getSchema($controller, $action); |
| 71 | - if ($schema !== null) { |
|
| 71 | + if ($schema !== null){ |
|
| 72 | 72 | $grid = $this->makeFactory($schema) |
| 73 | 73 | ->withDefaults($schema['defaults']) |
| 74 | 74 | ->create($result, $schema['grid']); |
| 75 | 75 | |
| 76 | - if ($schema['view'] !== null) { |
|
| 76 | + if ($schema['view'] !== null){ |
|
| 77 | 77 | $grid = $grid->withView($schema['view']); |
| 78 | 78 | } |
| 79 | 79 | |
@@ -93,14 +93,14 @@ discard block |
||
| 93 | 93 | private function getSchema(string $controller, string $action): ?array |
| 94 | 94 | { |
| 95 | 95 | $key = sprintf('%s:%s', $controller, $action); |
| 96 | - if (array_key_exists($key, $this->cache)) { |
|
| 96 | + if (array_key_exists($key, $this->cache)){ |
|
| 97 | 97 | return $this->cache[$key]; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | $this->cache[$key] = null; |
| 101 | - try { |
|
| 101 | + try{ |
|
| 102 | 102 | $method = new \ReflectionMethod($controller, $action); |
| 103 | - } catch (\ReflectionException $e) { |
|
| 103 | + }catch (\ReflectionException $e){ |
|
| 104 | 104 | return null; |
| 105 | 105 | } |
| 106 | 106 | |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | |
| 109 | 109 | /** @var DataGrid $dataGrid */ |
| 110 | 110 | $dataGrid = $reader->getMethodAnnotation($method, DataGrid::class); |
| 111 | - if ($dataGrid === null) { |
|
| 111 | + if ($dataGrid === null){ |
|
| 112 | 112 | return null; |
| 113 | 113 | } |
| 114 | 114 | |
@@ -129,19 +129,19 @@ discard block |
||
| 129 | 129 | 'factory' => $dataGrid->factory, |
| 130 | 130 | ]; |
| 131 | 131 | |
| 132 | - if (is_string($schema['view'])) { |
|
| 132 | + if (is_string($schema['view'])){ |
|
| 133 | 133 | $schema['view'] = $this->container->get($schema['view']); |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - if ($schema['defaults'] === [] && method_exists($schema['grid'], 'getDefaults')) { |
|
| 136 | + if ($schema['defaults'] === [] && method_exists($schema['grid'], 'getDefaults')){ |
|
| 137 | 137 | $schema['defaults'] = $schema['grid']->getDefaults(); |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - if ($schema['options'] === [] && method_exists($schema['grid'], 'getOptions')) { |
|
| 140 | + if ($schema['options'] === [] && method_exists($schema['grid'], 'getOptions')){ |
|
| 141 | 141 | $schema['options'] = $schema['grid']->getOptions(); |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - if ($schema['view'] === null && is_callable($schema['grid'])) { |
|
| 144 | + if ($schema['view'] === null && is_callable($schema['grid'])){ |
|
| 145 | 145 | $schema['view'] = $schema['grid']; |
| 146 | 146 | } |
| 147 | 147 | |
@@ -150,9 +150,9 @@ discard block |
||
| 150 | 150 | |
| 151 | 151 | private function makeFactory(array $schema): GridFactoryInterface |
| 152 | 152 | { |
| 153 | - if (!empty($schema['factory']) && $this->container->has($schema['factory'])) { |
|
| 153 | + if (!empty($schema['factory']) && $this->container->has($schema['factory'])){ |
|
| 154 | 154 | $factory = $this->container->get($schema['factory']); |
| 155 | - if ($factory instanceof GridFactoryInterface) { |
|
| 155 | + if ($factory instanceof GridFactoryInterface){ |
|
| 156 | 156 | return $factory; |
| 157 | 157 | } |
| 158 | 158 | } |
@@ -66,14 +66,17 @@ discard block |
||
| 66 | 66 | { |
| 67 | 67 | $result = $core->callAction($controller, $action, $parameters); |
| 68 | 68 | |
| 69 | - if (is_iterable($result)) { |
|
| 69 | + if (is_iterable($result)) |
|
| 70 | + { |
|
| 70 | 71 | $schema = $this->getSchema($controller, $action); |
| 71 | - if ($schema !== null) { |
|
| 72 | + if ($schema !== null) |
|
| 73 | + { |
|
| 72 | 74 | $grid = $this->makeFactory($schema) |
| 73 | 75 | ->withDefaults($schema['defaults']) |
| 74 | 76 | ->create($result, $schema['grid']); |
| 75 | 77 | |
| 76 | - if ($schema['view'] !== null) { |
|
| 78 | + if ($schema['view'] !== null) |
|
| 79 | + { |
|
| 77 | 80 | $grid = $grid->withView($schema['view']); |
| 78 | 81 | } |
| 79 | 82 | |
@@ -93,14 +96,18 @@ discard block |
||
| 93 | 96 | private function getSchema(string $controller, string $action): ?array |
| 94 | 97 | { |
| 95 | 98 | $key = sprintf('%s:%s', $controller, $action); |
| 96 | - if (array_key_exists($key, $this->cache)) { |
|
| 99 | + if (array_key_exists($key, $this->cache)) |
|
| 100 | + { |
|
| 97 | 101 | return $this->cache[$key]; |
| 98 | 102 | } |
| 99 | 103 | |
| 100 | 104 | $this->cache[$key] = null; |
| 101 | - try { |
|
| 105 | + try |
|
| 106 | + { |
|
| 102 | 107 | $method = new \ReflectionMethod($controller, $action); |
| 103 | - } catch (\ReflectionException $e) { |
|
| 108 | + } |
|
| 109 | + catch (\ReflectionException $e) |
|
| 110 | + { |
|
| 104 | 111 | return null; |
| 105 | 112 | } |
| 106 | 113 | |
@@ -108,7 +115,8 @@ discard block |
||
| 108 | 115 | |
| 109 | 116 | /** @var DataGrid $dataGrid */ |
| 110 | 117 | $dataGrid = $reader->getMethodAnnotation($method, DataGrid::class); |
| 111 | - if ($dataGrid === null) { |
|
| 118 | + if ($dataGrid === null) |
|
| 119 | + { |
|
| 112 | 120 | return null; |
| 113 | 121 | } |
| 114 | 122 | |
@@ -129,19 +137,23 @@ discard block |
||
| 129 | 137 | 'factory' => $dataGrid->factory, |
| 130 | 138 | ]; |
| 131 | 139 | |
| 132 | - if (is_string($schema['view'])) { |
|
| 140 | + if (is_string($schema['view'])) |
|
| 141 | + { |
|
| 133 | 142 | $schema['view'] = $this->container->get($schema['view']); |
| 134 | 143 | } |
| 135 | 144 | |
| 136 | - if ($schema['defaults'] === [] && method_exists($schema['grid'], 'getDefaults')) { |
|
| 145 | + if ($schema['defaults'] === [] && method_exists($schema['grid'], 'getDefaults')) |
|
| 146 | + { |
|
| 137 | 147 | $schema['defaults'] = $schema['grid']->getDefaults(); |
| 138 | 148 | } |
| 139 | 149 | |
| 140 | - if ($schema['options'] === [] && method_exists($schema['grid'], 'getOptions')) { |
|
| 150 | + if ($schema['options'] === [] && method_exists($schema['grid'], 'getOptions')) |
|
| 151 | + { |
|
| 141 | 152 | $schema['options'] = $schema['grid']->getOptions(); |
| 142 | 153 | } |
| 143 | 154 | |
| 144 | - if ($schema['view'] === null && is_callable($schema['grid'])) { |
|
| 155 | + if ($schema['view'] === null && is_callable($schema['grid'])) |
|
| 156 | + { |
|
| 145 | 157 | $schema['view'] = $schema['grid']; |
| 146 | 158 | } |
| 147 | 159 | |
@@ -150,9 +162,11 @@ discard block |
||
| 150 | 162 | |
| 151 | 163 | private function makeFactory(array $schema): GridFactoryInterface |
| 152 | 164 | { |
| 153 | - if (!empty($schema['factory']) && $this->container->has($schema['factory'])) { |
|
| 165 | + if (!empty($schema['factory']) && $this->container->has($schema['factory'])) |
|
| 166 | + { |
|
| 154 | 167 | $factory = $this->container->get($schema['factory']); |
| 155 | - if ($factory instanceof GridFactoryInterface) { |
|
| 168 | + if ($factory instanceof GridFactoryInterface) |
|
| 169 | + { |
|
| 156 | 170 | return $factory; |
| 157 | 171 | } |
| 158 | 172 | } |