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 | * The number of rows that has been skipped. |
||
51 | * |
||
52 | * @var integer |
||
53 | */ |
||
54 | private $skippedRows = 0; |
||
55 | |||
56 | /** |
||
57 | * Stop's observer execution on the actual row. |
||
58 | * |
||
59 | * @param boolean $skip The flag to skip row exection or not |
||
60 | * |
||
61 | * @return void |
||
62 | */ |
||
63 | 1 | public function skipRow($skip = true) |
|
74 | |||
75 | /** |
||
76 | * Query's whether or not the observer execution for the given row has to be skipped. |
||
77 | * |
||
78 | * @return boolean TRUE if the observer execution has to be skipped, else FALSE |
||
79 | */ |
||
80 | public function rowHasToBeSkipped() |
||
84 | |||
85 | /** |
||
86 | * Set's the actual row, that has to be processed. |
||
87 | * |
||
88 | * @param array $row The row |
||
89 | * |
||
90 | * @return void |
||
91 | */ |
||
92 | 10 | public function setRow(array $row) |
|
96 | |||
97 | /** |
||
98 | * Return's the actual row. |
||
99 | * |
||
100 | * @return array The actual row |
||
101 | */ |
||
102 | 14 | public function getRow() |
|
106 | |||
107 | /** |
||
108 | * Query whether or not a value for the column with the passed name exists. |
||
109 | * |
||
110 | * @param string $name The column name to query for a valid value |
||
111 | * |
||
112 | * @return boolean TRUE if the value is set, else FALSE |
||
113 | */ |
||
114 | 2 | public function hasValue($name) |
|
129 | |||
130 | /** |
||
131 | * Set the value in the passed column name. |
||
132 | * |
||
133 | * @param string $name The column name to set the value for |
||
134 | * @param mixed $value The value to set |
||
135 | * |
||
136 | * @return void |
||
137 | */ |
||
138 | 4 | protected function setValue($name, $value) |
|
142 | |||
143 | /** |
||
144 | * Resolve's the value with the passed colum name from the actual row. If a callback will |
||
145 | * be passed, the callback will be invoked with the found value as parameter. If |
||
146 | * the value is NULL or empty, the default value will be returned. |
||
147 | * |
||
148 | * @param string $name The name of the column to return the value for |
||
149 | * @param mixed|null $default The default value, that has to be returned, if the row's value is empty |
||
150 | * @param callable|null $callback The callback that has to be invoked on the value, e. g. to format it |
||
151 | * |
||
152 | * @return mixed|null The, almost formatted, value |
||
153 | */ |
||
154 | 15 | public function getValue($name, $default = null, callable $callback = null) |
|
183 | } |
||
184 |
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.