Completed
Pull Request — master (#91)
by Piotr
03:42
created

FSiAdminSecurityBundle.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
namespace FSi\Bundle\AdminSecurityBundle;
11
12
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass;
13
use FSi\Bundle\AdminSecurityBundle\DependencyInjection\Compiler\FirewallMapCompilerPass;
14
use FSi\Bundle\AdminSecurityBundle\DependencyInjection\Compiler\ValidationCompilerPass;
15
use FSi\Bundle\AdminSecurityBundle\DependencyInjection\FSIAdminSecurityExtension;
16
use FSi\Bundle\AdminSecurityBundle\Security\User\UserRepositoryInterface;
17
use LogicException;
18
use Symfony\Component\DependencyInjection\ContainerBuilder;
19
use Symfony\Component\HttpKernel\Bundle\Bundle;
20
21
class FSiAdminSecurityBundle extends Bundle
22
{
23
    public function build(ContainerBuilder $container)
24
    {
25
        parent::build($container);
26
27
        $container->addCompilerPass(new FirewallMapCompilerPass());
28
        $container->addCompilerPass(new ValidationCompilerPass());
29
30
        $doctrineConfigDir = realpath(__DIR__ . '/Resources/config/doctrine');
31
32
        $mappings = [
33
            $doctrineConfigDir . '/User' => 'FSi\Bundle\AdminSecurityBundle\Security\User',
34
            $doctrineConfigDir . '/Token' => 'FSi\Bundle\AdminSecurityBundle\Security\Token',
35
        ];
36
37
        $container->addCompilerPass(DoctrineOrmMappingsPass::createXmlMappingDriver($mappings));
38
39
        if ($container->hasExtension('fos_user')) {
40
            $mappings = [
41
                $doctrineConfigDir . '/FOS' => 'FSi\Bundle\AdminSecurityBundle\Security\FOS',
42
            ];
43
44
            $container->addCompilerPass(DoctrineOrmMappingsPass::createXmlMappingDriver($mappings));
45
        }
46
    }
47
48
    public function boot()
49
    {
50
        $userRepository = $this->container->get('admin_security.repository.user');
51
        if (!($userRepository instanceof UserRepositoryInterface)) {
52
            throw new LogicException(sprintf(
53
                'Repository for class "\%s" does not implement the "\%s" interface!',
54
                get_class($userRepository),
55
                'FSi\Bundle\AdminSecurityBundle\Security\User\UserRepositoryInterface'
56
            ));
57
        }
58
59
        parent::boot();
60
    }
61
62
    /**
63
     * @return FSIAdminSecurityExtension
64
     */
65
    public function getContainerExtension()
66
    {
67
        if (null === $this->extension) {
68
            $this->extension = new FSIAdminSecurityExtension();
69
        }
70
71
        return $this->extension;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The expression $this->extension; of type Symfony\Component\Depend...xtensionInterface|false adds false to the return on line 71 which is incompatible with the return type declared by the interface Symfony\Component\HttpKe...::getContainerExtension of type Symfony\Component\Depend...ExtensionInterface|null. It seems like you forgot to handle an error condition.
Loading history...
72
    }
73
}
74