Module   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 8

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
B init() 0 31 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\EntryNameResolver
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_module_options';
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
        
60
        /** @var ServiceLocatorInterface $sm */
61
        $sm = $manager->getEvent()->getParam('ServiceManager');
62
63
        if (!$sm instanceof ServiceLocatorInterface) {
64
            $errMsg = sprintf('Service locator not implement %s', ServiceLocatorInterface::class);
65
            throw new Exception\InvalidArgumentException($errMsg);
66
        }
67
        /** @var ServiceListenerInterface $serviceListener */
68
        $serviceListener = $sm->get('ServiceListener');
69
        if (!$serviceListener instanceof ServiceListenerInterface) {
70
            $errMsg = sprintf('ServiceListener not implement %s', ServiceListenerInterface::class);
71
            throw new Exception\InvalidArgumentException($errMsg);
72
        }
73
74
75
        $serviceListener->addServiceManager(
76
            EntryNameResolverManagerInterface::class,
77
            EntryNameResolverManager::CONFIG_KEY,
78
            EntryNameResolverProviderInterface::class,
79
            'getEntryNameResolverConfig'
80
        );
81
82
    }
83
84
    /**
85
     * @inheritdoc
86
     *
87
     * @param EventInterface $e
88
     *
89
     * @return array|void
90
     *
91
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
92
     */
93
    public function onBootstrap(EventInterface $e)
94
    {
95
        /** @var MvcEvent $e */
96
        $eventManager        = $e->getApplication()->getEventManager();
97
        $moduleRouteListener = new ModuleRouteListener();
98
        $moduleRouteListener->attach($eventManager);
99
100
    }
101
102
103
    /**
104
     * @return array
105
     */
106
    public function getAutoloaderConfig()
107
    {
108
        return [
109
            'Zend\Loader\StandardAutoloader' => [
110
                'namespaces' => [
111
                    __NAMESPACE__ => __DIR__ . '/src/',
112
                ],
113
            ],
114
        ];
115
    }
116
117
118
    /**
119
     * @inheritdoc
120
     *
121
     * @return array
122
     */
123
    public function getConfig()
124
    {
125
        return include __DIR__ . '/config/module.config.php';
126
    }
127
128
}