1 | <?php |
||
32 | trait RowTrait |
||
33 | { |
||
34 | |||
35 | /** |
||
36 | * The actual row, that has to be processed. |
||
37 | * |
||
38 | * @var array |
||
39 | */ |
||
40 | protected $row = array(); |
||
41 | |||
42 | /** |
||
43 | * The flag that stop's overserver execution on the actual row. |
||
44 | * |
||
45 | * @var boolean |
||
46 | */ |
||
47 | protected $skipRow = false; |
||
48 | |||
49 | /** |
||
50 | * Stop's observer execution on the actual row. |
||
51 | * |
||
52 | * @param boolean $skip The flag to skip row exection or not |
||
53 | * |
||
54 | * @return void |
||
55 | */ |
||
56 | 1 | public function skipRow($skip = true) |
|
60 | |||
61 | /** |
||
62 | * Query's whether or not the observer execution for the given row has to be skipped. |
||
63 | * |
||
64 | * @return boolean TRUE if the observer execution has to be skipped, else FALSE |
||
65 | */ |
||
66 | public function rowHasToBeSkipped() |
||
70 | |||
71 | /** |
||
72 | * Set's the actual row, that has to be processed. |
||
73 | * |
||
74 | * @param array $row The row |
||
75 | * |
||
76 | * @return void |
||
77 | */ |
||
78 | 10 | public function setRow(array $row) |
|
82 | |||
83 | /** |
||
84 | * Return's the actual row. |
||
85 | * |
||
86 | * @return array The actual row |
||
87 | */ |
||
88 | 14 | public function getRow() |
|
92 | |||
93 | /** |
||
94 | * Query whether or not a value for the column with the passed name exists. |
||
95 | * |
||
96 | * @param string $name The column name to query for a valid value |
||
97 | * |
||
98 | * @return boolean TRUE if the value is set, else FALSE |
||
99 | */ |
||
100 | 2 | public function hasValue($name) |
|
115 | |||
116 | /** |
||
117 | * Set the value in the passed column name. |
||
118 | * |
||
119 | * @param string $name The column name to set the value for |
||
120 | * @param mixed $value The value to set |
||
121 | * |
||
122 | * @return void |
||
123 | */ |
||
124 | 4 | protected function setValue($name, $value) |
|
128 | |||
129 | /** |
||
130 | * Resolve's the value with the passed colum name from the actual row. If a callback will |
||
131 | * be passed, the callback will be invoked with the found value as parameter. If |
||
132 | * the value is NULL or empty, the default value will be returned. |
||
133 | * |
||
134 | * @param string $name The name of the column to return the value for |
||
135 | * @param mixed|null $default The default value, that has to be returned, if the row's value is empty |
||
136 | * @param callable|null $callback The callback that has to be invoked on the value, e. g. to format it |
||
137 | * |
||
138 | * @return mixed|null The, almost formatted, value |
||
139 | */ |
||
140 | 15 | public function getValue($name, $default = null, callable $callback = null) |
|
169 | } |
||
170 |
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.