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

FunctionInterceptorAspect::aroundArrayFunctions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 10
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 7
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\FunctionInvocation;
15
use Go\Lang\Annotation\Around;
16
17
/**
18
 * Function interceptor can intercept an access to the system functions
19
 */
20
class FunctionInterceptorAspect implements Aspect
21
{
22
23
    /**
24
     * This advice intercepts an access to the array_*** function in Demo\Example\ namespace
25
     *
26
     * @param FunctionInvocation $invocation
27
     *
28
     * @Around("execution(Demo\Example\array_*(*)) && !execution(Demo\Example\array_multisort(*))")
29
     *
30
     * @return mixed
31
     */
32
    public function aroundArrayFunctions(FunctionInvocation $invocation)
33
    {
34
        echo 'Calling Around Interceptor for ',
35
            $invocation,
36
            ' with arguments: ',
37
            json_encode($invocation->getArguments()),
38
            PHP_EOL;
39
40
        return $invocation->proceed();
41
    }
42
43
    /**
44
     * This advice intercepts an access to the file_get_contents() function
45
     *
46
     * @param FunctionInvocation $invocation
47
     *
48
     * @Around("execution(Demo\Example\file_get_contents(*))")
49
     *
50
     * @return mixed
51
     */
52
    public function aroundFileGetContents(FunctionInvocation $invocation)
53
    {
54
        echo 'Calling Around Interceptor for ',
55
            $invocation,
56
            ' with arguments: ',
57
            json_encode($invocation->getArguments()),
58
            PHP_EOL;
59
60
        // return $invocation->proceed(); // Do not call original file_get_contents()
61
        return 'Hello!'; // Override return value for function
62
    }
63
}
64