1 | <?php |
||
12 | abstract class MoipResource implements JsonSerializable { |
||
13 | /** |
||
14 | * Version of API. |
||
15 | * |
||
16 | * @const string |
||
17 | */ |
||
18 | const VERSION = 'v2'; |
||
19 | |||
20 | /** |
||
21 | * @var \Moip\Moip |
||
22 | */ |
||
23 | protected $moip; |
||
24 | |||
25 | /** |
||
26 | * @var \stdClass |
||
27 | */ |
||
28 | protected $data; |
||
29 | |||
30 | /** |
||
31 | * Initialize a new instance. |
||
32 | */ |
||
33 | abstract protected function initialize(); |
||
34 | |||
35 | /** |
||
36 | * Mount information of a determined object. |
||
37 | * |
||
38 | * @param \stdClass $response |
||
39 | * |
||
40 | * @return mixed |
||
41 | */ |
||
42 | abstract protected function populate(stdClass $response); |
||
43 | |||
44 | /** |
||
45 | * Create a new instance. |
||
46 | * |
||
47 | * @param \Moip\Moip $moip |
||
48 | */ |
||
49 | public function __construct(Moip $moip) { |
||
54 | |||
55 | /** |
||
56 | * Create a new connecttion. |
||
57 | * |
||
58 | * @return \Moip\Http\HTTPConnection |
||
59 | */ |
||
60 | protected function createConnection() { |
||
63 | |||
64 | /** |
||
65 | * Get a key of an object if he exist. |
||
66 | * |
||
67 | * @param string $key |
||
68 | * @param \stdClass|null $data |
||
69 | * |
||
70 | * @return mixed |
||
71 | */ |
||
72 | protected function getIfSet($key, stdClass $data = null) { |
||
84 | |||
85 | protected function getIfSetDateFmt($key, $fmt, stdClass $data=null){ |
||
94 | |||
95 | /** |
||
96 | * Get a key, representing a date (Y-m-d), of an object if it exists. |
||
97 | * @param string $key |
||
98 | * @param stdClass|null $data |
||
99 | * @return \DateTime|null |
||
100 | */ |
||
101 | protected function getIfSetDate($key, stdClass $data = null) { |
||
106 | |||
107 | /** |
||
108 | * Get a key representing a datetime (\Datetime::ATOM), of an object if it exists. |
||
109 | * @param string $key |
||
110 | * @param stdClass|null $data |
||
111 | * @return \DateTime|null |
||
112 | */ |
||
113 | |||
114 | protected function getIfSetDateTime($key, stdClass $data = null) { |
||
117 | |||
118 | /** |
||
119 | * Specify data which should be serialized to JSON. |
||
120 | * |
||
121 | * @return \stdClass |
||
122 | */ |
||
123 | public function jsonSerialize() { |
||
126 | |||
127 | /** |
||
128 | * Find by path. |
||
129 | * |
||
130 | * @param string $path |
||
131 | * |
||
132 | * @return stdClass |
||
133 | */ |
||
134 | public function getByPath($path) { |
||
146 | |||
147 | /** |
||
148 | * Create a new item in Moip. |
||
149 | * |
||
150 | * @param string $path |
||
151 | * |
||
152 | * @return stdClass |
||
153 | */ |
||
154 | public function createResource($path) { |
||
170 | } |
||
171 |