{"id":37008858,"url":"https://github.com/ahsankhatri/firestore-php","last_synced_at":"2026-01-14T00:50:35.140Z","repository":{"id":52599150,"uuid":"130093614","full_name":"ahsankhatri/firestore-php","owner":"ahsankhatri","description":"Firestore PHP Client (without gRPC extension)","archived":true,"fork":false,"pushed_at":"2022-10-18T12:37:00.000Z","size":43,"stargazers_count":63,"open_issues_count":20,"forks_count":61,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-12-25T23:57:21.294Z","etag":null,"topics":["composer","firebase","firestore","google","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ahsankhatri.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-04-18T16:44:30.000Z","updated_at":"2025-08-27T12:16:28.000Z","dependencies_parsed_at":"2022-09-10T15:01:15.118Z","dependency_job_id":null,"html_url":"https://github.com/ahsankhatri/firestore-php","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/ahsankhatri/firestore-php","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahsankhatri%2Ffirestore-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahsankhatri%2Ffirestore-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahsankhatri%2Ffirestore-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahsankhatri%2Ffirestore-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ahsankhatri","download_url":"https://codeload.github.com/ahsankhatri/firestore-php/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahsankhatri%2Ffirestore-php/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28407207,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T00:40:43.272Z","status":"ssl_error","status_checked_at":"2026-01-14T00:40:42.636Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["composer","firebase","firestore","google","php"],"created_at":"2026-01-14T00:50:34.472Z","updated_at":"2026-01-14T00:50:35.132Z","avatar_url":"https://github.com/ahsankhatri.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Firestore Client for PHP\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/ahsankhatri/firestore-php.svg?style=flat-square)](https://packagist.org/packages/ahsankhatri/firestore-php)\n[![Total Downloads](https://img.shields.io/packagist/dt/ahsankhatri/firestore-php.svg?style=flat-square)](https://packagist.org/packages/ahsankhatri/firestore-php)\n[![License](https://poser.pugx.org/ahsankhatri/firestore-php/license?format=flat-square)](https://packagist.org/packages/ahsankhatri/firestore-php)\n\nThis package is totally based on [Firestore REST API](https://firebase.google.com/docs/firestore/use-rest-api)\n\n## Authentication / Generate API Key\n\n1) Visit [Google Cloud Firestore API](https://console.cloud.google.com/projectselector/apis/api/firestore.googleapis.com/overview)  \n2) Select your desired project.  \n3) Select `Credentials` from left menu and select `API Key` from Server key or `Create your own credentials`  \n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require ahsankhatri/firestore-php\n```\n\nor install it by adding it to `composer.json` then run `composer update`\n\n```javascript\n\"require\": {\n    \"ahsankhatri/firestore-php\": \"^2.0\",\n}\n```\n\n## Dependencies\n\nThe bindings require the following extensions in order to work properly:\n\n- [`curl`](https://secure.php.net/manual/en/book.curl.php)\n- [`json`](https://secure.php.net/manual/en/book.json.php)\n- [`guzzlehttp/guzzle`](https://packagist.org/packages/guzzlehttp/guzzle)\n\nIf you use Composer, these dependencies should be handled automatically. If you install manually, you'll want to make sure that these extensions are available.\n\n## Usage\n\n#### Initialization\n\n```php\n$firestoreClient = new FirestoreClient('project-id', 'AIzaxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', [\n    'database' =\u003e '(default)',\n]);\n```\n\n#### Adding a document\n\n```php\n$firestoreClient-\u003eaddDocument($collection, [\n    'booleanTrue' =\u003e true,\n    'booleanFalse' =\u003e false,\n    'null' =\u003e null,\n    'string' =\u003e 'abc123',\n    'integer' =\u003e 123456,\n    'arrayRaw' =\u003e [\n        'string' =\u003e 'abc123',\n    ],\n    'bytes' =\u003e new FirestoreBytes('bytesdata'),\n    'array' =\u003e new FirestoreArray([\n        'string' =\u003e 'abc123',\n    ]),\n    'reference' =\u003e new FirestoreReference('/users/23'),\n    'object' =\u003e new FirestoreObject(['nested1' =\u003e new FirestoreObject(['nested2' =\u003e new FirestoreObject(['nested3' =\u003e 'test'])])]),\n    'timestamp' =\u003e new FirestoreTimestamp,\n    'geopoint' =\u003e new FirestoreGeoPoint(1,1),\n]);\n```\n\n**NOTE:** Pass third argument if you want your custom **document id** to set else auto-id will generate it for you.\n\nOr\n\n```php\n$document = new FirestoreDocument;\n$document-\u003esetObject('sdf', new FirestoreObject(['nested1' =\u003e new FirestoreObject(['nested2' =\u003e new FirestoreObject(['nested3' =\u003e 'test'])])]));\n$document-\u003esetBoolean('booleanTrue', true);\n$document-\u003esetBoolean('booleanFalse', false);\n$document-\u003esetNull('null', null);\n$document-\u003esetString('string', 'abc123');\n$document-\u003esetInteger('integer', 123456);\n$document-\u003esetArray('arrayRaw', ['string'=\u003e'abc123']);\n$document-\u003esetBytes('bytes', new FirestoreBytes('bytesdata'));\n$document-\u003esetArray('arrayObject', new FirestoreArray(['string' =\u003e 'abc123']));\n$document-\u003esetTimestamp('timestamp', new FirestoreTimestamp);\n$document-\u003esetGeoPoint('geopoint', new FirestoreGeoPoint(1.11,1.11));\n\n$firestoreClient-\u003eaddDocument($collection, $document, 'customDocumentId');\n```\n\nAnd..\n\n```php\n$document-\u003efillValues([\n    'string' =\u003e 'abc123',\n    'boolean' =\u003e true,\n]);\n```\n\n#### Inserting/Updating a document\n\n- Update (Merge) or Insert document\n\nFollowing will merge document (if exist) else insert the data.\n\n```php\n$firestoreClient-\u003eupdateDocument($documentRoot, [\n    'newFieldToAdd' =\u003e new FirestoreTimestamp(new DateTime('2018-04-20 15:00:00')),\n    'existingFieldToRemove' =\u003e new FirestoreDeleteAttribute\n]);\n```\n\n**NOTE:** Passing 3rd argument as a boolean _true_ will force check that document must exist and vice-versa in order to perform update operation.\n\nFor example: If you want to update document only if exist else `MrShan0\\PHPFirestore\\Exceptions\\Client\\NotFound` (Exception) will be thrown.\n\n```php\n$firestoreClient-\u003eupdateDocument($documentPath, [\n    'newFieldToAdd' =\u003e new FirestoreTimestamp(new DateTime('2018-04-20 15:00:00')),\n    'existingFieldToRemove' =\u003e new FirestoreDeleteAttribute\n], true);\n```\n\n- Overwirte or Insert document\n\n```php\n$firestoreClient-\u003esetDocument($collection, $documentId, [\n    'newFieldToAdd' =\u003e new FirestoreTimestamp(new DateTime('2018-04-20 15:00:00')),\n    'existingFieldToRemove' =\u003e new FirestoreDeleteAttribute\n], [\n    'exists' =\u003e true, // Indicate document must exist\n]);\n```\n\n#### Deleting a document\n\n```php\n$collection = 'collection/document/innerCollection';\n$firestoreClient-\u003edeleteDocument($collection, $documentId);\n```\n\n#### List documents with pagination (or custom parameters)\n\n```php\n$collections = $firestoreClient-\u003elistDocuments('users', [\n    'pageSize' =\u003e 1,\n    'pageToken' =\u003e 'nextpagetoken'\n]);\n```\n\n**Note:** You can pass custom parameters as supported by [firestore list document](https://firebase.google.com/docs/firestore/reference/rest/v1/projects.databases.documents/list#query-parameters)\n\n#### Get field from document\n\n```php\n$document-\u003eget('bytes')-\u003eparseValue(); // will return bytes decoded value.\n\n// Catch field that doesn't exist in document\ntry {\n    $document-\u003eget('allowed_notification');\n} catch (\\MrShan0\\PHPFirestore\\Exceptions\\Client\\FieldNotFound $e) {\n    // Set default value\n}\n```\n\n### Firebase Authentication\n\n#### Sign in with Email and Password.\n\n```php\n$firestoreClient\n    -\u003eauthenticator()\n    -\u003esignInEmailPassword('testuser@example.com', 'abc123');\n```\n\n#### Sign in Anonymously.\n\n```php\n$firestoreClient\n    -\u003eauthenticator()\n    -\u003esignInAnonymously();\n```\n\n### Retrieve Auth Token\n\n```php\n$authToken = $firestoreClient-\u003eauthenticator()-\u003egetAuthToken();\n```\n\n### TODO\n- [x] Added delete attribute support.\n- [x] Add Support for Object, Boolean, Null, String, Integer, Array, Timestamp, GeoPoint, Bytes\n- [x] Add Exception Handling.\n- [x] List all documents.\n- [ ] List all collections.\n- [x] Filters and pagination support.\n- [ ] Structured Query support.\n- [ ] Transaction support.\n- [ ] Indexes support.\n- [ ] Entire collection delete support.\n\n### Testing\n\n``` bash\ncomposer test\n```\n\n### Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n### Security\n\nIf you discover any security related issues, please email ahsankhatri1992@gmail.com instead of using the issue tracker.\n\n## Credits\n\n- [Ahsaan Muhammad Yousuf](https://ahsaan.me)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahsankhatri%2Ffirestore-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahsankhatri%2Ffirestore-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahsankhatri%2Ffirestore-php/lists"}