Completed
Push — master ( 144202...6a00f8 )
by Peter
11:59
created

DataTrait::fetchData()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 1
ccs 0
cts 0
cp 0
nc 1
1
<?php
2
3
/*
4
 * To change this license header, choose License Headers in Project Properties.
5
 * To change this template file, choose Tools | Templates
6
 * and open the template in the editor.
7
 */
8
9
namespace Maslosoft\Mangan\Traits\DataProvider;
10
11
/**
12
 * DataTrait
13
 *
14
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
15
 */
16
trait DataTrait
17
{
18
19
	private $data = null;
20
21
	/**
22
	 * Returns the data items currently available, ensures that result is at leas empty array
23
	 * @param boolean $refresh whether the data should be re-fetched from persistent storage.
24
	 * @return array the list of data items currently available in this data provider.
25
	 */
26 1
	public function getData($refresh = false)
27
	{
28 1
		if ($this->data === null || $refresh)
29 1
		{
30 1
			$this->data = $this->fetchData();
31 1
		}
32 1
		if ($this->data === null)
33 1
		{
34
			return [];
35
		}
36 1
		return $this->data;
37
	}
38
39
	abstract protected function fetchData();
40
}
41