Completed
Push — master ( 20b2e7...221c15 )
by Tom
16:49 queued 06:52
created

Module::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 19
ccs 0
cts 11
cp 0
rs 9.4285
cc 1
eloc 13
nc 1
nop 1
crap 2
1
<?php
2
3
namespace DoctrineORMModule;
4
5
use Interop\Container\ContainerInterface;
6
use Zend\EventManager\EventInterface;
7
use Zend\ModuleManager\Feature\BootstrapListenerInterface;
8
use Zend\ModuleManager\Feature\ControllerProviderInterface;
9
use Zend\ModuleManager\Feature\ConfigProviderInterface;
10
use Zend\ModuleManager\Feature\DependencyIndicatorInterface;
11
use Zend\ModuleManager\ModuleManagerInterface;
12
use DoctrineORMModule\CliConfigurator;
13
14
/**
15
 * Base module for Doctrine ORM.
16
 *
17
 * @license MIT
18
 * @link    www.doctrine-project.org
19
 * @author  Kyle Spraggs <[email protected]>
20
 * @author  Marco Pivetta <[email protected]>
21
 */
22
class Module implements
23
    BootstrapListenerInterface,
24
    ControllerProviderInterface,
25
    ConfigProviderInterface,
26
    DependencyIndicatorInterface
27
{
28
    /**
29
     * {@inheritDoc}
30
     */
31
    public function init(ModuleManagerInterface $manager)
32
    {
33
        // Initialize the console
34
        $manager
35
            ->getEventManager()
36
            ->getSharedManager()
37
            ->attach(
38
                'doctrine',
39
                'loadCli.post',
40
                function (EventInterface $event) {
41
                    $event
42
                        ->getParam('ServiceManager')
43
                        ->get(CliConfigurator::class)
44
                        ->configure($event->getTarget())
45
                        ;
46
                },
47
                1
48
            );
49
    }
50
51
    /**
52
     * {@inheritDoc}
53
     */
54
    public function onBootstrap(EventInterface $event)
55 72
    {
56
        /* @var $application \Zend\Mvc\Application */
57 72
        $application = $event->getTarget();
58
59
        /* @var $container ContainerInterface */
60
        $container = $application->getServiceManager();
61
62
        $events = $application->getEventManager();
63 72
64
        // Initialize logger collector once the profiler is initialized itself
65 72
        $events->attach(
66
            'profiler_init',
67
            function () use ($container) {
68
                $container->get('doctrine.sql_logger_collector.orm_default');
69
            }
70
        );
71 72
    }
72
73 72
    /**
74
     * {@inheritDoc}
75
     */
76
    public function getConfig()
77
    {
78
        return include __DIR__ . '/../../config/module.config.php';
79
    }
80
81
    /**
82
     * {@inheritDoc}
83
     */
84
    public function getControllerConfig()
85
    {
86
        return include __DIR__ . '/../../config/controllers.config.php';
87
    }
88
89
    /**
90
     * {@inheritDoc}
91
     */
92
    public function getModuleDependencies()
93
    {
94
        return ['DoctrineModule'];
95
    }
96
}
97