1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* File part of the Redmine User Provider bundle |
4
|
|
|
* |
5
|
|
|
* @category SymfonyBundle |
6
|
|
|
* @package GMaissa.RedmineUserProviderBundle |
7
|
|
|
* @author Guillaume Maïssa <[email protected]> |
8
|
|
|
* @copyright 2017 Guillaume Maïssa |
9
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace GMaissa\RedmineUserProviderBundle\DependencyInjection; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Config\Definition\Processor; |
15
|
|
|
use Symfony\Component\Config\FileLocator; |
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
17
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
18
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Infrastructure UserBundle Dependency Injection Class |
22
|
|
|
*/ |
23
|
|
|
class GmRedmineUserProviderExtension extends Extension |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* {@inheritdoc} |
27
|
|
|
*/ |
28
|
9 |
|
public function load(array $configs, ContainerBuilder $container) |
29
|
|
|
{ |
30
|
9 |
|
$processor = new Processor(); |
31
|
9 |
|
$configuration = new Configuration(); |
32
|
9 |
|
$config = $processor->processConfiguration($configuration, $configs); |
33
|
|
|
|
34
|
9 |
|
$container->setParameter('gm_redmine_user_provider.redmine.url', $config['redmine']['url']); |
35
|
9 |
|
$container->setParameter( |
36
|
9 |
|
'gm_redmine_user_provider.redmine.allowed_domains', |
37
|
9 |
|
$config['redmine']['allowed_domains'] |
38
|
|
|
); |
39
|
9 |
|
if (isset($config['user_class'])) { |
40
|
9 |
|
$reflection = new \ReflectionClass($config['user_class']); |
41
|
9 |
|
$userInterface = '\Symfony\Component\Security\Core\User\UserInterface'; |
42
|
9 |
|
if (!$reflection->implementsInterface($userInterface)) { |
43
|
1 |
|
throw new \InvalidArgumentException( |
44
|
|
|
sprintf( |
45
|
1 |
|
'The user class %s should implement interface "%s"', |
46
|
1 |
|
$config['user_class'], |
47
|
|
|
$userInterface |
48
|
|
|
) |
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
|
52
|
8 |
|
$container->setParameter('gm_redmine_user_provider.user_class', $config['user_class']); |
53
|
|
|
} |
54
|
|
|
|
55
|
8 |
|
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); |
56
|
|
|
|
57
|
|
|
// Load default services |
58
|
8 |
|
$loader->load('services.yml'); |
59
|
|
|
|
60
|
|
|
// Load persistence services |
61
|
8 |
|
if (isset($config['persistence_driver']) && !is_null($config['persistence_driver'])) { |
62
|
2 |
|
$loader->load(sprintf('%s.yml', $config['persistence_driver'])); |
63
|
|
|
} |
64
|
8 |
|
} |
65
|
|
|
} |
66
|
|
|
|