1 | <?php |
||
19 | class FirebaseLib implements FirebaseInterface |
||
20 | { |
||
21 | protected $baseURI; |
||
22 | protected $timeout; |
||
23 | protected $token; |
||
24 | protected $curlHandler; |
||
25 | protected $sslConnection; |
||
26 | |||
27 | /** |
||
28 | * Constructor |
||
29 | * |
||
30 | * @param string $baseURI |
||
31 | * @param string $token |
||
32 | */ |
||
33 | public function __construct(string $baseURI = '', string $token = '') |
||
49 | |||
50 | /** |
||
51 | * Initializing the CURL handler |
||
52 | * |
||
53 | * @return void |
||
54 | */ |
||
55 | public function initCurlHandler(): void |
||
59 | |||
60 | /** |
||
61 | * Closing the CURL handler |
||
62 | * |
||
63 | * @return void |
||
64 | */ |
||
65 | public function closeCurlHandler(): void |
||
69 | |||
70 | /** |
||
71 | * Enabling/Disabling SSL Connection |
||
72 | * |
||
73 | * @param bool $enableSSLConnection |
||
74 | */ |
||
75 | public function setSSLConnection(bool $enableSSLConnection): void |
||
79 | |||
80 | /** |
||
81 | * Returns status of SSL Connection |
||
82 | * |
||
83 | * @return boolean |
||
84 | */ |
||
85 | public function getSSLConnection(): bool |
||
89 | |||
90 | /** |
||
91 | * Sets Token |
||
92 | * |
||
93 | * @param string $token Token |
||
94 | * @return void |
||
95 | */ |
||
96 | public function setToken(string $token): void |
||
100 | |||
101 | /** |
||
102 | * Get Token |
||
103 | * |
||
104 | * @return string |
||
105 | */ |
||
106 | public function getToken(): string |
||
110 | |||
111 | /** |
||
112 | * Sets Base URI, ex: http://yourcompany.firebase.com/youruser |
||
113 | * |
||
114 | * @param string $baseURI Base URI |
||
115 | * @return void |
||
116 | */ |
||
117 | public function setBaseURI(string $baseURI): void |
||
122 | |||
123 | /** |
||
124 | * Gets Base URI |
||
125 | * |
||
126 | * @return string |
||
127 | */ |
||
128 | public function getBaseURI(): string |
||
132 | |||
133 | /** |
||
134 | * Returns with the normalized JSON absolute path |
||
135 | * |
||
136 | * @param string $path Path |
||
137 | * @param array $options Options |
||
138 | * @return string |
||
139 | */ |
||
140 | private function getJsonPath(string $path, $options = []): string |
||
150 | |||
151 | /** |
||
152 | * Sets REST call timeout in seconds |
||
153 | * |
||
154 | * @param int $seconds Seconds to timeout |
||
155 | * @return void |
||
156 | */ |
||
157 | public function setTimeOut(int $seconds): void |
||
161 | |||
162 | /** |
||
163 | * Gets timeout in seconds |
||
164 | * |
||
165 | * @return int |
||
166 | */ |
||
167 | public function getTimeOut(): int |
||
171 | |||
172 | /** |
||
173 | * Writing data into Firebase with a PUT request |
||
174 | * HTTP 200: Ok |
||
175 | * |
||
176 | * @param string $path Path |
||
177 | * @param mixed $data Data |
||
178 | * @param array $options Options |
||
179 | * @return mixed |
||
180 | */ |
||
181 | public function set(string $path, $data, array $options = []) |
||
185 | |||
186 | /** |
||
187 | * Pushing data into Firebase with a POST request |
||
188 | * HTTP 200: Ok |
||
189 | * |
||
190 | * @param string $path Path |
||
191 | * @param mixed $data Data |
||
192 | * @param array $options Options |
||
193 | * @return mixed |
||
194 | */ |
||
195 | public function push(string $path, $data, array $options = []) |
||
199 | |||
200 | /** |
||
201 | * Updating data into Firebase with a PATH request |
||
202 | * HTTP 200: Ok |
||
203 | * |
||
204 | * @param string $path Path |
||
205 | * @param mixed $data Data |
||
206 | * @param array $options Options |
||
207 | * @return mixed |
||
208 | */ |
||
209 | public function update(string $path, $data, array $options = []) |
||
213 | |||
214 | /** |
||
215 | * Reading data from Firebase |
||
216 | * HTTP 200: Ok |
||
217 | * |
||
218 | * @param string $path Path |
||
219 | * @param array $options Options |
||
220 | * @return mixed |
||
221 | */ |
||
222 | public function get(string $path, array $options = []) |
||
227 | |||
228 | /** |
||
229 | * Deletes data from Firebase |
||
230 | * HTTP 204: Ok |
||
231 | * |
||
232 | * @param string $path Path |
||
233 | * @param array $options Options |
||
234 | * @return mixed |
||
235 | */ |
||
236 | public function delete(string $path, array $options = []) |
||
241 | |||
242 | /** |
||
243 | * Returns with Initialized CURL Handler |
||
244 | * |
||
245 | * @param string $path Path |
||
246 | * @param string $mode Mode |
||
247 | * @param array $options Options |
||
248 | * @return mixed |
||
249 | */ |
||
250 | private function getCurlHandler(string $path, string $mode, array $options = []) |
||
263 | |||
264 | /** |
||
265 | * Writes Data to Firebase API |
||
266 | * |
||
267 | * @param string $path |
||
268 | * @param $data |
||
269 | * @param string $method |
||
270 | * @param array $options |
||
271 | * @return mixed |
||
272 | */ |
||
273 | private function writeData(string $path, $data, string $method = 'PUT', array $options = []) |
||
285 | } |
||
286 |