Completed
Pull Request — master (#11)
by
unknown
11:22
created

Module   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 4
dl 0
loc 46
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 7 1
A initializeAspects() 0 14 2
A getConfig() 0 4 1
1
<?php
2
/*
3
 * Go! AOP framework
4
 *
5
 * @copyright Copyright 2016, Lisachenko Alexander <[email protected]>
6
 *
7
 * This source file is subject to the license that is bundled
8
 * with this source code in the file LICENSE.
9
 */
10
11
namespace Go\Zend\Framework;
12
13
use Go\Core\AspectContainer;
14
use Zend\ModuleManager\Feature\ConfigProviderInterface;
15
use Zend\ModuleManager\Feature\InitProviderInterface;
16
use Zend\ModuleManager\ModuleEvent;
17
use Zend\ModuleManager\ModuleManagerInterface;
18
19
/**
20
 * Module for registration of Go! AOP Framework
21
 */
22
class Module implements ConfigProviderInterface, InitProviderInterface
23
{
24
    const CONFIG_KEY = 'goaop_module';
25
    const ASPECT_CONFIG_KEY = 'goaop_aspect';
26
27
    /**
28
     * @inheritDoc
29
     */
30
    public function init(ModuleManagerInterface $manager)
31
    {
32
        $manager->getEventManager()->attach(
33
            ModuleEvent::EVENT_LOAD_MODULES_POST,
34
            [ $this, 'initializeAspects' ]
35
        );
36
    }
37
38
    /**
39
     * Register aspects after all modules are loaded.
40
     *
41
     * @param ModuleEvent $e
42
     */
43
    public function initializeAspects(ModuleEvent $e)
44
    {
45
        $serviceManager = $e->getParam('ServiceManager');
46
47
        /** @var AspectContainer $aspectContainer */
48
        $aspectContainer = $serviceManager->get(AspectContainer::class);
49
        $config          = $serviceManager->get('config');
50
        $listOfAspects   = $config[self::ASPECT_CONFIG_KEY];
51
52
        foreach ($listOfAspects as $aspectService) {
53
            $aspect = $serviceManager->get($aspectService);
54
            $aspectContainer->registerAspect($aspect);
55
        }
56
    }
57
58
    /**
59
     * Returns configuration to merge with application configuration
60
     *
61
     * @return array|\Traversable
62
     */
63
    public function getConfig()
64
    {
65
        return include __DIR__ . '/../config/module.config.php';
66
    }
67
}
68