1 | <?php |
||
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 |