1 | <?php |
||
11 | abstract class LazyResourceList extends LazyResource implements \Countable |
||
12 | { |
||
13 | /* @var array */ |
||
14 | protected $resources = []; |
||
15 | |||
16 | /** |
||
17 | * The key in the response object that points to the resource list. |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $responseKey; |
||
22 | |||
23 | /** |
||
24 | * LazyResourceList constructor. |
||
25 | * |
||
26 | * @param Client $client |
||
27 | * @param string $responseKey |
||
28 | */ |
||
29 | public function __construct(Client $client, $responseKey) |
||
34 | |||
35 | /** |
||
36 | * Convert a data element to a resource object. |
||
37 | * |
||
38 | * @param $data |
||
39 | * @return mixed |
||
40 | */ |
||
41 | abstract protected function convertToResource($data); |
||
42 | |||
43 | /** |
||
44 | * Called when data is available to be processed. |
||
45 | * |
||
46 | * @param mixed $data |
||
47 | */ |
||
48 | public function onData($data) |
||
57 | |||
58 | /** |
||
59 | * Check if we have the full representation of our data object. |
||
60 | * |
||
61 | * @param \stdClass $data |
||
62 | * @return boolean |
||
63 | */ |
||
64 | protected function isInitialized($data) |
||
68 | |||
69 | /** |
||
70 | * Get all the resources. |
||
71 | * |
||
72 | * @return array |
||
73 | */ |
||
74 | public function all() |
||
78 | |||
79 | /** |
||
80 | * Number of resources. |
||
81 | * |
||
82 | * @link http://php.net/manual/en/countable.count.php |
||
83 | * |
||
84 | * @return int The number of resources as an integer. |
||
85 | */ |
||
86 | public function count() |
||
90 | } |
||
91 |