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

LoggingDemo   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 41
rs 10
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\Example;
12
13
use Demo\Annotation\Loggable;
14
15
/**
16
 * Example class to show how to use logging with AOP
17
 */
18
class LoggingDemo
19
{
20
21
    /**
22
     * Executes a task and logs all incoming arguments
23
     *
24
     * @Loggable
25
     * @param mixed $task Some specific argument
26
     */
27
    public function execute($task)
28
    {
29
        $this->perform($task, 'first');
30
        $this->perform($task, 'second');
31
    }
32
33
    /**
34
     * Protected method can be also loggable
35
     *
36
     * @Loggable
37
     *
38
     * @param mixed $task Specific task
39
     * @param string $level
40
     */
41
    protected function perform($task, $level)
42
    {
43
        // some logic here
44
    }
45
46
    /**
47
     * Everything is possible with AOP, so static methods can be intercepted too
48
     *
49
     * @Loggable
50
     *
51
     * @param string $task Some specific argument
52
     */
53
    public static function runByName($task)
54
    {
55
        $instance = new static(); // Go! AOP requires LSB to work correctly
56
        $instance->execute($task);
57
    }
58
}
59