1 | <?php |
||
15 | abstract class LazyResource extends Model |
||
16 | { |
||
17 | /** |
||
18 | * This class is a ghost object that lazy loads the full record only when needed. |
||
19 | * If $initialized is false, it means we haven't yet loaded the full record. |
||
20 | * We can still have incomplete data from a search response. |
||
21 | */ |
||
22 | protected $initialized = false; |
||
23 | |||
24 | public function __construct(Client $client) |
||
28 | |||
29 | /** |
||
30 | * Check if we have the full representation of our data object. |
||
31 | * |
||
32 | * @param \stdClass $data |
||
33 | * @return boolean |
||
34 | */ |
||
35 | abstract protected function isInitialized($data); |
||
36 | |||
37 | /** |
||
38 | * Load data onto this object. Chainable method. |
||
39 | * |
||
40 | * @param \stdClass $data |
||
41 | * |
||
42 | * @return self |
||
43 | */ |
||
44 | public function init($data = null) |
||
65 | |||
66 | /** |
||
67 | * Get the model data. |
||
68 | */ |
||
69 | protected function fetchData() |
||
73 | |||
74 | /** |
||
75 | * Store data onto object. Can be overriden. |
||
76 | * |
||
77 | * @param mixed $data |
||
78 | */ |
||
79 | protected function setData($data) |
||
82 | |||
83 | /** |
||
84 | * Get the raw data object. |
||
85 | */ |
||
86 | public function getData() |
||
90 | |||
91 | /** |
||
92 | * Check if the object exists. |
||
93 | */ |
||
94 | public function exists() |
||
103 | |||
104 | /** |
||
105 | * Generate the base URL for this resource. |
||
106 | * |
||
107 | * @return string |
||
108 | */ |
||
109 | abstract protected function urlBase(); |
||
110 | |||
111 | /** |
||
112 | * Build a full URL for a resource. |
||
113 | * |
||
114 | * @param string $url |
||
115 | * @param array $query |
||
116 | * @return UriInterface |
||
117 | */ |
||
118 | protected function url($url = '', $query = []) |
||
122 | } |
||
123 |