Completed
Pull Request — master (#101)
by Łukasz
10:52 queued 13s
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
40
    public function boot()
41
    {
42
        $userRepository = $this->container->get('admin_security.repository.user');
43
        if (!($userRepository instanceof UserRepositoryInterface)) {
44
            throw new LogicException(sprintf(
45
                'Repository for class "\%s" does not implement the "\%s" interface!',
46
                get_class($userRepository),
47
                'FSi\Bundle\AdminSecurityBundle\Security\User\UserRepositoryInterface'
48
            ));
49
        }
50
51
        parent::boot();
52
    }
53
54
    /**
55
     * @return FSIAdminSecurityExtension
56
     */
57
    public function getContainerExtension()
58
    {
59
        if (null === $this->extension) {
60
            $this->extension = new FSIAdminSecurityExtension();
61
        }
62
63
        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 63 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...
64
    }
65
}
66