Passed
Push — master ( 9ff996...7ddffb )
by Xavier
02:16
created

Providers   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 36
rs 10
c 1
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A onKernelRequest() 0 7 2
A getSubscribedEvents() 0 3 1
A __construct() 0 3 1
A registerLDAP() 0 7 1
1
<?php
2
3
/*
4
 * @author  Xavier Chopin <[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 AppBundle\EventListener;
11
12
13
use Symfony\Component\DependencyInjection\Container;
14
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
15
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
16
use Symfony\Component\HttpKernel\Event\KernelEvent;
17
use Symfony\Component\HttpKernel\HttpKernel;
18
use Symfony\Component\HttpKernel\KernelEvents;
19
20
21
class Providers
22
{
23
    private $container;
24
25
    public function __construct(Container $container)
26
    {
27
        $this->container = $container;
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function onKernelRequest(GetResponseEvent $event)
34
    {
35
        if (HttpKernel::MASTER_REQUEST != $event->getRequestType()) {
36
            return;
37
        }
38
39
        $this->registerLDAP();
40
    }
41
42
    /**
43
     * Registers a LDAP Instance into the container.
44
     */
45
    private function registerLDAP()
46
    {
47
        $settings = $this->container->getParameter('ldap');
48
        $ldapInstance = ldap_connect($settings['host'], $settings['port']);
49
        ldap_set_option($ldapInstance, LDAP_OPT_PROTOCOL_VERSION, 3);
50
        ldap_set_option($ldapInstance, LDAP_OPT_REFERRALS, 0);
51
        $this->container->set('ldap', $ldapInstance);
0 ignored issues
show
Bug introduced by
$ldapInstance of type resource is incompatible with the type object expected by parameter $service of Symfony\Component\Depend...ection\Container::set(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

51
        $this->container->set('ldap', /** @scrutinizer ignore-type */ $ldapInstance);
Loading history...
52
    }
53
54
    public static function getSubscribedEvents()
55
    {
56
        return [ KernelEvents::REQUEST => [['onKernelRequest', 200]] ];
57
    }
58
}