Download the PHP package ldkafka/yii3-google-firestore without Composer

On this page you can find all versions of the php package ldkafka/yii3-google-firestore. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package yii3-google-firestore

yii3-google-firestore

tests

A Google Cloud Firestore client for PHP 8.4 over the REST API v1, with a thin Yii3 config layer. It needs no gRPC extension, no Google SDK and no Guzzle: only the PSR interfaces for HTTP (PSR-18 client, PSR-17 factories), cache (PSR-16) and logging (PSR-3).

Status: 0.1. The API may change before 1.0 (the CHANGELOG says how). Plans: ROADMAP.md.

Requirements

Installation

Then pick a PSR-18 client. Set its timeouts: PSR-18 has no timeout setting, so they are the client's, and the token exchange goes through the same client. The package bounds only the retries per call, the delay between them and the runs of a transaction.

Symfony HttpClient (with any PSR-17 implementation, here httpsoft/http-message):

Guzzle 7 (it is its own PSR-17 factory). It waits forever by default, so always pass timeouts:

Quick start (plain PHP)

ServiceAccountCredentials::fromEnvironment($http, $requests, $streams) reads the key path from GOOGLE_APPLICATION_CREDENTIALS, and the constructor also takes the decoded key as an array. Pass a PSR-16 cache as the last argument to share the access token between processes; the cache key is bound to the key's identity, so a rotated key never reuses a token. Tokens are refreshed 120 seconds before they expire. A named database: new FirestoreClient(..., $credentials, databaseId: 'bus-db').

Documents

Paths are relative to the database: 'messages/abc', or 'threads/t1/replies/r1' below a document. Ids may hold any character except /; they never go into a URL.

Queries

Operator Wire Operator Wire
== EQUAL array-contains ARRAY_CONTAINS
!= NOT_EQUAL array-contains-any ARRAY_CONTAINS_ANY
< <= LESS_THAN(_OR_EQUAL) in IN
> >= GREATER_THAN(_OR_EQUAL) not-in NOT_IN

Batches and transactions

A Transaction has get(), getAll(), runQuery($query) (reads in the transaction) and the four writes of a batch, which commit when the callable returns. When Firestore answers ABORTED (contention), the callable runs again with retryTransaction, up to transactionAttempts runs (default 5). Any other exception rolls the transaction back and is rethrown. So the callable:

Field transforms

Sentinels work in create(), set() and update(), at any depth, and their paths stay out of the update mask, so an update made only of transforms changes nothing else. $result->transformResults holds what the server set ('doneAt' => Timestamp, 'attempts' => 2); the array transforms give null. The server time has millisecond precision. increment() on a missing field starts from 0; arrayRemove() removes every copy and turns a missing field into an empty array.

Values

Firestore Read as Written from
nullValue null null
booleanValue bool bool
integerValue (int64) int int
doubleValue float float; NAN and ±INF too
timestampValue Value\Timestamp Timestamp, any DateTimeInterface
stringValue string string (valid UTF-8)
bytesValue Value\Bytes Bytes (raw binary)
referenceValue Value\Reference (relative path) Reference('messages/abc')
geoPointValue Value\GeoPoint GeoPoint
arrayValue list a list; [] is an empty array
mapValue array<string, mixed> an associative array; new stdClass() for an empty map

Concurrency: claiming a message

Two agents read the same new message; each claims it with the version it read. The first write changes the version, so the second is refused: exactly one wins.

When the outcome is unknown (a 5xx ApiException or a TransportException from the commit), the write may have happened. Re-read the document and check claimant. A blind retry of a claim that won would be refused, and the winner would think it lost; that is why commits are never retried on those errors.

Errors and retries

Exception When
FirestoreException base of everything thrown on purpose
ConfigurationException no credentials and no emulator; key missing, unreadable or invalid; no project id
AuthenticationException the token endpoint refused the key (httpStatus, oauthError)
TransportException no HTTP answer: the PSR-18 client threw
ApiException Firestore answered with an error (method, httpStatus, status)
NotFoundException NOT_FOUND: update or exists: true on a missing document
AlreadyExistsException ALREADY_EXISTS: create, or exists: false, on an existing document
FailedPreconditionException FAILED_PRECONDITION: an updateTime mismatch, or a query that needs an index
AbortedException ABORTED: contention

The status comes from the body's error.status, because HTTP 400 and 409 each stand for two statuses. Bad arguments (a bad path, an unknown operator) throw \InvalidArgumentException.

Call Retried on
batchGet, runQuery, runAggregationQuery, listCollectionIds, beginTransaction, rollback RESOURCE_EXHAUSTED (429), UNAVAILABLE (503, and a bare 502), INTERNAL (500), DEADLINE_EXCEEDED (504), network errors
commit outside a transaction RESOURCE_EXHAUSTED, ABORTED (both mean nothing was written)
commit of a transaction RESOURCE_EXHAUSTED (ABORTED re-runs the whole transaction)

RetryPolicy sets the limits: maxRetries 3 per call, backoff min(maxDelayMs, baseDelayMs × 2^(n−1)) with a jitter of 0.75 to 1 (base 200 ms, cap 5 s), and transactionAttempts 5. Each retry logs one PSR-3 warning with the method, the status, the attempt and the delay. Retry-After is not read.

The emulator

What the emulator does (checked on the image above, Standard edition, Native mode):

If port 8080 on the host is taken, run the PHP side in a container on the emulator's network: docker run --rm --network container:firestore-emulator -v "$PWD":/app -w /app -e FIRESTORE_EMULATOR_HOST=127.0.0.1:8080 php:8.4-cli-alpine php vendor/bin/phpunit --testsuite integration.

Yii3

With yiisoft/config the package registers config/params.php and config/di.php:

The application binds Psr\Http\Client\ClientInterface (with its timeouts), Psr\Http\Message\RequestFactoryInterface and Psr\Http\Message\StreamFactoryInterface; then take FirestoreClient from the container. With an emulator host there is no credentials object.

Set keyFile explicitly in any process that also uses another Google package that falls back on GOOGLE_APPLICATION_CREDENTIALS (ldkafka/yii3-google-cloud-logging does), or both will use the same key.

Security

Testing

License

BSD 3-Clause. See LICENSE.


All versions of yii3-google-firestore with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
ext-json Version *
ext-openssl Version *
psr/http-client Version ^1.0
psr/http-factory Version ^1.0
psr/http-message Version ^1.1 || ^2.0
psr/log Version ^1.1 || ^2.0 || ^3.0
psr/simple-cache Version ^1.0 || ^2.0 || ^3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package ldkafka/yii3-google-firestore contains the following files

Loading the files please wait ...