|
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
|
|
|
$this->createConfigs($config['groups'], $config['permissions'], $container); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Create the config services. |
|
28
|
|
|
* |
|
29
|
|
|
* @param $groups |
|
30
|
|
|
* @param ContainerBuilder $container |
|
31
|
|
|
*/ |
|
32
|
|
|
protected function createConfigs($groups, $permissions, ContainerBuilder $container) |
|
33
|
|
|
{ |
|
34
|
|
|
$configManager = $container->findDefinition(ConfigManagerInterface::class); |
|
35
|
|
|
|
|
36
|
|
|
foreach ($groups as $groupCode => $group) |
|
37
|
|
|
{ |
|
38
|
|
|
$pathPrefix = $container->getParameter('expansion.admin_groups.config.path') . "/$groupCode"; |
|
39
|
|
|
|
|
40
|
|
|
$id = 'expansion.admin_groups.config.label.' . $groupCode; |
|
41
|
|
|
$container->setDefinition($id, new ChildDefinition('expansion.admin_groups.config.label.abstract')) |
|
42
|
|
|
->replaceArgument('$path', "$pathPrefix/label") |
|
43
|
|
|
->replaceArgument('$defaultValue', $group['label']); |
|
44
|
|
|
$configManager->addMethodCall('registerConfig', [new Reference($id), $id]); |
|
45
|
|
|
|
|
46
|
|
|
$id = 'expansion.admin_groups.config.logins.' . $groupCode; |
|
47
|
|
|
$container->setDefinition($id, new ChildDefinition('expansion.admin_groups.config.logins.abstract')) |
|
48
|
|
|
->setArgument('$path', "$pathPrefix/logins") |
|
49
|
|
|
->setArgument('$defaultValue', $group['logins']); |
|
50
|
|
|
$configManager->addMethodCall('registerConfig', [new Reference($id), $id]); |
|
51
|
|
|
|
|
52
|
|
|
if ($groupCode != "master_admin") { |
|
53
|
|
|
foreach ($permissions as $permission) { |
|
54
|
|
|
$id = 'expansion.admin_groups.config.permissions.' . $groupCode . '.permission'; |
|
55
|
|
|
$container->setDefinition($id, new ChildDefinition('expansion.admin_groups.config.logins.abstract')) |
|
56
|
|
|
->setArgument('$path', "$pathPrefix/perm_perm") |
|
57
|
|
|
->setArgument('$defaultValue', $group['logins']) |
|
58
|
|
|
->setArgument('$name', "expansion_admingroups.permission.$permission.label") |
|
59
|
|
|
->setArgument('$description', "expansion_admingroups.permission.$permission.description"); |
|
60
|
|
|
$configManager->addMethodCall('registerConfig', [new Reference($id), $id]); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
} |