Completed
Push — master ( d404ac...fc4cfb )
by Alexander
10:24 queued 07:21
created

LoggingAspect   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
lcom 0
cbo 0
dl 0
loc 26
rs 10
c 1
b 0
f 0
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\MethodInvocation;
15
use Go\Lang\Annotation\Before;
16
17
/**
18
 * Logging aspect
19
 *
20
 * @see http://go.aopphp.com/blog/2013/07/21/implementing-logging-aspect-with-doctrine-annotations/
21
 */
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