Completed
Push — 1.x ( a98302...e42f79 )
by Alexander
07:32
created

PropertyInterceptorAspect::aroundFieldAccess()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 8
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
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 Demo\Aspect;
12
13
use Go\Aop\Aspect;
14
use Go\Aop\Intercept\FieldAccess;
15
use Go\Lang\Annotation\Around;
16
17
/**
18
 * Property interceptor can intercept an access to the public and protected properties
19
 *
20
 * Be aware, it's very tricky and will not work for indirect modification, such as array_pop($this->property);
21
 */
22
class PropertyInterceptorAspect implements Aspect
23
{
24
25
    /**
26
     * Advice that controls an access to the properties
27
     *
28
     * @param FieldAccess $fieldAccess Joinpoint
29
     *
30
     * @Around("access(public|protected Demo\Example\PropertyDemo->*)")
31
     * @return mixed
32
     */
33
    public function aroundFieldAccess(FieldAccess $fieldAccess)
34
    {
35
        $value = $fieldAccess->proceed();
36
        echo "Calling Around Interceptor for ", $fieldAccess, ", value: ", json_encode($value), PHP_EOL;
37
38
        // $value = 666; You can change the return value for read/write operations in advice!
39
        return $value;
40
    }
41
}
42