-
Notifications
You must be signed in to change notification settings - Fork 446
Expand file tree
/
Copy pathGrantExtensionsCompilerPass.php
More file actions
47 lines (40 loc) · 1.74 KB
/
GrantExtensionsCompilerPass.php
File metadata and controls
47 lines (40 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
declare(strict_types=1);
/*
* This file is part of the FOSOAuthServerBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace FOS\OAuthServerBundle\DependencyInjection\Compiler;
use FOS\OAuthServerBundle\Storage\GrantExtensionDispatcherInterface;
use ReflectionClass;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Reference;
/**
* @author Adrien Brault <adrien.brault@gmail.com>
*/
class GrantExtensionsCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container): void
{
$storageDefinition = $container->findDefinition('fos_oauth_server.storage');
$className = $container->getParameterBag()->resolveValue($storageDefinition->getClass());
$storageClass = new ReflectionClass($className);
if (!$storageClass->implementsInterface(GrantExtensionDispatcherInterface::class)) {
return;
}
foreach ($container->findTaggedServiceIds('fos_oauth_server.grant_extension') as $id => $tags) {
foreach ($tags as $tag) {
if (empty($tag['uri'])) {
throw new InvalidArgumentException(sprintf('Service "%s" must define the "uri" attribute on "fos_oauth_server.grant_extension" tags.', $id));
}
$storageDefinition->addMethodCall('setGrantExtension', [$tag['uri'], new Reference($id)]);
}
}
}
}