1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* (c) FSi sp. z o.o. <[email protected]> |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
declare(strict_types=1); |
11
|
|
|
|
12
|
|
|
namespace FSi\Bundle\AdminSecurityBundle; |
13
|
|
|
|
14
|
|
|
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass; |
15
|
|
|
use FSi\Bundle\AdminSecurityBundle\DependencyInjection\Compiler\FirewallMapCompilerPass; |
16
|
|
|
use FSi\Bundle\AdminSecurityBundle\DependencyInjection\Compiler\ValidationCompilerPass; |
17
|
|
|
use FSi\Bundle\AdminSecurityBundle\DependencyInjection\FSIAdminSecurityExtension; |
18
|
|
|
use FSi\Bundle\AdminSecurityBundle\Security\User\UserRepositoryInterface; |
19
|
|
|
use LogicException; |
20
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
21
|
|
|
use Symfony\Component\HttpKernel\Bundle\Bundle; |
22
|
|
|
|
23
|
|
|
class FSiAdminSecurityBundle extends Bundle |
24
|
|
|
{ |
25
|
|
|
public function build(ContainerBuilder $container): void |
26
|
|
|
{ |
27
|
|
|
parent::build($container); |
28
|
|
|
|
29
|
|
|
$container->addCompilerPass(new FirewallMapCompilerPass()); |
30
|
|
|
$container->addCompilerPass(new ValidationCompilerPass()); |
31
|
|
|
|
32
|
|
|
$doctrineConfigDir = realpath(__DIR__ . '/Resources/config/doctrine'); |
33
|
|
|
|
34
|
|
|
$mappings = [ |
35
|
|
|
$doctrineConfigDir . '/User' => 'FSi\Bundle\AdminSecurityBundle\Security\User', |
36
|
|
|
$doctrineConfigDir . '/Token' => 'FSi\Bundle\AdminSecurityBundle\Security\Token', |
37
|
|
|
]; |
38
|
|
|
|
39
|
|
|
$container->addCompilerPass(DoctrineOrmMappingsPass::createXmlMappingDriver($mappings)); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function boot(): void |
43
|
|
|
{ |
44
|
|
|
$userRepository = $this->container->get('admin_security.repository.user'); |
45
|
|
|
if (!($userRepository instanceof UserRepositoryInterface)) { |
46
|
|
|
throw new LogicException(sprintf( |
47
|
|
|
'Repository for class "\%s" does not implement the "\%s" interface!', |
48
|
|
|
get_class($userRepository), |
49
|
|
|
'FSi\Bundle\AdminSecurityBundle\Security\User\UserRepositoryInterface' |
50
|
|
|
)); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
parent::boot(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function getContainerExtension(): FSIAdminSecurityExtension |
57
|
|
|
{ |
58
|
|
|
if (null === $this->extension) { |
59
|
|
|
$this->extension = new FSIAdminSecurityExtension(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return $this->extension; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|