Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 16 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ControllerCommand | |
0.00% |
0 / 16 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
| bakeController | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
| getSearchFields | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | declare(strict_types=1); |
| 3 | |
| 4 | namespace AdminTheme\Command\Bake; |
| 5 | |
| 6 | use Bake\Command\ControllerCommand as BakeControllerCommand; |
| 7 | use Cake\Console\Arguments; |
| 8 | use Cake\Console\ConsoleIo; |
| 9 | |
| 10 | class ControllerCommand extends BakeControllerCommand |
| 11 | { |
| 12 | public function bakeController(string $controllerName, array $data, Arguments $args, ConsoleIo $io): void |
| 13 | { |
| 14 | $io->quiet(sprintf('Baking controller class for %s...', $controllerName)); |
| 15 | |
| 16 | $data['actions'] = ['index', 'view', 'add', 'edit', 'delete']; |
| 17 | $data['searchFields'] = $this->getSearchFields($data['modelObj']); |
| 18 | |
| 19 | $contents = $this->createTemplateRenderer() |
| 20 | ->set($data) |
| 21 | ->generate('AdminTheme.Controller/controller'); |
| 22 | |
| 23 | $path = $this->getPath($args); |
| 24 | $filename = $path . $controllerName . 'Controller.php'; |
| 25 | $io->createFile($filename, $contents, $this->force); |
| 26 | } |
| 27 | |
| 28 | protected function getSearchFields($modelObj): array |
| 29 | { |
| 30 | $schema = $modelObj->getSchema(); |
| 31 | $searchFields = []; |
| 32 | |
| 33 | foreach ($schema->columns() as $field) { |
| 34 | $type = $schema->getColumnType($field); |
| 35 | if (in_array($type, ['string', 'text'])) { |
| 36 | $searchFields[] = $field; |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | return $searchFields; |
| 41 | } |
| 42 | } |