1 | <?php |
||
22 | class LoggingAspect implements Aspect |
||
23 | { |
||
24 | |||
25 | /** |
||
26 | * This advice intercepts an execution of loggable methods |
||
27 | * |
||
28 | * We use "Before" type of advice to log only class name, method name and arguments before |
||
29 | * method execution. |
||
30 | * You can choose your own logger, for example, monolog or log4php. |
||
31 | * Also you can choose "After" or "Around" advice to access an return value from method. |
||
32 | * |
||
33 | * To inject logger into this aspect you can look at Warlock framework with DI+AOP |
||
34 | * |
||
35 | * @param MethodInvocation $invocation Invocation |
||
36 | * |
||
37 | * @Before("@execution(Demo\Annotation\Loggable)") |
||
38 | */ |
||
39 | public function beforeMethodExecution(MethodInvocation $invocation) |
||
40 | { |
||
41 | echo 'Calling Before Interceptor for ', |
||
42 | $invocation, |
||
43 | ' with arguments: ', |
||
44 | json_encode($invocation->getArguments()), |
||
45 | PHP_EOL; |
||
46 | } |
||
47 | } |
||
48 |