1 | <?php |
||
16 | trait ConditionalizableTrait |
||
17 | { |
||
18 | /** |
||
19 | * Condition needed to render the entity. |
||
20 | * |
||
21 | * @var string|boolean |
||
22 | */ |
||
23 | private $condition; |
||
24 | |||
25 | /** |
||
26 | * rendered condition. |
||
27 | * |
||
28 | * @var string|boolean |
||
29 | */ |
||
30 | private $resolvedCondition; |
||
31 | |||
32 | /** |
||
33 | * @return boolean |
||
34 | */ |
||
35 | public function resolvedCondition() |
||
49 | |||
50 | /** |
||
51 | * @return boolean|string |
||
52 | */ |
||
53 | public function condition() |
||
57 | |||
58 | /** |
||
59 | * @param boolean|string $condition A condition to evaluate. |
||
60 | * @throws InvalidArgumentException If the condition is not a string nor boolean. |
||
61 | * @return self |
||
62 | */ |
||
63 | public function setCondition($condition) |
||
75 | |||
76 | /** |
||
77 | * Resolve the conditional logic. |
||
78 | * |
||
79 | * @param mixed $condition The condition. |
||
80 | * @return boolean|null |
||
81 | */ |
||
82 | final protected function parseConditionalLogic($condition) |
||
104 | |||
105 | /** |
||
106 | * Parse the widget's conditional logic. |
||
107 | * |
||
108 | * @param callable|string $condition The callable or renderable condition. |
||
109 | * @return boolean |
||
110 | */ |
||
111 | protected function resolveConditionalLogic($condition) |
||
135 | } |
||
136 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.