PHP code example of wead / google-firestore-rest-client
1. Go to this page and download the library: Download wead/google-firestore-rest-client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
wead / google-firestore-rest-client example snippets
Wead\Firestore\WeadFirestoreClient;
// download this json file from Google Console API
// https://cloud.google.com/iam/docs/creating-managing-service-account-keys
$firestorage = new WeadFirestoreClient("./google-account-services.json");
// it's only get collection object, but not create it
$collection = $firestorage->getCollection('users');
// set new or existing document inside this collection
$doc = $firestorage->getDocument($collection, "adriano");
$doc2 = $firestorage->getDocument($collection, "temp-to-remove"); // delete document example
// insert or update document with content
// a fild will be removed if already exists online but not informed here
// suport nested array and objects
$outDoc = $firestorage->setDocument($doc, [
"name" => "Adriano Maciel",
"email" => "[email protected]",
"social" => [
[
"dev" => [
"github" => [
"https://github.com/adrianowead",
"https://github.com/adrianowead/google-firestore-rest-client",
],
"https://pt.stackoverflow.com/users/109468/adriano-maciel",
],
],
[
"https://www.linkedin.com/in/adrianowead",
],
"type_int" => 1,
"type_bool" => false,
"type_null" => null,
"string_empty" => "",
"array_empty" => [],
"array_null" => [null],
"array_bool" => [false],
"array_string_empty" => [""],
"object_empty" => json_decode('{}'),
"object_string_empty" => json_decode('{"0":""}'),
"object_null" => json_decode('{"0":null}'),
"object_bool" => json_decode('{"0":false}'),
]
]);
// get a object with all information and fields inside this document
$read = $firestorage->readDocument($doc);
print_r($read);
// write and remove temp document
$outDoc = $firestorage->setDocument($doc2, [
"content" => "to be removed"
]);
$read = $firestorage->readDocument($doc2);
print_r($read);
// delete doc
$firestorage->removeDocument($doc2);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.