1 | <?php namespace Fenos\Notifynder\Builder; |
||
21 | class NotifynderBuilder implements ArrayAccess |
||
22 | { |
||
23 | use BuilderRules; |
||
24 | |||
25 | /** |
||
26 | * @var string notification to store |
||
27 | */ |
||
28 | public $date; |
||
29 | |||
30 | /** |
||
31 | * Builder data |
||
32 | * |
||
33 | * @var array |
||
34 | */ |
||
35 | protected $notifications = []; |
||
36 | |||
37 | /** |
||
38 | * @var NotifynderCategory |
||
39 | */ |
||
40 | private $notifynderCategory; |
||
41 | |||
42 | /** |
||
43 | * @param NotifynderCategory $notifynderCategory |
||
44 | */ |
||
45 | function __construct(NotifynderCategory $notifynderCategory) |
||
49 | |||
50 | /** |
||
51 | * Set who will send the notification |
||
52 | * |
||
53 | * @return $this |
||
54 | */ |
||
55 | public function from() |
||
63 | |||
64 | /** |
||
65 | * Set who will receive the notification |
||
66 | * |
||
67 | * @return $this |
||
68 | */ |
||
69 | public function to() |
||
77 | |||
78 | /** |
||
79 | * Set the url of the notification |
||
80 | * |
||
81 | * @param $url |
||
82 | * @return $this |
||
83 | */ |
||
84 | public function url($url) |
||
92 | |||
93 | /** |
||
94 | * Set expire time |
||
95 | * |
||
96 | * @param $datetime |
||
97 | * @return $this |
||
98 | */ |
||
99 | public function expire($datetime) |
||
106 | |||
107 | /** |
||
108 | * Set Category and covert it, to the id |
||
109 | * if name of it given |
||
110 | * |
||
111 | * @param $category |
||
112 | * @return $this |
||
113 | */ |
||
114 | public function category($category) |
||
125 | |||
126 | /** |
||
127 | * Set extra value |
||
128 | * |
||
129 | * @param $extra |
||
130 | * @return $this |
||
131 | */ |
||
132 | public function extra(array $extra = []) |
||
142 | |||
143 | /** |
||
144 | * Build the array with the builder inside |
||
145 | * a Closure, it has more flexibility for |
||
146 | * the generation of your array |
||
147 | * |
||
148 | * |
||
149 | * @param callable|Closure $closure |
||
150 | * @return array|false |
||
151 | * @throws NotificationBuilderException |
||
152 | */ |
||
153 | public function raw(Closure $closure) |
||
163 | |||
164 | /** |
||
165 | * Loop the datas for create |
||
166 | * multi notifications array |
||
167 | * |
||
168 | * @param $dataToIterate |
||
169 | * @param Closure $builder |
||
170 | * @return $this |
||
171 | * @throws NotificationBuilderException |
||
172 | */ |
||
173 | public function loop($dataToIterate, Closure $builder) |
||
192 | |||
193 | /** |
||
194 | * Compose the builder to |
||
195 | * the array |
||
196 | * |
||
197 | * @throws NotificationBuilderException |
||
198 | * @return mixed |
||
199 | */ |
||
200 | public function toArray() |
||
233 | |||
234 | /** |
||
235 | * Refresh the state of the notifications |
||
236 | */ |
||
237 | public function refresh() |
||
243 | |||
244 | /** |
||
245 | * @param $var |
||
246 | * @return bool |
||
247 | */ |
||
248 | protected function isIterable($var) |
||
252 | |||
253 | /** |
||
254 | * It set the entity who will do |
||
255 | * the action of receive or |
||
256 | * send |
||
257 | * |
||
258 | * @param $from |
||
259 | * @param $property |
||
260 | * @return array |
||
261 | */ |
||
262 | protected function setEntityAction($from, $property) |
||
277 | |||
278 | /** |
||
279 | * If the values passed are 2 or more, |
||
280 | * it means that you spefied the entity |
||
281 | * over then the id |
||
282 | * |
||
283 | * @param array $info |
||
284 | * @return bool |
||
285 | */ |
||
286 | protected function hasEntity(array $info) |
||
290 | |||
291 | /** |
||
292 | * Set date on the array |
||
293 | */ |
||
294 | protected function setDate() |
||
301 | |||
302 | /** |
||
303 | * @return string |
||
304 | */ |
||
305 | protected function getDate() |
||
309 | |||
310 | /** |
||
311 | * Set builder Data |
||
312 | * |
||
313 | * @param $field |
||
314 | * @param $data |
||
315 | */ |
||
316 | protected function setBuilderData($field, $data) |
||
320 | |||
321 | |||
322 | /** |
||
323 | * @param mixed $offset |
||
324 | * @return bool |
||
325 | */ |
||
326 | public function offsetExists($offset) |
||
330 | |||
331 | |||
332 | /** |
||
333 | * @param mixed $offset |
||
334 | * @return mixed |
||
335 | */ |
||
336 | public function offsetGet($offset) |
||
340 | |||
341 | |||
342 | /** |
||
343 | * @param mixed $offset |
||
344 | * @param mixed $value |
||
345 | */ |
||
346 | public function offsetSet($offset, $value) |
||
357 | |||
358 | /** |
||
359 | * @param mixed $offset |
||
360 | * @return null |
||
361 | */ |
||
362 | public function offsetUnset($offset) |
||
366 | } |
||
367 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.