1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/* |
3
|
|
|
* This file is part of FlexPHP. |
4
|
|
|
* |
5
|
|
|
* (c) Freddie Gar <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
6 |
|
*/ |
10
|
|
|
namespace FlexPHP\Generator\Domain\Builders\Controller; |
11
|
6 |
|
|
12
|
6 |
|
use FlexPHP\Generator\Domain\Builders\AbstractBuilder; |
13
|
6 |
|
use FlexPHP\Schema\Constants\Action; |
14
|
6 |
|
use FlexPHP\Schema\SchemaInterface; |
15
|
|
|
|
16
|
|
|
final class ControllerBuilder extends AbstractBuilder |
17
|
|
|
{ |
18
|
6 |
|
public function __construct(SchemaInterface $schema, array $actions) |
19
|
6 |
|
{ |
20
|
|
|
$entity = $this->getInflector()->entity($schema->name()); |
21
|
6 |
|
$route = $this->getInflector()->route($schema->name()); |
22
|
|
|
$fkFns = $this->getFkFunctions($schema->fkRelations()); |
23
|
6 |
|
$header = self::getHeaderFile(); |
24
|
|
|
$hasFilter = $schema->hasAction(Action::FILTER); |
25
|
|
|
unset($actions['login']); |
26
|
6 |
|
|
27
|
|
|
foreach ($actions as $action => $builder) { |
28
|
6 |
|
$actions[$this->getInflector()->pascalAction($action)] = $builder; |
29
|
|
|
unset($actions[$action]); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
parent::__construct(\compact('entity', 'actions', 'route', 'fkFns', 'header', 'hasFilter')); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
protected function getFileTemplate(): string |
36
|
|
|
{ |
37
|
|
|
return 'Controller.php.twig'; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
protected function getPathTemplate(): string |
41
|
|
|
{ |
42
|
|
|
return \sprintf('%1$s/Symfony/src/Controller', parent::getPathTemplate()); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|