-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
GoAopBundle.php
56 lines (50 loc) · 1.7 KB
/
GoAopBundle.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/**
* Go! AOP framework
*
* @copyright Copyright 2015, Lisachenko Alexander <[email protected]>
*
* This source file is subject to the license that is bundled
* with this source code in the file LICENSE.
*/
namespace Go\Symfony\GoAopBundle;
use Go\Instrument\ClassLoading\AopComposerLoader;
use Go\Symfony\GoAopBundle\DependencyInjection\Compiler\AspectCollectorPass;
use Symfony\Component\Debug\DebugClassLoader;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class GoAopBundle extends Bundle
{
/**
* {@inheritdoc}
*/
public function build(ContainerBuilder $container)
{
$bundles = $container->getParameter('kernel.bundles');
$firstBundle = key($bundles);
if ($firstBundle !== $this->name) {
$message = "Please move the {$this->name} initialization to the top in your Kernel->init()";
throw new \InvalidArgumentException($message);
}
$container->addCompilerPass(new AspectCollectorPass());
}
/**
* {@inheritdoc}
*/
public function boot()
{
// it is a quick way to check if loader was enabled
$wasDebugEnabled = class_exists(DebugClassLoader::class, false);
if ($wasDebugEnabled) {
// disable temporary to apply AOP loader first
DebugClassLoader::disable();
}
$this->container->get('goaop.aspect.container');
if (!AopComposerLoader::wasInitialized()) {
throw new \RuntimeException("Initialization of AOP loader was failed, probably due to Debug::enable()");
}
if ($wasDebugEnabled) {
DebugClassLoader::enable();
}
}
}