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