wead/google-firestore-rest-client

This package is abandoned and no longer maintained. The author suggests using the google/cloud-firestore package instead.

1.0.8 2022-05-23 14:53 UTC

README

Warning This package is abandoned in favor of Cloud Firestore client for PHP. And not will be updated.

Wead Google Cloud Firestore REST Client

Integrate client PHP with REST Api from Google Cloud Firestore.

Requirements

Supported PHP version

Dependecies

Requires Guzzle Firebase / PHP-JWT

Current features

  • Get
  • Set
  • Remove

Installation

It's reommended to install with composer:

composer require wead/google-firestore-rest-client

Usage

Sample usage

<?php

require "vendor/autoload.php";

use \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" => "adriano_mail@hotmail.com",
    "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);

BuyMeACoffee

PayPal