{"id":15277484,"url":"https://github.com/tattersoftware/codeigniter4-firebase","last_synced_at":"2025-06-29T18:32:26.612Z","repository":{"id":36501171,"uuid":"227824752","full_name":"tattersoftware/codeigniter4-firebase","owner":"tattersoftware","description":"Firebase integration for CodeIgniter 4","archived":false,"fork":false,"pushed_at":"2024-01-17T22:59:24.000Z","size":237,"stargazers_count":29,"open_issues_count":2,"forks_count":8,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2025-05-14T09:09:35.564Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/tattersoftware.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-13T11:29:08.000Z","updated_at":"2025-03-02T22:05:18.000Z","dependencies_parsed_at":"2024-11-14T14:36:26.620Z","dependency_job_id":"ff2e7758-1ef7-4b2f-bccd-065ccdb1fe39","html_url":"https://github.com/tattersoftware/codeigniter4-firebase","commit_stats":null,"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"purl":"pkg:github/tattersoftware/codeigniter4-firebase","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tattersoftware%2Fcodeigniter4-firebase","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tattersoftware%2Fcodeigniter4-firebase/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tattersoftware%2Fcodeigniter4-firebase/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tattersoftware%2Fcodeigniter4-firebase/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tattersoftware","download_url":"https://codeload.github.com/tattersoftware/codeigniter4-firebase/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tattersoftware%2Fcodeigniter4-firebase/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261249241,"owners_count":23130493,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-09-30T11:07:02.870Z","updated_at":"2025-06-29T18:32:26.572Z","avatar_url":"https://github.com/tattersoftware.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Tatter\\Firebase\nFirebase integration for CodeIgniter 4\n\n[![](https://github.com/tattersoftware/codeigniter4-firebase/workflows/PHPUnit/badge.svg)](https://github.com/tattersoftware/codeigniter4-firebase/actions/workflows/phpunit.yml)\n[![](https://github.com/tattersoftware/codeigniter4-firebase/workflows/PHPStan/badge.svg)](https://github.com/tattersoftware/codeigniter4-firebase/actions/workflows/phpstan.yml)\n[![](https://github.com/tattersoftware/codeigniter4-firebase/workflows/Deptrac/badge.svg)](https://github.com/tattersoftware/codeigniter4-firebase/actions/workflows/deptrac.yml)\n[![Coverage Status](https://coveralls.io/repos/github/tattersoftware/codeigniter4-firebase/badge.svg?branch=develop)](https://coveralls.io/github/tattersoftware/codeigniter4-firebase?branch=develop)\n\n## Quick Start\n\n1. Install with Composer: `\u003e composer require tatter/firebase`\n2. Edit **.env** and add the path to your Firebase credentials: `GOOGLE_APPLICATION_CREDENTIALS = ../credentials/keyfile.json`\n3. Access components via the service: `$authentication = service('firebase')-\u003eauth;`\n4. Use the Firestore `Collection` and `Entity` to model your data: `$widget = collection(WidgetCollection::class)-\u003eget($widgetId);`\n\n## Description\n\nThis is a CodeIgniter 4 integration of `Kreait\\Firebase`, the \"Unofficial Firebase Admin\nSDK for PHP\":\n\n* [Documentation](https://firebase-php.readthedocs.io/)\n* [GitHub repository](https://github.com/kreait/firebase-php)\n\nIt provides a convenience service and custom Firestore classes to use your Firebase project\nwithin CodeIgniter 4. Please pay attention to the requirements of the underlying services:\n\n* [kreait\\firebase-php](https://firebase-php.readthedocs.io/en/stable/overview.html#requirements)\n* [google\\cloud-firestore](https://firebase-php.readthedocs.io/en/stable/cloud-firestore.html)\n\nNotably, you must have the [gRPC PHP extension](https://github.com/grpc/grpc/tree/master/src/php)\nand the credentials file to a [Service Account](https://firebase.google.com/docs/admin/setup#add_firebase_to_your_app)\nwith the *Project -\u003e Editor* or *Project -\u003e Owner* role.\n\n## Installation\n\nInstall easily via Composer to take advantage of CodeIgniter 4's autoloading capabilities\nand always be up-to-date:\n```bash\ncomposer require tatter/firebase\n```\n\nOr, install manually by downloading the source files and adding the directory to\n**app/Config/Autoload.php**.\n\n\u003e Note: As of February 5, 2022 this library fully supports PHP 8.1, however Google's Protobuf\n\u003e has an incompatibility (hopefully fixed soon: https://github.com/protocolbuffers/protobuf/issues/9293).\n\n## Credentials\n\nYou must provide a key file with your application's service account credentials. The standard\nway to do this is to add **keyfile.json** to your project and edit **.env** to its path\n(relative to **public/**):\n\n\tGOOGLE_APPLICATION_CREDENTIALS = ../keyfile.json\n\n\u003e *WARNING* Make sure you exclude the key file from any repository updates!\n\nTo generate a key file from your Firebase project:\n\n1. Firebase Project Home\n2. Project Settings (gear)\n3. Service Accounts\n4. Firebase Admin SDK\n5. Generate new private key\n\nFor more info on acquiring credentials see the\n[Firestore Quick Start Guide](https://firebase.google.com/docs/firestore/quickstart)\n\nFor more information on credential specification see the\n[SDK setup docs](https://firebase-php.readthedocs.io/en/stable/setup.html)\n\n## Usage\n\nLoad the Firebase service:\n```php\n$firebase = service('firebase');\n```\n\nThe service will handle creating and caching each component as you need them. Access\ncomponents by their name:\n```php\n$storage = $firebase-\u003estorage;\n$bucket  = $storage-\u003egetBucket('my-bucket');\n```\n\nYou can also use the service to access all the functions of `Kreait\\Firebase\\Factory`\ndirectly, for example if you wanted a separate component instance:\n```php\n$shareClient = $firebase-\u003eauth;\n$altClient   = $firebase-\u003ecreateAuth();\n```\n\nSee the [SDK docs](https://firebase-php.readthedocs.io/en/stable/index.html) for a list of\nsupported components. Available at the time of this writing:\n* Auth\n* Database\n* Firestore\n* Messaging\n* RemoteConfig\n* Storage\n* *Caller*\n\n## Caller\n\nWhile not yet officially supported by the Firebase SDK, this library includes a component\nfor Firebase callable functions. A simple example shows all its features:\n```php\n// Get the component\n$caller = service('firebase')-\u003ecaller;\n\n// Set the UID of the user making the call\n$caller-\u003esetUid($user-\u003euid);\n\n// Make the call\n$data     = ['customerId' =\u003e 7, 'charge' =\u003e 3.50];\n$response = $caller-\u003ecall('https://us-central1-myproject.cloudfunctions.net/addCharge', $data);\n\nif ($response === null) {\n    echo implode(' ', $caller-\u003egetErrors());\n}\nelse {\n    print_r($response);\n}\n```\n\n## Firestore\n\nThis library provides access to the Firestore database directly via `FirestoreClient`.\nUse the helper function for direct access to a shared instance of the client:\n```php\nhelper('firestore');\n\n$document = firestore()-\u003ecollection('users')-\u003edocument('lovelace');\n$document-\u003eset([\n    'first' =\u003e 'Ada',\n    'last' =\u003e 'Lovelace',\n    'born' =\u003e 1815\n]);\n\nprintf('Added data to the \"lovelace\" document in the users collection.');\n```\n\nSince the SDK and Google classes already represent a full database implementation there is\nno need for a framework database layer. You can interact directly with the Firestore classes\naccording to [Google's User Guide](https://googleapis.github.io/google-cloud-php/#/docs/cloud-firestore/latest).\n\n### Collection\n\nThe `Collection` class is inspired by the framework's `Model` and handles most of the pre-\nand post-processing that developers are used to. All you need to supply is the name of the\ncollection and the Entity type to use:\n```php\n\u003c?php\n\nnamespace App\\Collections;\n\nuse App\\Entities\\Widget;\nuse Tatter\\Firebase\\Firestore\\Collection;\n\nfinal class WidgetCollection extends Collection\n{\n    public const NAME   = 'widgets';\n    public const ENTITY = Widget::class;\n}\n```\n\n#### Instantiating\n\nYou can create your collection instances just like you would a `Model`. The Firestore\nHelper also contains a helper function to create and manage shared instances, just like\nthe framework's `model()` helper:\n```\n$widgets = new WidgetCollection();\n// OR\nhelper('firestore');\n$widgets = collection(WidgetCollection::class);\n```\n\nBy default a new Collection will create a `CollectionReference` to the top-level collection\nmatching it's `NAME` constant. Alternatively you may pass in a `CollectionReference` directly\nfor it to use. Use the second parameter to the `collection()` function to make instant\nsubcollections of any `Firestore\\Entity` or `DocumentReference`:\n```php\n$user = collection(UserCollection::class)-\u003eget($userId);\n\n$userWidgets = collection(WidgetCollection::class, $user);\nforeach ($userWidgets-\u003elist() as $widget) {\n    echo \"{$user-\u003ename}: {$widget-\u003ename}\";\n}\n```\n\n#### Methods\n\n`Collection` supplies the following CRUD methods:\n* `add(array|Entity $entity): Entity`\n* `update(Entity $entity, array $data): Entity`\n* `remove(Entity|string $entity): void`\n* `get(DocumentReference|string $reference): ?Entity`\n* `list($source = null): Traversable` *Read more below*\n\nAnd support methods:\n* `fromSnapshot(DocumentSnapshot $snapshot): Entity`\n* `fake(array\u003cstring, mixed\u003e array $overrides = []): Entity`\n* `make(array\u003cstring, mixed\u003e array $overrides = []): Entity` *Same as `fake()` but inserts the document\n\nAdditionally, these methods access metadata about the underlying Firestore (sub)collection:\n* `collection(): CollectionReference`\n* `parent(): ?DocumentReference`\n* `id(): string`\n* `name(): string`\n* `path(): string`\n\nAnd finally some familiar `Model`-inspired validation methods:\n* `setValidation(ValidationInterface $validation): self`\n* `skipValidation(bool $skip = true)`\n* `validate(array $data, bool $cleanValidationRules = true): bool`\n* `getValidationRules(array $options = []): array`\n* `getErrors(): array`\n\n#### Retrieving Documents\n\nYou may use the Firestore client directly to return snapshots and convert them to your Entity\nof choice with `fromSnapshot()`, but `Collection` also allows specifying an overriding state\nfor `list()`. This can be an explicit `CollectionReference` or (more helpful) an instance of\n`Google\\Cloud\\Firestore\\Query`, which opens up the possibility of using filters, sorts, and\nlimits as well as traversing collection groups:\n```php\n// Using filters\n$widgets = new WidgetCollection();\n$query   = $widgets-\u003ecollection()-\u003ewhere('color', '=', 'purple'); // returns Query\nforeach ($widgets-\u003elist($query) as $widget) {\n    echo $widget-\u003eweight;\n}\n\n// Grouped collections (traverses all collections and subcollections named \"widgets\")\n$group = firestore()-\u003ecollectionGroup('widgets');\nforeach ($widgets-\u003elist($group) as $widget) {\n    echo $widget-\u003ecolor;\n}\n```\n\nTo make this even easier, `Collection` will \"pass through\" the following method calls to\nthe underlying collection:\n* `endAt()`, `endBefore()`, `limit()`, `limitToLast()`, `offset()`, `orderBy()`, `select()`, `startAfter()`, `startAt()`, `where()`\n\nThis allows for even easier method chaining:\n```php\n$result = $widgets-\u003elist($widgets-\u003eorderBy('color')-\u003elimit(5));\n```\n\n\u003e Note that `list()` always returns a `Traversable` so documents are only retrieved and converted ot Entities as they are actually needed\n\n### Entity\n\nThis library also comes with its own Firestore `Entity` that handles Google's timestamp\nconversions and these methods to access metadata about the underlying Firestore document:\n* `document(?DocumentReference $document = null): ?DocumentReference` *Gets or sets the document*\n* `id(): string`\n* `super(): ?DocumentReference` *Gets an Entity's parent Entity, if it is from a subcollection*\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftattersoftware%2Fcodeigniter4-firebase","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftattersoftware%2Fcodeigniter4-firebase","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftattersoftware%2Fcodeigniter4-firebase/lists"}