Completed
Pull Request — 1.x (#301)
by
unknown
04:37
created

BaseInterceptor   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 68
ccs 0
cts 24
cp 0
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getRawAdvice() 0 4 1
A serialize() 0 7 1
A unserialize() 0 8 2
1
<?php
2
/*
3
 * Go! AOP framework
4
 *
5
 * @copyright Copyright 2011, 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\Framework;
12
13
use Closure;
14
use Serializable;
15
use Go\Aop\Intercept\Interceptor;
16
17
/**
18
 * Base interceptor realization
19
 */
20
abstract class BaseInterceptor extends BaseAdvice implements Interceptor, Serializable
21
{
22
    /**
23
     * Pointcut expression
24
     *
25
     * @var string
26
     */
27
    protected $pointcutExpression = '';
28
29
    /**
30
     * Advice to call
31
     *
32
     * @var Closure
33
     */
34
    protected $adviceMethod;
35
36
    /**
37
     * Default constructor for interceptor
38
     *
39
     * @param Closure $adviceMethod Interceptor advice to call
40
     * @param integer $order Order of interceptor
41
     * @param string $pointcutExpression Pointcut expression or advice name
42
     */
43
    public function __construct(Closure $adviceMethod, $order = 0, $pointcutExpression = '')
44
    {
45
        $this->adviceMethod       = $adviceMethod;
46
        $this->order              = $order;
47
        $this->pointcutExpression = $pointcutExpression;
48
    }
49
50
    /**
51
     * Getter for extracting the advice closure from Interceptor
52
     *
53
     * @return callable|null
54
     */
55
    public function getRawAdvice()
56
    {
57
        return $this->adviceMethod;
58
    }
59
60
    /**
61
     * Serializes an interceptor into string representation
62
     *
63
     * @return string the string representation of the object or null
64
     */
65
    public function serialize()
66
    {
67
        $vars = array_filter(get_object_vars($this));
68
        $vars['adviceMethod'] = static::serializeAdvice($this->adviceMethod);
69
70
        return serialize($vars);
71
    }
72
73
    /**
74
     * Unserialize an interceptor from the string
75
     *
76
     * @param string $serialized The string representation of the object.
77
     * @return void
78
     */
79
    public function unserialize($serialized)
80
    {
81
        $vars = unserialize($serialized);
82
        $vars['adviceMethod'] = static::unserializeAdvice($vars['adviceMethod']);
83
        foreach ($vars as $key=>$value) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space before "=>"; 0 found
Loading history...
Coding Style introduced by
Expected 1 space after "=>"; 0 found
Loading history...
84
            $this->$key = $value;
85
        }
86
    }
87
}
88