Completed
Push — dev ( 8e5da6...89fd4e )
by Андрей
02:08
created

Module::getConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * @link    https://github.com/nnx-framework/doctrine-fixture-module
4
 * @author  Malofeykin Andrey  <[email protected]>
5
 */
6
namespace Nnx\DoctrineFixtureModule;
7
8
use Zend\ModuleManager\Feature\ConfigProviderInterface;
9
use Zend\ModuleManager\Listener\ServiceListenerInterface;
10
use Zend\ModuleManager\ModuleManager;
11
use Zend\ModuleManager\ModuleManagerInterface;
12
use Zend\Mvc\ModuleRouteListener;
13
use Zend\Mvc\MvcEvent;
14
use Zend\EventManager\EventInterface;
15
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
16
use Zend\ModuleManager\Feature\BootstrapListenerInterface;
17
use Zend\ModuleManager\Feature\InitProviderInterface;
18
use Zend\ServiceManager\ServiceLocatorInterface;
19
20
21
/**
22
 * Class Module
23
 *
24
 * @package Nnx\DoctrineFixtureModule
25
 */
26
class Module implements
27
    BootstrapListenerInterface,
28
    AutoloaderProviderInterface,
29
    InitProviderInterface,
30
    ConfigProviderInterface
31
{
32
    /**
33
     * Имя секции в конфиги приложения отвечающей за настройки модуля
34
     *
35
     * @var string
36
     */
37
    const CONFIG_KEY = 'nnx_doctrine_fixture_module';
38
39
    /**
40
     * Имя модуля
41
     *
42
     * @var string
43
     */
44
    const MODULE_NAME = __NAMESPACE__;
45
46
    /**
47
     * @param ModuleManagerInterface $manager
48
     *
49
     * @throws Exception\InvalidArgumentException
50
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
51
     */
52
    public function init(ModuleManagerInterface $manager)
53
    {
54
        if (!$manager instanceof ModuleManager) {
55
            $errMsg =sprintf('Module manager not implement %s', ModuleManager::class);
56
            throw new Exception\InvalidArgumentException($errMsg);
57
        }
58
59
        /** @var ServiceLocatorInterface $sm */
60
        $sm = $manager->getEvent()->getParam('ServiceManager');
61
62
        if (!$sm instanceof ServiceLocatorInterface) {
63
            $errMsg = sprintf('Service locator not implement %s', ServiceLocatorInterface::class);
64
            throw new Exception\InvalidArgumentException($errMsg);
65
        }
66
        /** @var ServiceListenerInterface $serviceListener */
67
        $serviceListener = $sm->get('ServiceListener');
68
        if (!$serviceListener instanceof ServiceListenerInterface) {
69
            $errMsg = sprintf('ServiceListener not implement %s', ServiceListenerInterface::class);
70
            throw new Exception\InvalidArgumentException($errMsg);
71
        }
72
73
74
75
    }
76
77
    /**
78
     * @inheritdoc
79
     *
80
     * @param EventInterface $e
81
     *
82
     * @return array|void
83
     *
84
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
85
     */
86
    public function onBootstrap(EventInterface $e)
87
    {
88
        /** @var MvcEvent $e */
89
        $eventManager        = $e->getApplication()->getEventManager();
90
        $moduleRouteListener = new ModuleRouteListener();
91
        $moduleRouteListener->attach($eventManager);
92
93
    }
94
95
96
    /**
97
     * @return array
98
     */
99
    public function getAutoloaderConfig()
100
    {
101
        return [
102
            'Zend\Loader\StandardAutoloader' => [
103
                'namespaces' => [
104
                    __NAMESPACE__ => __DIR__ . '/src/',
105
                ],
106
            ],
107
        ];
108
    }
109
110
111
    /**
112
     * @inheritdoc
113
     *
114
     * @return array
115
     */
116
    public function getConfig()
117
    {
118
        return include __DIR__ . '/config/module.config.php';
119
    }
120
121
}