forked from lanfix/goaop-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctionInterceptorAspect.php
More file actions
54 lines (47 loc) · 1.52 KB
/
FunctionInterceptorAspect.php
File metadata and controls
54 lines (47 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
declare(strict_types=1);
/*
* Go! AOP framework
*
* @copyright Copyright 2014, Lisachenko Alexander <lisachenko.it@gmail.com>
*
* This source file is subject to the license that is bundled
* with this source code in the file LICENSE.
*/
namespace Demo\Aspect;
use Go\Aop\Aspect;
use Go\Aop\Intercept\FunctionInvocation;
use Go\Lang\Attribute\Around;
/**
* Function interceptor can intercept an access to the system functions
*/
class FunctionInterceptorAspect implements Aspect
{
/**
* This advice intercepts an access to the array_*** function in Demo\Example\ namespace
*/
#[Around('execution(Demo\Example\array_*(*))')]
public function aroundArrayFunctions(FunctionInvocation $invocation): mixed
{
echo 'Calling Around Interceptor for ',
$invocation,
' with arguments: ',
json_encode($invocation->getArguments()),
PHP_EOL;
return $invocation->proceed();
}
/**
* This advice intercepts an access to the file_get_contents() function
*/
#[Around('execution(Demo\Example\file_get_contents(*))')]
public function aroundFileGetContents(FunctionInvocation $invocation): string
{
echo 'Calling Around Interceptor for ',
$invocation,
' with arguments: ',
json_encode($invocation->getArguments()),
PHP_EOL;
// return $invocation->proceed(); // Do not call original file_get_contents()
return 'Hello!'; // Override return value for function
}
}