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