dev-master
9999999-dev https://github.com/ahsankhatri/firestore-phpFirestore PHP Client
MIT
The Requires
- php >=5.6.6
- ext-curl *
- ext-json *
The Development Requires
php google firebase firestore
Wallogit.com
2017 © Pedro Peláez
Firestore PHP Client
This package is totally based on Firestore REST API, (*2)
1) Visit Google Cloud Firestore API
2) Select your desired project.
3) Select Credentials from left menu and select API Key from Server key or Create your own credentials, (*3)
You can install the package via composer:, (*4)
composer require ahsankhatri/firestore-php
The bindings require the following extensions in order to work properly:, (*5)
If you use Composer, these dependencies should be handled automatically. If you install manually, you'll want to make sure that these extensions are available., (*6)
$firestoreClient = new FireStoreApiClient('project-id', 'AIzaxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', [
'database' => '(default)',
]);
$firestoreClient->addDocument($collection, [
'booleanTrue' => true,
'booleanFalse' => false,
'null' => null,
'string' => 'abc123',
'integer' => 123456,
'arrayRaw' => [
'string' => 'abc123',
],
'array' => new FireStoreArray([
'string' => 'abc123',
]),
'reference' => new FireStoreReference('/users/23'),
'object' => new FireStoreObject(['nested1' => new FireStoreObject(['nested2' => new FireStoreObject(['nested3' => 'test'])])]),
'timestamp' => new FireStoreTimestamp,
'geopoint' => new FireStoreGeoPoint(1,1),
]);
NOTE: Pass third argument if you want your custom document id to set else auto-id will generate it for you., (*7)
Or, (*8)
$document = new FireStoreDocument;
$document->setObject('sdf', new FireStoreObject(['nested1' => new FireStoreObject(['nested2' => new FireStoreObject(['nested3' => 'test'])])]));
$document->setBoolean('booleanTrue', true);
$document->setBoolean('booleanFalse', false);
$document->setNull('null', null);
$document->setString('string', 'abc123');
$document->setInteger('integer', 123456);
$document->setArray('arrayRaw', ['string'=>'abc123']);
$document->setArray('arrayObject', new FireStoreArray(['string' => 'abc123']));
$document->setTimestamp('timestamp', new FireStoreTimestamp);
$document->setGeoPoint('geopoint', new FireStoreGeoPoint(1.11,1.11));
$firestoreClient->addDocument($collection, $document, 'customDocumentId');
And.., (*9)
$document->fillValues([
'string' => 'abc123',
'boolean' => true,
]);
$firestoreClient->updateDocument($collection, $documentId, [
'newFieldToAdd' => new FireStoreTimestamp(new DateTime('2018-04-20 15:00:00')),
'existingFieldToRemove' => new FireStoreDeleteAttribute
], true);
NOTE: Passing 3rd argument as a boolean true will indicate that document must exist and vice-versa., (*10)
$firestoreClient->setDocument($collection, $documentId, [
'newFieldToAdd' => new FireStoreTimestamp(new DateTime('2018-04-20 15:00:00')),
'existingFieldToRemove' => new FireStoreDeleteAttribute
], [
'exists' => true, // Indicate document must exist
]);
$collection = 'collection/document/innerCollection'; $firestoreClient->deleteDocument($collection, $documentId);
bash
composer test, (*11)
Please see CHANGELOG for more information what has changed recently., (*12)
Please see CONTRIBUTING for details., (*13)
If you discover any security related issues, please email ahsankhatri1992@gmail.com instead of using the issue tracker., (*14)
The MIT License (MIT). Please see License File for more information., (*15)
Firestore PHP Client
MIT
php google firebase firestore