1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Happyr\GoogleSiteAuthenticatorBundle\DependencyInjection; |
4
|
|
|
|
5
|
|
|
use Happyr\GoogleSiteAuthenticatorBundle\Model\TokenConfig; |
6
|
|
|
use Happyr\GoogleSiteAuthenticatorBundle\Service\ClientProvider; |
7
|
|
|
use Symfony\Component\Config\FileLocator; |
8
|
|
|
use Symfony\Component\DependencyInjection\ChildDefinition; |
9
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
10
|
|
|
use Symfony\Component\DependencyInjection\DefinitionDecorator; |
11
|
|
|
use Symfony\Component\DependencyInjection\Loader; |
12
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
13
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
14
|
|
|
|
15
|
|
|
class HappyrGoogleSiteAuthenticatorExtension extends Extension |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @param array $configs |
19
|
2 |
|
* @param ContainerBuilder $container |
20
|
|
|
*/ |
21
|
2 |
|
public function load(array $configs, ContainerBuilder $container) |
22
|
2 |
|
{ |
23
|
|
|
$configuration = new Configuration(); |
24
|
2 |
|
$config = $this->processConfiguration($configuration, $configs); |
25
|
2 |
|
|
26
|
|
|
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
27
|
|
|
$loader->load('services.yml'); |
28
|
2 |
|
|
29
|
2 |
|
// Configure the correct PSR-6 cache |
30
|
|
|
$clientProvider = $container->getDefinition(ClientProvider::class); |
31
|
|
|
$clientProvider->replaceArgument(1, new Reference($config['cache_service'])); |
32
|
2 |
|
|
33
|
2 |
|
// Configure TokenConfig |
34
|
|
|
$definition = $container->getDefinition(TokenConfig::class); |
35
|
|
|
$definition->replaceArgument(0, $config['tokens']); |
36
|
2 |
|
|
37
|
2 |
|
// make sure we shortcut the service name |
38
|
2 |
|
$decorator = new ChildDefinition('happyr.google_site_authenticator.client'); |
39
|
2 |
|
foreach ($config['tokens'] as $name => $tokenConfig) { |
40
|
|
|
$service = $container->setDefinition('google.client.'.$name, $decorator); |
41
|
|
|
$service->replaceArgument(0, $name); |
42
|
|
|
} |
43
|
2 |
|
|
44
|
2 |
|
// set an alias for happyr.google_site_authenticator.client |
45
|
|
|
$container->setAlias('google.client', 'happyr.google_site_authenticator.client'); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|