1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Gbere\SimpleAuth\DependencyInjection; |
6
|
|
|
|
7
|
|
|
use Exception; |
8
|
|
|
use Symfony\Component\Config\FileLocator; |
9
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
10
|
|
|
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; |
11
|
|
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; |
12
|
|
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension; |
13
|
|
|
|
14
|
|
|
class GbereSimpleAuthExtension extends Extension implements PrependExtensionInterface |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @throws Exception |
18
|
|
|
*/ |
19
|
|
|
public function load(array $configs, ContainerBuilder $container): void |
20
|
|
|
{ |
21
|
|
|
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
22
|
|
|
$loader->load('services.yaml'); |
23
|
|
|
|
24
|
|
|
$configuration = $this->getConfiguration($configs, $container); |
25
|
|
|
$config = $this->processConfiguration($configuration, $configs); |
|
|
|
|
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function prepend(ContainerBuilder $container): void |
29
|
|
|
{ |
30
|
|
|
if ('test' === $container->getParameter('kernel.environment')) { |
31
|
|
|
// https://github.com/symfony/symfony/issues/24461#issuecomment-355839669 |
32
|
|
|
$extensionConfigsRefl = new \ReflectionProperty(ContainerBuilder::class, 'extensionConfigs'); |
33
|
|
|
$extensionConfigsRefl->setAccessible(true); |
34
|
|
|
$extensionConfigs = $extensionConfigsRefl->getValue($container); |
35
|
|
|
$extensionConfigs['security'][0]['access_control'] = array_merge([ |
36
|
|
|
['path' => '^/gbere-auth-test-role-admin', 'role' => 'ROLE_ADMIN'], |
37
|
|
|
['path' => '^/gbere-auth-test-role-user', 'role' => 'ROLE_USER'], ], |
38
|
|
|
$extensionConfigs['security'][0]['access_control'] |
39
|
|
|
); |
40
|
|
|
|
41
|
|
|
$extensionConfigsRefl->setValue($container, $extensionConfigs); |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|