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

PointcutReference   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 8
c 2
b 0
f 0
lcom 1
cbo 3
dl 0
loc 98
ccs 0
cts 32
cp 0
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A matches() 0 4 1
A getKind() 0 4 1
A getClassFilter() 0 4 1
A getPointcut() 0 8 2
A __sleep() 0 4 1
A __wakeup() 0 4 1
1
<?php
2
/*
3
 * Go! AOP framework
4
 *
5
 * @copyright Copyright 2015, 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\Pointcut;
12
13
use Go\Aop\Pointcut;
14
use Go\Aop\PointFilter;
15
use Go\Core\AspectContainer;
16
use Go\Core\AspectKernel;
17
18
/**
19
 * Reference to the pointcut holds an id of pointcut to fetch when needed
20
 */
21
class PointcutReference implements Pointcut
22
{
23
    /**
24
     * @var Pointcut
25
     */
26
    protected $pointcut = null;
27
28
    /**
29
     * Name of the pointcut to fetch from the container
30
     *
31
     * @var string
32
     */
33
    private $pointcutName;
34
35
    /**
36
     * Instance of aspect container
37
     *
38
     * @var AspectContainer
39
     */
40
    private $container;
41
42
    /**
43
     * Pointcut reference constructor
44
     *
45
     * @param AspectContainer $container Instance of container
46
     * @param string $pointcutName Referenced pointcut
47
     */
48
    public function __construct(AspectContainer $container, $pointcutName)
49
    {
50
        $this->container    = $container;
51
        $this->pointcutName = $pointcutName;
52
    }
53
54
    /**
55
     * Performs matching of point of code
56
     *
57
     * @param mixed $point Specific part of code, can be any Reflection class
58
     * @param null|mixed $context Related context, can be class or namespace
59
     * @param null|string|object $instance Invocation instance or string for static calls
60
     * @param null|array $arguments Dynamic arguments for method
61
     *
62
     * @return bool
63
     */
64
    public function matches($point, $context = null, $instance = null, array $arguments = null)
65
    {
66
        return $this->getPointcut()->matches($point, $context, $instance, $arguments);
67
    }
68
69
    /**
70
     * Returns the kind of point filter
71
     *
72
     * @return integer
73
     */
74
    public function getKind()
75
    {
76
        return $this->getPointcut()->getKind();
77
    }
78
79
    /**
80
     * Return the class filter for this pointcut.
81
     *
82
     * @return PointFilter
83
     */
84
    public function getClassFilter()
85
    {
86
        return $this->getPointcut()->getClassFilter();
87
    }
88
89
    /**
90
     * Returns a real pointcut from the container
91
     *
92
     * @return Pointcut
93
     */
94
    public function getPointcut()
95
    {
96
        if (!$this->pointcut) {
97
            $this->pointcut = $this->container->getPointcut($this->pointcutName);
98
        }
99
100
        return $this->pointcut;
101
    }
102
103
    /**
104
     * {@inheritdoc}
105
     */
106
    public function __sleep()
107
    {
108
        return array('pointcutName');
109
    }
110
111
    /**
112
     * {@inheritdoc}
113
     */
114
    public function __wakeup()
115
    {
116
        $this->container = AspectKernel::getInstance()->getContainer();
117
    }
118
}
119