1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* Go! AOP framework |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright 2012, 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\After; |
16
|
|
|
use Go\Lang\Annotation\Before; |
17
|
|
|
use Go\Lang\Annotation\Pointcut; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Healthy live aspect |
21
|
|
|
*/ |
22
|
|
|
class HealthyLiveAspect implements Aspect |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Pointcut for eat method |
26
|
|
|
* |
27
|
|
|
* @Pointcut("execution(public Demo\Example\HumanDemo->eat(*))") |
28
|
|
|
*/ |
29
|
|
|
protected function humanEat() {} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Washing hands before eating |
33
|
|
|
* |
34
|
|
|
* @param MethodInvocation $invocation Invocation |
35
|
|
|
* @Before("$this->humanEat") |
36
|
|
|
*/ |
37
|
|
|
protected function washUpBeforeEat(MethodInvocation $invocation) |
38
|
|
|
{ |
39
|
|
|
/** @var $person \Demo\Example\HumanDemo */ |
40
|
|
|
$person = $invocation->getThis(); |
41
|
|
|
$person->washUp(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Method that advices to clean the teeth after eating |
46
|
|
|
* |
47
|
|
|
* @param MethodInvocation $invocation Invocation |
48
|
|
|
* @After("$this->humanEat") |
49
|
|
|
*/ |
50
|
|
|
protected function cleanTeethAfterEat(MethodInvocation $invocation) |
51
|
|
|
{ |
52
|
|
|
/** @var $person \Demo\Example\HumanDemo */ |
53
|
|
|
$person = $invocation->getThis(); |
54
|
|
|
$person->cleanTeeth(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Method that advice to clean the teeth before going to sleep |
59
|
|
|
* |
60
|
|
|
* @param MethodInvocation $invocation Invocation |
61
|
|
|
* @Before("execution(public Demo\Example\HumanDemo->sleep(*))") |
62
|
|
|
*/ |
63
|
|
|
protected function cleanTeethBeforeSleep(MethodInvocation $invocation) |
64
|
|
|
{ |
65
|
|
|
/** @var $person \Demo\Example\HumanDemo */ |
66
|
|
|
$person = $invocation->getThis(); |
67
|
|
|
$person->cleanTeeth(); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|