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\Config; |
11
|
|
|
|
12
|
|
|
use FlexPHP\Generator\Domain\Builders\AbstractBuilder; |
13
|
|
|
|
14
|
|
|
final class MenuBuilder extends AbstractBuilder |
15
|
|
|
{ |
16
|
|
|
public function __construct(array $entities) |
17
|
|
|
{ |
18
|
|
|
$names = []; |
19
|
|
|
$icons = []; |
20
|
|
|
$roles = []; |
21
|
|
|
$routes = []; |
22
|
|
|
|
23
|
|
|
foreach ($entities as $entity => $icon) { |
24
|
|
|
$names[] = $this->getName($entity); |
25
|
|
|
$icons[] = $icon; |
26
|
|
|
$roles[] = $this->getRole($entity); |
27
|
|
|
$routes[] = $this->getRoute($entity); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
parent::__construct(\compact('names', 'icons', 'roles', 'routes')); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
protected function getFileTemplate(): string |
34
|
|
|
{ |
35
|
|
|
return 'Menu.php.twig'; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
protected function getPathTemplate(): string |
39
|
|
|
{ |
40
|
|
|
return \sprintf('%1$s/FlexPHP/Config', parent::getPathTemplate()); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
private function getName(string $entity): string |
44
|
|
|
{ |
45
|
|
|
return $this->getInflector()->item($entity); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
private function getRole(string $entity): array |
49
|
|
|
{ |
50
|
|
|
$name = $this->getInflector()->role($entity); |
51
|
|
|
|
52
|
|
|
return [ |
53
|
|
|
'global' => \sprintf('ROLE_USER_%s_*', $name), |
54
|
|
|
'index' => \sprintf('ROLE_USER_%s_INDEX', $name), |
55
|
|
|
'create' => \sprintf('ROLE_USER_%s_CREATE', $name), |
56
|
|
|
]; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
private function getRoute(string $entity): array |
60
|
|
|
{ |
61
|
|
|
$name = $this->getInflector()->route($entity); |
62
|
|
|
|
63
|
|
|
return [ |
64
|
|
|
'index' => \sprintf('%s.index', $name), |
65
|
|
|
'create' => \sprintf('%s.new', $name), |
66
|
|
|
]; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|