|
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
|
|
|
*/ |
|
10
|
|
|
namespace FlexPHP\Generator\Domain\Builders\Template; |
|
11
|
|
|
|
|
12
|
|
|
use FlexPHP\Generator\Domain\Builders\AbstractBuilder; |
|
13
|
|
|
use FlexPHP\Schema\SchemaAttributeInterface; |
|
14
|
|
|
use FlexPHP\Schema\SchemaInterface; |
|
15
|
|
|
|
|
16
|
|
|
final class TemplateBuilder extends AbstractBuilder |
|
17
|
|
|
{ |
|
18
|
|
|
private string $action; |
|
19
|
|
|
|
|
20
|
|
|
public function __construct(SchemaInterface $schema, string $action) |
|
21
|
|
|
{ |
|
22
|
|
|
$this->action = $action; |
|
23
|
|
|
|
|
24
|
|
|
$route = $this->getInflector()->route($schema->name()); |
|
25
|
|
|
$item = $this->getInflector()->item($schema->name()); |
|
26
|
|
|
$items = $this->getInflector()->items($schema->name()); |
|
27
|
|
|
$fkRels = $this->getFkRelations($schema->fkRelations()); |
|
28
|
|
|
$pkName = $this->getInflector()->camelProperty($schema->pkName()); |
|
29
|
|
|
$properties = \array_reduce( |
|
30
|
|
|
$schema->attributes(), |
|
31
|
|
|
function (array $result, SchemaAttributeInterface $property) { |
|
32
|
|
|
$result[$this->getInflector()->camelProperty($property->name())] = $property; |
|
33
|
|
|
|
|
34
|
|
|
return $result; |
|
35
|
|
|
}, |
|
36
|
|
|
[] |
|
37
|
|
|
); |
|
38
|
|
|
|
|
39
|
|
|
parent::__construct(\compact('route', 'item', 'items', 'properties', 'fkRels', 'pkName')); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
protected function getFileTemplate(): string |
|
43
|
|
|
{ |
|
44
|
|
|
return $this->action . '.html.twig'; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
protected function getPathTemplate(): string |
|
48
|
|
|
{ |
|
49
|
|
|
return \sprintf('%1$s/Symfony/templates', parent::getPathTemplate()); |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|