1 | <?php |
||
21 | trait DataTrait |
||
22 | { |
||
23 | |||
24 | private $data = null; |
||
25 | |||
26 | /** |
||
27 | * Returns the data items currently available, ensures that result is at leas empty array |
||
28 | * @param boolean $refresh whether the data should be re-fetched from persistent storage. |
||
29 | * @return array the list of data items currently available in this data provider. |
||
30 | */ |
||
31 | 4 | public function getData($refresh = false) |
|
32 | { |
||
33 | 4 | if ($this->data === null || $refresh) |
|
34 | 4 | { |
|
35 | 4 | $this->data = $this->fetchData(); |
|
36 | 4 | } |
|
37 | 4 | if ($this->data === null) |
|
38 | 4 | { |
|
39 | return []; |
||
40 | } |
||
41 | 4 | return $this->data; |
|
42 | } |
||
43 | |||
44 | /** |
||
45 | * Manually set data. This is for special cases only, |
||
46 | * usually should not be used. |
||
47 | * |
||
48 | * @param array $data |
||
49 | */ |
||
50 | public function setData($data) |
||
54 | |||
55 | abstract protected function fetchData(); |
||
56 | } |
||
57 |