|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: peter |
|
5
|
|
|
* Date: 18.06.18 |
|
6
|
|
|
* Time: 21:59 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Maslosoft\Mangan; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
use Maslosoft\Addendum\Interfaces\AnnotatedInterface; |
|
13
|
|
|
use Maslosoft\Mangan\Interfaces\AspectsInterface; |
|
14
|
|
|
|
|
15
|
|
|
class AspectManager |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* Gracefully add aspect, this will check |
|
19
|
|
|
* if model implements AspectsInterface |
|
20
|
|
|
* and add only if it does. |
|
21
|
|
|
* |
|
22
|
|
|
* @see AspectsInterface |
|
23
|
|
|
* @param AnnotatedInterface $model |
|
24
|
|
|
* @param $aspect |
|
25
|
|
|
*/ |
|
26
|
119 |
|
public static function addAspect(AnnotatedInterface $model, $aspect) |
|
27
|
|
|
{ |
|
28
|
119 |
|
if($model instanceof AspectsInterface) |
|
29
|
|
|
{ |
|
30
|
44 |
|
$model->addAspect($aspect); |
|
31
|
|
|
} |
|
32
|
119 |
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Gracefully remove aspect, this will check |
|
36
|
|
|
* if model implements AspectsInterface |
|
37
|
|
|
* and remove only if it does. |
|
38
|
|
|
* |
|
39
|
|
|
* @see AspectsInterface |
|
40
|
|
|
* @param AnnotatedInterface $model |
|
41
|
|
|
* @param $aspect |
|
42
|
|
|
*/ |
|
43
|
119 |
|
public static function removeAspect(AnnotatedInterface $model, $aspect) |
|
44
|
|
|
{ |
|
45
|
119 |
|
if($model instanceof AspectsInterface) |
|
46
|
|
|
{ |
|
47
|
44 |
|
$model->removeAspect($aspect); |
|
48
|
|
|
} |
|
49
|
119 |
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Gracefully check if has aspect, this will check |
|
53
|
|
|
* if model implements `AspectsInterface` |
|
54
|
|
|
* and check only if it does. If model does not |
|
55
|
|
|
* implement AspectsInterface it will return `false`, |
|
56
|
|
|
* like if it has no such aspect. |
|
57
|
|
|
* |
|
58
|
|
|
* @see AspectsInterface |
|
59
|
|
|
* @param AnnotatedInterface $model |
|
60
|
|
|
* @param $aspect |
|
61
|
|
|
* @return bool|string |
|
62
|
|
|
*/ |
|
63
|
1 |
|
public static function hasAspect(AnnotatedInterface $model, $aspect) |
|
64
|
|
|
{ |
|
65
|
1 |
|
if($model instanceof AspectsInterface) |
|
66
|
|
|
{ |
|
67
|
1 |
|
return $model->hasAspect($aspect); |
|
68
|
|
|
} |
|
69
|
|
|
return false; |
|
70
|
|
|
} |
|
71
|
|
|
} |