Completed
Push — master ( 269014...5eca8b )
by Андрей
02:50 queued 54s
created

Module   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 8

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 0
cbo 8
dl 0
loc 102
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
B init() 0 30 4
A onBootstrap() 0 8 1
A getAutoloaderConfig() 0 10 1
A getConfig() 0 4 1
1
<?php
2
/**
3
 * @link    https://github.com/nnx-framework/entry-name-resolver
4
 * @author  Malofeykin Andrey  <[email protected]>
5
 */
6
namespace Nnx\EntryNameResolver;
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\EntryNameResolverOptions
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_entry_name_resolver';
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
        $serviceListener->addServiceManager(
75
            EntryNameResolverManager::class,
76
            EntryNameResolverManager::CONFIG_KEY,
77
            EntryNameResolverProviderInterface::class,
78
            'getEntryNameResolverConfig'
79
        );
80
81
    }
82
83
    /**
84
     * @inheritdoc
85
     *
86
     * @param EventInterface $e
87
     *
88
     * @return array|void
89
     *
90
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
91
     */
92
    public function onBootstrap(EventInterface $e)
93
    {
94
        /** @var MvcEvent $e */
95
        $eventManager        = $e->getApplication()->getEventManager();
96
        $moduleRouteListener = new ModuleRouteListener();
97
        $moduleRouteListener->attach($eventManager);
98
99
    }
100
101
102
    /**
103
     * @return array
104
     */
105
    public function getAutoloaderConfig()
106
    {
107
        return [
108
            'Zend\Loader\StandardAutoloader' => [
109
                'namespaces' => [
110
                    __NAMESPACE__ => __DIR__ . '/src/',
111
                ],
112
            ],
113
        ];
114
    }
115
116
117
    /**
118
     * @inheritdoc
119
     *
120
     * @return array
121
     */
122
    public function getConfig()
123
    {
124
        return include __DIR__ . '/config/module.config.php';
125
    }
126
127
}