Completed
Pull Request — master (#540)
by
unknown
14:01
created

Module::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1.0156

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 9
cts 12
cp 0.75
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 1
crap 1.0156

2 Methods

Rating   Name   Duplication   Size   Complexity  
A Module::getConfig() 0 4 1
A Module::getControllerConfig() 0 4 1
1
<?php
2
3
namespace DoctrineORMModule;
4
5
use DoctrineORMModule\Listener\PostCliLoadListener;
6
use Psr\Container\ContainerInterface;
7
use Symfony\Component\Console\Application;
8
use Zend\EventManager\EventInterface;
9
use Zend\ModuleManager\Feature\BootstrapListenerInterface;
10
use Zend\ModuleManager\Feature\ControllerProviderInterface;
11
use Zend\ModuleManager\Feature\ConfigProviderInterface;
12
use Zend\ModuleManager\Feature\DependencyIndicatorInterface;
13
use Zend\ModuleManager\ModuleManagerInterface;
14
15
/**
16
 * Base module for Doctrine ORM.
17
 *
18
 * @license MIT
19
 * @link    www.doctrine-project.org
20
 * @author  Kyle Spraggs <[email protected]>
21
 * @author  Marco Pivetta <[email protected]>
22
 */
23
class Module implements
24
    ControllerProviderInterface,
25
    ConfigProviderInterface,
26
    DependencyIndicatorInterface,
27
    BootstrapListenerInterface
28
{
29
    /**
30
     * {@inheritDoc}
31
     */
32 72
    public function getConfig()
33
    {
34 72
        return include __DIR__ . '/../../config/module.config.php';
35
    }
36
37
    /**
38
     * {@inheritDoc}
39
     */
40 72
    public function getControllerConfig()
41
    {
42 72
        return include __DIR__ . '/../../config/controllers.config.php';
43
    }
44
45
    /**
46
     * {@inheritDoc}
47
     */
48 72
    public function getModuleDependencies()
49
    {
50 72
        return ['DoctrineModule'];
51
    }
52
53
    /**
54
     * @param EventInterface $event
55
     * @throws \Psr\Container\ContainerExceptionInterface
56
     * @throws \Psr\Container\NotFoundExceptionInterface
57
     */
58 16
    public function onBootstrap(EventInterface $event)
59
    {
60
        /* @var $application \Zend\Mvc\Application */
61 16
        $application = $event->getTarget();
62
        /* @var $container ContainerInterface */
63 16
        $container = $application->getServiceManager();
64
65 16
        $events = $application->getEventManager();
66
67
        // Initialize logger collector once the profiler is initialized itself
68 16
        $events->attach(
69 16
            'profiler_init',
70
            function () use ($container) {
71
                $container->get('doctrine.sql_logger_collector.orm_default');
72
            }
73 16
        );
74
75
        /* @var $postCliLoadListener PostCliLoadListener */
76 16
        $postCliLoadListener = $container->get(PostCliLoadListener::class);
77 16
        $postCliLoadListener->attach($events);
78
79
        /* @var $doctrineCli Application */
80 16
        $doctrineCli = $container->get('doctrine.cli');
81
82 16
        $eventDispatcher = $container->get('doctrine.cli.event_dispatcher');
83 16
        $doctrineCli->setDispatcher($eventDispatcher);
84 16
    }
85
}
86