Module::getServiceConfig()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * @company MTE Telecom, Ltd.
4
 * @author Roman Malashin <[email protected]>
5
 */
6
7
namespace Nnx\DataGrid;
8
9
use Nnx\DataGrid\Column\GridColumnProviderInterface;
10
use Nnx\DataGrid\Mutator\GridMutatorProviderInterface;
11
use \Nnx\DataGrid\Button\GridButtonProviderInterface;
12
use Nnx\DataGrid\Options\ModuleOptions;
13
use Zend\EventManager\EventInterface;
14
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
15
use Zend\ModuleManager\Feature\BootstrapListenerInterface;
16
use Zend\ModuleManager\Feature\ConfigProviderInterface;
17
use Zend\ModuleManager\Feature\InitProviderInterface;
18
use Zend\ModuleManager\Feature\ServiceProviderInterface;
19
use Zend\ModuleManager\Listener\ServiceListenerInterface;
20
use Zend\ModuleManager\ModuleManager;
21
use Zend\ModuleManager\ModuleManagerInterface;
22
use Zend\Mvc\MvcEvent;
23
use Zend\ServiceManager\ServiceLocatorAwareInterface;
24
use Zend\ServiceManager\ServiceLocatorAwareTrait;
25
use Zend\ServiceManager\ServiceLocatorInterface;
26
27
/**
28
 * Class Module
29
 * @package Nnx\DataGrid
30
 */
31
class Module
32
    implements ServiceLocatorAwareInterface,
0 ignored issues
show
Coding Style introduced by
The implements keyword must be on the same line as the class name
Loading history...
Coding Style introduced by
The first item in a multi-line implements list must be on the line following the implements keyword
Loading history...
33
    ConfigProviderInterface,
34
    AutoloaderProviderInterface,
35
    BootstrapListenerInterface,
36
    ServiceProviderInterface,
37
    InitProviderInterface
38
{
39
40
    use ServiceLocatorAwareTrait;
41
42
    /**
43
     * Имя секции в конфигах приложения, содержащей настройки модуля
44
     *
45
     * @var string
46
     */
47
    const CONFIG_KEY = 'mteGrid';
48
49
    /**
50
     * Имя модуля
51
     *
52
     * @var string
53
     */
54
    const MODULE_NAME = __NAMESPACE__;
55
56
    /**
57
     * Получаем конфигурацию модуля
58
     * @return array
59
     */
60
    public function getConfig()
61
    {
62
        return require __DIR__ . '/config/module.config.php';
63
    }
64
65
    /**
66
     * Return an array for passing to Zend\Loader\AutoloaderFactory.
67
     *
68
     * @return array
69
     */
70
    public function getAutoloaderConfig()
71
    {
72
        $config = [];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
73
        $autoloadFile = __DIR__ . '/autoload_classmap.php';
74
        if (file_exists($autoloadFile)) {
75
            $config['Zend\Loader\ClassMapAutoloader'] = [
76
                $autoloadFile
77
            ];
78
        }
79
        $config['Zend\Loader\StandardAutoloader'] = [
80
            'namespaces' => [
81
                __NAMESPACE__ => __DIR__ . '/src'
82
            ]
83
        ];
84
        return $config;
85
    }
86
87
    /**
88
     * Listen to the bootstrap event
89
     *
90
     * @param EventInterface $e
91
     * @return array
0 ignored issues
show
Documentation introduced by
Should the return type not be array|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
92
     */
93
    public function onBootstrap(EventInterface $e)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $e. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
94
    {
95
        /** @var MvcEvent $e */
96
        $this->setServiceLocator($e->getApplication()->getServiceManager());
97
    }
98
99
    /**
100
     * Expected to return \Zend\ServiceManager\Config object or array to
101
     * seed such an object.
102
     *
103
     * @return array|\Zend\ServiceManager\Config
104
     */
105
    public function getServiceConfig()
106
    {
107
        return [];
108
    }
109
110
    /**
111
     * Initialize workflow
112
     *
113
     * @param  ModuleManagerInterface $manager
114
     * @throws Exception\RuntimeException
115
     */
116
    public function init(ModuleManagerInterface $manager)
117
    {
118
        if (!$manager instanceof ModuleManager) {
119
            $errMsg =sprintf('Менеджер модулей должен реализовывать %s', ModuleManager::class);
120
            throw new Exception\RuntimeException($errMsg);
121
        }
122
        /** @var ModuleManager $manager */
123
124
        /** @var ServiceLocatorInterface $sm */
125
        $sm = $manager->getEvent()->getParam('ServiceManager');
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $sm. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
126
127
        /** @var ServiceListenerInterface $serviceListener */
128
        $serviceListener = $sm->get('ServiceListener');
129
        $serviceListener->addServiceManager(
130
            'GridManager',
131
            'grid_manager',
132
            GridProviderInterface::class,
133
            'getGridConfig'
134
        );
135
136
        $serviceListener->addServiceManager(
137
            'GridColumnManager',
138
            'grid_columns',
139
            GridColumnProviderInterface::class,
140
            'getGridColumnConfig'
141
        );
142
        $serviceListener->addServiceManager(
143
            'GridMutatorManager',
144
            'grid_mutators',
145
            GridMutatorProviderInterface::class,
146
            'getGridMutatorConfig'
147
        );
148
        $serviceListener->addServiceManager(
149
            'GridButtonManager',
150
            'grid_buttons',
151
            GridButtonProviderInterface::class,
152
            'getGridButtonConfig'
153
        );
154
    }
155
156
    /**
157
     * Возвращает объект с настройками модуля
158
     *
159
     * @return ModuleOptions
160
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
161
     */
162
    public function getModuleOptions()
163
    {
164
        /** @var ModuleOptions $moduleOptions */
165
        return $this->getServiceLocator()->get('GridModuleOptions');
166
    }
167
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
168