1 | <?php |
||
53 | class ShouldOverwrite |
||
54 | { |
||
55 | use LookupMethodByType; |
||
56 | |||
57 | /** |
||
58 | * should we overwrite $ours's $property with the value of $theirs? |
||
59 | * |
||
60 | * @param mixed $ours |
||
61 | * the variable where $property may exist |
||
62 | * @param string $property |
||
63 | * the property on $ours whose fate we are deciding |
||
64 | * @param mixed $theirs |
||
65 | * the data we want to assign to the property |
||
66 | * @return boolean |
||
67 | * TRUE if we should overwrite the property's existing value |
||
68 | * with $value |
||
69 | * TRUE if $property currently has no value |
||
70 | * FALSE if we should merge $value into the property's exist |
||
71 | * value |
||
72 | */ |
||
73 | public function __invoke($ours, $property, $theirs) |
||
77 | |||
78 | /** |
||
79 | * should we overwrite $ours's $property with the value of $theirs? |
||
80 | * |
||
81 | * @param mixed $ours |
||
82 | * the variable where $property may exist |
||
83 | * @param string $property |
||
84 | * the property on $ours whose fate we are deciding |
||
85 | * @param mixed $theirs |
||
86 | * the data we want to assign to the property |
||
87 | * @return boolean |
||
88 | * TRUE if we should overwrite the property's existing value |
||
89 | * with $value |
||
90 | * TRUE if $property currently has no value |
||
91 | * FALSE if we should merge $value into the property's exist |
||
92 | * value |
||
93 | */ |
||
94 | public static function into($ours, $property, $theirs) |
||
99 | |||
100 | /** |
||
101 | * called when there's no entry in our dispatch table for a data type |
||
102 | * |
||
103 | * @param mixed $ours |
||
104 | * @return void |
||
105 | */ |
||
106 | private static function nothingMatchesTheInputType($ours) |
||
110 | |||
111 | /** |
||
112 | * should we overwrite $ours->$property with the value of $theirs? |
||
113 | * |
||
114 | * @param object $ours |
||
115 | * the object where $property may exist |
||
116 | * @param string $property |
||
117 | * the property on $ours whose fate we are deciding |
||
118 | * @param mixed $theirs |
||
119 | * the data we want to assign to the property |
||
120 | * @return boolean |
||
121 | * TRUE if we should overwrite the property's existing value |
||
122 | * with $value |
||
123 | * TRUE if $property currently has no value |
||
124 | * FALSE if we should merge $value into the property's exist |
||
125 | * value |
||
126 | */ |
||
127 | public static function intoObject($ours, $property, $theirs) |
||
136 | |||
137 | /** |
||
138 | * should we overwrite $ours->$property with the value of $theirs? |
||
139 | * |
||
140 | * @param object $ours |
||
141 | * the object where $property may exist |
||
142 | * @param string $property |
||
143 | * the property on $ours whose fate we are deciding |
||
144 | * @param mixed $theirs |
||
145 | * the data we want to assign to the property |
||
146 | * @return boolean |
||
147 | * TRUE if we should overwrite the property's existing value |
||
148 | * with $value |
||
149 | * TRUE if $property currently has no value |
||
150 | * FALSE if we should merge $value into the property's exist |
||
151 | * value |
||
152 | */ |
||
153 | private static function checkObject($ours, $property, $theirs) |
||
164 | |||
165 | /** |
||
166 | * should we overwrite $ours[$key] with the value of $theirs? |
||
167 | * |
||
168 | * @param array $ours |
||
169 | * the array where $key may exist |
||
170 | * @param string $key |
||
171 | * the index on $ours whose fate we are deciding |
||
172 | * @param mixed $theirs |
||
173 | * the data we want to assign to the index |
||
174 | * @return boolean |
||
175 | * TRUE if we should overwrite the index's existing value |
||
176 | * with $value |
||
177 | * TRUE if $key currently has no value |
||
178 | * FALSE if we should merge $value into the index's exist |
||
179 | * value |
||
180 | */ |
||
181 | public static function intoArray($ours, $key, $theirs) |
||
190 | |||
191 | /** |
||
192 | * should we overwrite $ours[$key] with the value of $theirs? |
||
193 | * |
||
194 | * @param array $ours |
||
195 | * the array where $key may exist |
||
196 | * @param string $key |
||
197 | * the index on $ours whose fate we are deciding |
||
198 | * @param mixed $theirs |
||
199 | * the data we want to assign to the index |
||
200 | * @return boolean |
||
201 | * TRUE if we should overwrite the index's existing value |
||
202 | * with $value |
||
203 | * TRUE if $key currently has no value |
||
204 | * FALSE if we should merge $value into the index's exist |
||
205 | * value |
||
206 | */ |
||
207 | private static function checkArray(array $ours, $key, $theirs) |
||
218 | |||
219 | /** |
||
220 | * lookup table of which method to call for which data type |
||
221 | * @var array |
||
222 | */ |
||
223 | private static $dispatchTable = [ |
||
224 | 'Array' => 'intoArray', |
||
225 | 'Object' => 'intoObject', |
||
226 | ]; |
||
227 | } |