1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the DoyoUserBundle project. |
5
|
|
|
* |
6
|
|
|
* (c) Anthonius Munthi <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Doyo\UserBundle\DependencyInjection; |
15
|
|
|
|
16
|
|
|
use Symfony\Component\Config\ConfigCache; |
17
|
|
|
use Symfony\Component\Config\Definition\Processor; |
18
|
|
|
use Symfony\Component\Config\FileLocator; |
19
|
|
|
use Symfony\Component\Config\Resource\FileResource; |
20
|
|
|
use Symfony\Component\DependencyInjection\Alias; |
21
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
22
|
|
|
use Symfony\Component\DependencyInjection\Extension\Extension; |
23
|
|
|
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; |
24
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
25
|
|
|
use Symfony\Component\DependencyInjection\Reference; |
26
|
|
|
|
27
|
|
|
class DoyoUserExtension extends Extension implements PrependExtensionInterface |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var array |
31
|
|
|
*/ |
32
|
|
|
private static $doctrineDrivers = [ |
33
|
|
|
'orm' => [ |
34
|
|
|
'registry' => 'doctrine', |
35
|
|
|
'tag' => 'doctrine.event_subscriber', |
36
|
|
|
], |
37
|
|
|
'mongodb' => [ |
38
|
|
|
'registry' => 'doctrine_mongodb', |
39
|
|
|
'tag' => 'doctrine_mongodb.odm.event_subscriber', |
40
|
|
|
], |
41
|
|
|
'couchdb' => [ |
42
|
|
|
'registry' => 'doctrine_couchdb', |
43
|
|
|
'tag' => 'doctrine_couchdb.event_subscriber', |
44
|
|
|
'listener_class' => 'Doyo\UserBundle\Bridge\CouchDB\UserListener', |
45
|
|
|
], |
46
|
|
|
]; |
47
|
|
|
|
48
|
|
|
public function prepend(ContainerBuilder $container) |
49
|
|
|
{ |
50
|
|
|
} |
51
|
|
|
|
52
|
2 |
|
public function load(array $configs, ContainerBuilder $container) |
53
|
|
|
{ |
54
|
2 |
|
$processor = new Processor(); |
55
|
2 |
|
$configuration = new Configuration(); |
56
|
|
|
|
57
|
2 |
|
$config = $processor->processConfiguration($configuration, $configs); |
58
|
|
|
|
59
|
2 |
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
60
|
|
|
|
61
|
2 |
|
$loader->load('util.xml'); |
62
|
2 |
|
$loader->load('command.xml'); |
63
|
|
|
|
64
|
2 |
|
$this->loadDbDriver($loader, $container, $config); |
65
|
|
|
|
66
|
2 |
|
$container->setParameter('doyo_user.user_class', $config['user_class']); |
67
|
2 |
|
$container->setParameter('doyo_user.model_manager_name', $config['model_manager_name']); |
68
|
2 |
|
$container->setParameter('doyo_user.api_platform', $config['api_platform']); |
69
|
2 |
|
$container->setParameter('doyo_user.backend_type_orm', true); |
70
|
2 |
|
$container->setParameter('doyo_user.storage', $config['db_driver']); |
71
|
|
|
|
72
|
2 |
|
$container->setAlias('doyo_user.util.email_canonicalizer', $config['service']['email_canonicalizer']); |
73
|
2 |
|
$container->setAlias('doyo_user.util.username_canonicalizer', $config['service']['username_canonicalizer']); |
74
|
2 |
|
$container->setAlias('doyo_user.util.password_updater', $config['service']['password_updater']); |
75
|
2 |
|
$container->setAlias('doyo_user.user_manager', $config['service']['user_manager']); |
76
|
|
|
|
77
|
2 |
|
if ($config['api_platform']) { |
78
|
1 |
|
$loader->load('api-platform.xml'); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
2 |
|
private function loadDbDriver(XmlFileLoader $loader, ContainerBuilder $container, $config) |
83
|
|
|
{ |
84
|
2 |
|
if ('custom' !== $config['db_driver']) { |
85
|
2 |
|
if (isset(self::$doctrineDrivers[$config['db_driver']])) { |
86
|
2 |
|
$loader->load('doctrine.xml'); |
87
|
2 |
|
$container->setAlias('doyo_user.doctrine_registry', new Alias(self::$doctrineDrivers[$config['db_driver']]['registry'], false)); |
88
|
|
|
} else { |
89
|
|
|
$loader->load(sprintf('%s.xml', $config['db_driver'])); |
90
|
|
|
} |
91
|
2 |
|
$container->setParameter($this->getAlias() . '.backend_type_' . $config['db_driver'], true); |
92
|
|
|
} |
93
|
|
|
|
94
|
2 |
|
if (isset(self::$doctrineDrivers[$config['db_driver']])) { |
95
|
2 |
|
$definition = $container->getDefinition('doyo_user.object_manager'); |
96
|
2 |
|
$definition->setFactory([new Reference('doyo_user.doctrine_registry'), 'getManager']); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|