Completed
Push — master ( 210608...516dcf )
by Alexander
12s
created

Module::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 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\ZF2\GoAopModule;
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
 * ZF2 Module for registration of Go! AOP Framework
21
 */
22
class Module implements ConfigProviderInterface, InitProviderInterface
23
{
24
    /**
25
     * @inheritDoc
26
     */
27
    public function init(ModuleManagerInterface $manager)
28
    {
29
        $manager->getEventManager()->attach(
30
            ModuleEvent::EVENT_LOAD_MODULES_POST,
31
            [ $this, 'initializeAspects']
32
        );
33
    }
34
35
    /**
36
     * Register aspects after all modules are loaded.
37
     *
38
     * @param ModuleEvent $e
39
     */
40
    public function initializeAspects(ModuleEvent $e)
41
    {
42
        $serviceManager = $e->getParam('ServiceManager');
43
44
        /** @var AspectContainer $aspectContainer */
45
        $aspectContainer = $serviceManager->get(AspectContainer::class);
46
        $config          = $serviceManager->get('config');
47
        $listOfAspects   = $config['goaop_aspect'];
48
        foreach ($listOfAspects as $aspectService) {
49
            $aspect = $serviceManager->get($aspectService);
50
            $aspectContainer->registerAspect($aspect);
51
        }
52
    }
53
54
    /**
55
     * Returns configuration to merge with application configuration
56
     *
57
     * @return array|\Traversable
58
     */
59
    public function getConfig()
60
    {
61
        return include __DIR__ . '/../config/module.config.php';
62
    }
63
}
64