Completed
Push — master ( ec1826...17149c )
by Taosikai
15:14
created

DoctrineExtensionsServiceProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 30
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 27 3
1
<?php
2
3
/*
4
 * This file is part of the jade/jade package.
5
 *
6
 * (c) Slince <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Jade\Provider;
13
14
use Doctrine\Common\EventManager;
15
use Gedmo\Sortable\SortableListener;
16
use Gedmo\Timestampable\TimestampableListener;
17
use Gedmo\Sluggable\SluggableListener;
18
use Jade\ContainerInterface;
19
use Jade\ServiceProviderInterface;
20
21
/**
22
 * @author Sérgio Rafael Siquira <[email protected]>
23
 */
24
class DoctrineExtensionsServiceProvider implements ServiceProviderInterface
25
{
26
    public function register(ContainerInterface $container)
27
    {
28
        if (!isset($container['annotations'])) {
29
            throw new \LogicException(
30
                'You must register the AnnotationsServiceProvider to use the DoctrineExtensionsServiceProvider.'
31
            );
32
        }
33
34
        $container['gedmo.listeners'] = function () {
35
            return [
36
                new SortableListener(),
37
                new TimestampableListener(),
38
                new SluggableListener(),
39
            ];
40
        };
41
42
        $container['db.event_manager'] = $container->extend('db.event_manager', function (EventManager $event) use ($container) {
43
            $listeners = $container['gedmo.listeners'];
44
45
            foreach ($listeners as $listener) {
46
                $listener->setAnnotationReader($container['annotations']);
47
                $event->addEventSubscriber($listener);
48
            }
49
50
            return $event;
51
        });
52
    }
53
}