1 | <?php |
||
8 | abstract class GhostModel extends Model |
||
9 | { |
||
10 | /** |
||
11 | * This class is a ghost object that lazy loads the full record only when needed. |
||
12 | * If $initialized is false, it means we haven't yet loaded the full record. |
||
13 | * We can still have incomplete data from a search response. |
||
14 | */ |
||
15 | protected $initialized = false; |
||
16 | |||
17 | public function __construct(Client $client) |
||
21 | |||
22 | /** |
||
23 | * Check if we have the full representation of our data object. |
||
24 | * |
||
25 | * @param \stdClass $data |
||
26 | * @return boolean |
||
27 | */ |
||
28 | abstract protected function isInitialized($data); |
||
29 | |||
30 | /** |
||
31 | * Load data onto this object. Chainable method. |
||
32 | * |
||
33 | * @param \stdClass $data |
||
34 | * |
||
35 | * @return self |
||
36 | */ |
||
37 | public function init($data = null) |
||
58 | |||
59 | /** |
||
60 | * Get the model data. |
||
61 | */ |
||
62 | protected function fetchData() |
||
66 | |||
67 | /** |
||
68 | * Store data onto object. Can be overriden. |
||
69 | * |
||
70 | * @param \stdClass $data |
||
71 | */ |
||
72 | protected function setData(\stdClass $data) |
||
75 | |||
76 | /** |
||
77 | * Get the raw data object. |
||
78 | */ |
||
79 | public function getData() |
||
83 | |||
84 | /** |
||
85 | * Check if the object exists. |
||
86 | */ |
||
87 | public function exists() |
||
95 | |||
96 | /** |
||
97 | * Generate the base URL for this resource. |
||
98 | * |
||
99 | * @return string |
||
100 | */ |
||
101 | abstract protected function urlBase(); |
||
102 | |||
103 | /** |
||
104 | * Build a full URL for a resource. |
||
105 | * |
||
106 | * @param string $url |
||
107 | * @param array $query |
||
108 | * @return UriInterface |
||
109 | */ |
||
110 | protected function url($url = '', $query = []) |
||
114 | } |