Completed
Push — 1.x ( c183a4...05b51a )
by Alexander
8s
created

LazyPointcutAdvisor::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 6
ccs 0
cts 6
cp 0
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 4
nc 1
nop 3
crap 2
1
<?php
2
/*
3
 * Go! AOP framework
4
 *
5
 * @copyright Copyright 2014, 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\Aop\Support;
12
13
use Go\Aop\Advice;
14
use Go\Aop\Pointcut;
15
use Go\Core\AspectContainer;
16
17
/**
18
 * Lazy pointcut advisor is used to create a delayed pointcut only when needed
19
 */
20
class LazyPointcutAdvisor extends AbstractGenericPointcutAdvisor
21
{
22
23
    /**
24
     * Pointcut expression
25
     *
26
     * @var string
27
     */
28
    private $pointcutExpression;
29
30
    /**
31
     * Instance of parsed pointcut
32
     *
33
     * @var Pointcut|null
34
     */
35
    private $pointcut;
36
37
    /**
38
     * @var AspectContainer
39
     */
40
    private $container;
41
42
    /**
43
     * Create a DefaultPointcutAdvisor, specifying Pointcut and Advice.
44
     *
45
     * @param AspectContainer $container Instance of container
46
     * @param string $pointcutExpression The Pointcut targeting the Advice
47
     * @param Advice $advice The Advice to run when Pointcut matches
48
     */
49
    public function __construct(AspectContainer $container, $pointcutExpression, Advice $advice)
50
    {
51
        $this->container          = $container;
52
        $this->pointcutExpression = $pointcutExpression;
53
        parent::__construct($advice);
54
    }
55
56
    /**
57
     * Get the Pointcut that drives this advisor.
58
     *
59
     * @return Pointcut The pointcut
60
     */
61
    public function getPointcut()
62
    {
63
        if (!$this->pointcut) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
64
65
            // Inject this dependencies and make them lazy!
66
            // should be extracted from AbstractAspectLoaderExtension into separate class
67
68
            /** @var Pointcut\PointcutLexer $lexer */
69
            $lexer = $this->container->get('aspect.pointcut.lexer');
70
71
            /** @var Pointcut\PointcutParser $parser */
72
            $parser = $this->container->get('aspect.pointcut.parser');
73
74
            $tokenStream    = $lexer->lex($this->pointcutExpression);
75
            $this->pointcut = $parser->parse($tokenStream);
76
        }
77
78
        return $this->pointcut;
79
    }
80
}
81