1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* ZfTable ( Module for Zend Framework 2) |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (c) 2013 Piotr Duda [email protected] |
6
|
|
|
* @license MIT License |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace ZfTable\Decorator; |
10
|
|
|
|
11
|
|
|
use ZfTable\AbstractCommon; |
12
|
|
|
use ZfTable\Decorator\Condition\ConditionFactory; |
13
|
|
|
|
14
|
|
|
abstract class AbstractDecorator extends AbstractCommon implements DecoratorInterface |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Decorator is adding before cotext |
19
|
|
|
*/ |
20
|
|
|
const PRE_CONTEXT = 'pre'; |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Decorator is adding after context |
25
|
|
|
*/ |
26
|
|
|
const POST_CONTEXT = 'post'; |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Decorator reset context and return only new context |
31
|
|
|
*/ |
32
|
|
|
const RESET_CONTEXT = 'reset'; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Collections of conditions objects |
36
|
|
|
* @var array |
37
|
|
|
*/ |
38
|
|
|
protected $conditions = array(); |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Add new condition to decorator |
42
|
|
|
* |
43
|
|
|
* @param string $name |
44
|
|
|
* @param array $options |
45
|
|
|
* @return $this|null |
46
|
|
|
*/ |
47
|
|
|
public function addCondition($name, $options) |
48
|
|
|
{ |
49
|
|
|
if ($this instanceof DataAccessInterface) { |
50
|
|
|
$condition = ConditionFactory::factory($name, $options); |
51
|
|
|
$condition->setDecorator($this); |
|
|
|
|
52
|
|
|
$this->attachCondition($condition); |
53
|
|
|
return $this; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Attach new condition |
59
|
|
|
* |
60
|
|
|
* @param Condition\AbstractCondition $condition |
61
|
|
|
*/ |
62
|
|
|
protected function attachCondition($condition) |
63
|
|
|
{ |
64
|
|
|
$this->conditions[] = $condition; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Check if all conditions are valid |
69
|
|
|
* |
70
|
|
|
* @return boolean |
71
|
|
|
*/ |
72
|
|
|
public function validConditions() |
73
|
|
|
{ |
74
|
|
|
if (!count($this->conditions)) { |
75
|
|
|
return true; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
foreach ($this->conditions as $condition) { |
79
|
|
|
if (!$condition->isValid()) { |
80
|
|
|
return false; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return true; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: