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