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
|
|
|
|