1 | <?php |
||
21 | class ScopePolicyCompilerPass implements CompilerPassInterface |
||
22 | { |
||
23 | /** |
||
24 | * {@inheritdoc} |
||
25 | */ |
||
26 | public function process(ContainerBuilder $container) |
||
27 | { |
||
28 | if (!$container->hasDefinition(ScopePolicyManager::class)) { |
||
29 | return; |
||
30 | } |
||
31 | |||
32 | $definition = $container->getDefinition(ScopePolicyManager::class); |
||
33 | $default = $container->getParameter('oauth2_server.scope.policy.by_default'); |
||
34 | |||
35 | $taggedServices = $container->findTaggedServiceIds('oauth2_server_scope_policy'); |
||
36 | $default_found = false; |
||
37 | $policy_names = []; |
||
38 | foreach ($taggedServices as $id => $tags) { |
||
39 | foreach ($tags as $attributes) { |
||
40 | if (!array_key_exists('policy_name', $attributes)) { |
||
41 | throw new \InvalidArgumentException(sprintf('The scope policy "%s" does not have any "policy_name" attribute.', $id)); |
||
42 | } |
||
43 | $is_default = $default === $attributes['policy_name']; |
||
44 | $policy_names[] = $attributes['policy_name']; |
||
45 | if (true === $is_default) { |
||
46 | $default_found = true; |
||
47 | } |
||
48 | $definition->addMethodCall('add', [new Reference($id), $is_default]); |
||
49 | } |
||
50 | } |
||
51 | |||
52 | if (!$default_found) { |
||
53 | throw new \InvalidArgumentException(sprintf('Unable to find the scope policy "%s". Available policies are: %s.', $default, implode(', ', $policy_names))); |
||
57 |