|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace eXpansion\Framework\AdminGroups\DependencyInjection\Compiler; |
|
4
|
|
|
|
|
5
|
|
|
use eXpansion\Framework\Config\Services\ConfigManagerInterface; |
|
6
|
|
|
use Symfony\Component\DependencyInjection\ChildDefinition; |
|
7
|
|
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
9
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class ConfigPass |
|
13
|
|
|
* |
|
14
|
|
|
* @author de Cramer Oliver<[email protected]> |
|
15
|
|
|
* @copyright 2018 Smile |
|
16
|
|
|
* @package eXpansion\Framework\AdminGroups\DependencyInjection\Compiler |
|
17
|
|
|
*/ |
|
18
|
|
|
class ConfigPass implements CompilerPassInterface |
|
19
|
|
|
{ |
|
20
|
|
|
public function process(ContainerBuilder $container) |
|
21
|
|
|
{ |
|
22
|
|
|
$config = $container->getParameter('expansion.admin_groups.raw.configs'); |
|
23
|
|
|
|
|
24
|
|
|
// Replace permissions read in config with those coming for service declarations |
|
25
|
|
|
$permissions = $this->loadPermissions($container); |
|
26
|
|
|
$config['permissions'] = $permissions; |
|
27
|
|
|
$container->setParameter('expansion.admin_groups.raw.configs', $config); |
|
28
|
|
|
|
|
29
|
|
|
$this->createConfigs($config['groups'], $config['permissions'], $container); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param ContainerBuilder $container |
|
34
|
|
|
* |
|
35
|
|
|
* @return array |
|
36
|
|
|
*/ |
|
37
|
|
|
protected function loadPermissions(ContainerBuilder $container) |
|
38
|
|
|
{ |
|
39
|
|
|
$permissions = []; |
|
40
|
|
|
|
|
41
|
|
|
$permissionServices = $container->findTaggedServiceIds("exp.permission"); |
|
42
|
|
|
foreach ($permissionServices as $tags) { |
|
43
|
|
|
foreach ($tags as $attributes) { |
|
44
|
|
|
$permissions[] = $attributes['permission']; |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
return $permissions; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Create the config services. |
|
53
|
|
|
* |
|
54
|
|
|
* @param $groups |
|
55
|
|
|
* @param ContainerBuilder $container |
|
56
|
|
|
*/ |
|
57
|
|
|
protected function createConfigs($groups, $permissions, ContainerBuilder $container) |
|
58
|
|
|
{ |
|
59
|
|
|
$configManager = $container->findDefinition(ConfigManagerInterface::class); |
|
60
|
|
|
|
|
61
|
|
|
foreach ($groups as $groupCode => $group) |
|
62
|
|
|
{ |
|
63
|
|
|
$pathPrefix = $container->getParameter('expansion.admin_groups.config.path') . "/$groupCode"; |
|
64
|
|
|
|
|
65
|
|
|
$id = 'expansion.admin_groups.config.label.' . $groupCode; |
|
66
|
|
|
$container->setDefinition($id, new ChildDefinition('expansion.admin_groups.config.label.abstract')) |
|
67
|
|
|
->replaceArgument('$path', "$pathPrefix/label") |
|
68
|
|
|
->replaceArgument('$defaultValue', $group['label']); |
|
69
|
|
|
$configManager->addMethodCall('registerConfig', [new Reference($id), $id]); |
|
70
|
|
|
|
|
71
|
|
|
$id = 'expansion.admin_groups.config.logins.' . $groupCode; |
|
72
|
|
|
$container->setDefinition($id, new ChildDefinition('expansion.admin_groups.config.logins.abstract')) |
|
73
|
|
|
->setArgument('$path', "$pathPrefix/logins") |
|
74
|
|
|
->setArgument('$defaultValue', $group['logins']); |
|
75
|
|
|
$configManager->addMethodCall('registerConfig', [new Reference($id), $id]); |
|
76
|
|
|
|
|
77
|
|
|
if ($groupCode != "master_admin") { |
|
78
|
|
|
foreach ($permissions as $permission) { |
|
79
|
|
|
$id = 'expansion.admin_groups.config.permissions.' . $groupCode . ".$permission"; |
|
80
|
|
|
$container->setDefinition($id, new ChildDefinition('expansion.admin_groups.config.permissions.abstract')) |
|
81
|
|
|
->setArgument('$path', "$pathPrefix/perm_$permission") |
|
82
|
|
|
->setArgument('$defaultValue', in_array($permission, $group['permissions'])) |
|
83
|
|
|
->setArgument('$name', "expansion_admin_groups.permission.$permission.label") |
|
84
|
|
|
->setArgument('$description', "expansion_admin_groups.permission.$permission.description"); |
|
85
|
|
|
$configManager->addMethodCall('registerConfig', [new Reference($id), $id]); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|