1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This software package is licensed under AGPL or Commercial license. |
5
|
|
|
* |
6
|
|
|
* @package maslosoft/mangan |
7
|
|
|
* @licence AGPL or Commercial |
8
|
|
|
* @copyright Copyright (c) Piotr Masełkowski <[email protected]> |
9
|
|
|
* @copyright Copyright (c) Maslosoft |
10
|
|
|
* @copyright Copyright (c) Others as mentioned in code |
11
|
|
|
* @link https://maslosoft.com/mangan/ |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Maslosoft\Mangan\Traits\Criteria; |
15
|
|
|
|
16
|
|
|
use Maslosoft\Addendum\Interfaces\AnnotatedInterface; |
17
|
|
|
use Maslosoft\Mangan\Criteria\ConditionDecorator; |
18
|
|
|
use Maslosoft\Mangan\Interfaces\ConditionDecoratorInterface; |
19
|
|
|
use Maslosoft\Mangan\Interfaces\Criteria\DecoratableInterface; |
20
|
|
|
use Maslosoft\Mangan\Interfaces\CriteriaInterface; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* DecoratableTrait |
24
|
|
|
* @see DecoratableInterface |
25
|
|
|
* @see CriteriaInterface |
26
|
|
|
* @author Piotr Maselkowski <pmaselkowski at gmail.com> |
27
|
|
|
*/ |
28
|
|
|
trait DecoratableTrait |
29
|
|
|
{ |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Condition decorator instance |
33
|
|
|
* @var ConditionDecoratorInterface |
34
|
|
|
*/ |
35
|
|
|
private $cd = null; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Get condition interface |
39
|
|
|
* @return ConditionDecoratorInterface |
40
|
|
|
*/ |
41
|
98 |
|
public function getCd() |
42
|
|
|
{ |
43
|
98 |
|
return $this->cd; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Set condition decorator interface |
48
|
|
|
* @param ConditionDecoratorInterface $cd |
49
|
|
|
* @return CriteriaInterface |
50
|
|
|
*/ |
51
|
107 |
|
public function setCd(ConditionDecoratorInterface $cd) |
52
|
|
|
{ |
53
|
107 |
|
$this->cd = $cd; |
54
|
107 |
|
return $this; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Decorate and sanitize criteria with provided model. |
59
|
|
|
* @param AnnotatedInterface $model Model to use for decorators and sanitizer when creating conditions. If null no decorators will be used. If model is provided it's sanitizers and decorators will be used. |
60
|
|
|
* @param ConditionDecoratorInterface $decorator |
61
|
|
|
* @return CriteriaInterface |
62
|
|
|
*/ |
63
|
104 |
|
public function decorateWith($model, ConditionDecoratorInterface $decorator = null) |
64
|
|
|
{ |
65
|
104 |
|
if (null !== $decorator) |
66
|
104 |
|
{ |
67
|
|
|
$this->cd = $decorator; |
68
|
|
|
} |
69
|
|
|
else |
70
|
|
|
{ |
71
|
104 |
|
$this->cd = new ConditionDecorator($model); |
72
|
|
|
} |
73
|
104 |
|
return $this; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
} |
77
|
|
|
|