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); |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public static function getSubscribedEvents() |
55
|
|
|
{ |
56
|
|
|
return [ KernelEvents::REQUEST => [['onKernelRequest', 200]] ]; |
57
|
|
|
} |
58
|
|
|
} |