From 000d16daa8e1a783e12f830539092f5fbfd68445 Mon Sep 17 00:00:00 2001 From: Georges Date: Sun, 7 Jan 2024 13:37:59 +0100 Subject: [PATCH] Moved Dynamodb and Firestore to their own extensions --- .github/workflows/testsv2.yml | 13 +- .travis.yml | 9 +- CHANGELOG.md | 2 +- EXTENSIONS.MD | 1 - README.md | 28 +- bin/ci/scripts/install_dependencies.sh | 5 +- bin/ci/scripts/install_dependencies_lite.sh | 5 - bin/ci/scripts/setup_gcp.sh | 7 - composer.json | 17 +- docs/DRIVERS.md | 7 + docs/EVENTS.md | 10 +- lib/Phpfastcache/Drivers/Dynamodb/Config.php | 230 ------------- lib/Phpfastcache/Drivers/Dynamodb/Driver.php | 306 ------------------ lib/Phpfastcache/Drivers/Dynamodb/Event.php | 8 - lib/Phpfastcache/Drivers/Dynamodb/Item.php | 30 -- lib/Phpfastcache/Drivers/Firestore/Config.php | 211 ------------ lib/Phpfastcache/Drivers/Firestore/Driver.php | 247 -------------- lib/Phpfastcache/Drivers/Firestore/Event.php | 8 - lib/Phpfastcache/Drivers/Firestore/Item.php | 30 -- .../{Mongodb.test.php => Casssandra.test.php} | 10 +- tests/cases/Dynamodb.test.php | 48 --- tests/cases/Firestore.test.php | 43 --- tests/cases/GetAllItems.test.php | 5 +- 23 files changed, 37 insertions(+), 1243 deletions(-) delete mode 100755 bin/ci/scripts/install_dependencies_lite.sh delete mode 100755 bin/ci/scripts/setup_gcp.sh delete mode 100644 lib/Phpfastcache/Drivers/Dynamodb/Config.php delete mode 100644 lib/Phpfastcache/Drivers/Dynamodb/Driver.php delete mode 100644 lib/Phpfastcache/Drivers/Dynamodb/Event.php delete mode 100644 lib/Phpfastcache/Drivers/Dynamodb/Item.php delete mode 100644 lib/Phpfastcache/Drivers/Firestore/Config.php delete mode 100644 lib/Phpfastcache/Drivers/Firestore/Driver.php delete mode 100644 lib/Phpfastcache/Drivers/Firestore/Event.php delete mode 100644 lib/Phpfastcache/Drivers/Firestore/Item.php rename tests/cases/{Mongodb.test.php => Casssandra.test.php} (65%) delete mode 100644 tests/cases/Dynamodb.test.php delete mode 100644 tests/cases/Firestore.test.php diff --git a/.github/workflows/testsv2.yml b/.github/workflows/testsv2.yml index 3fa925d1..98679d44 100644 --- a/.github/workflows/testsv2.yml +++ b/.github/workflows/testsv2.yml @@ -11,7 +11,7 @@ jobs: php-versions: ['8.0', '8.1', '8.2', '8.3'] name: PHP ${{ matrix.php-versions }} quality/tests on ${{ matrix.operating-system }} env: - extensions: mbstring, intl, pdo_sqlite, json, redis, grpc, couchbase-3.2.2 + extensions: mbstring, intl, pdo_sqlite, json, redis, couchbase-3.2.2 key: cache-v1 steps: - name: Checkout @@ -63,12 +63,6 @@ jobs: restore-keys: | ${{ runner.os }}-php- - - name: Setup GCP environment - run: "./bin/ci/scripts/setup_gcp.sh || echo \"GCP setup failed (maybe due to fork limitation)\"" - env: - BASE64_GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.BASE64_GOOGLE_APPLICATION_CREDENTIALS }} - GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }} - - name: Install dependencies run: ./bin/ci/scripts/install_dependencies.sh @@ -76,9 +70,4 @@ jobs: run: composer run-script quality - name: Run tests - env: - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }} - GOOGLE_CLOUD_PROJECT: ${{ secrets.GOOGLE_CLOUD_PROJECT }} run: composer run-script tests diff --git a/.travis.yml b/.travis.yml index bdfb141a..60551c76 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,10 +30,6 @@ jobs: before_install: - sudo apt remove cmake - pip install cmake --upgrade -# Memcached is not yet available for PHP8 (hasn't been updated since 2019): https://pecl.php.net/package/memcached -# Memcache however seems to be compatible with PHP 7 and 8: https://pecl.php.net/package/memcache -# - # - ./bin/ci/scripts/install_arangodb.sh; - phpenv config-add bin/ci/php_common.ini - phpenv config-rm xdebug.ini - composer install @@ -42,14 +38,11 @@ before_install: - "./bin/ci/scripts/install_couchbase.sh || echo \"Couchbase install failed\"" - "./bin/ci/scripts/setup_gcp.sh || echo \"GCP setup failed\"" - "pecl channel-update pecl.php.net || echo \"PECL Channel update failed\"" - # - yes | pecl install -f grpc-stable | grep -v --line-buffered "/tmp/pear/install/grpc"; # This pecl install is partially muted due to too much output written - - "yes | ./vendor/bin/ci-pecl-install grpc | grep -v --line-buffered \"/tmp/pear/install/grpc\" || echo \"PECL GRPC install failed\"" - # - "yes | ./vendor/bin/ci-pecl-install apcu || echo \"PECL Apcu install failed\"" # Apcu seems to be provided In Bionic: https://docs.travis-ci.com/user/reference/bionic/#php-support - "yes | ./vendor/bin/ci-pecl-install memcache || echo \"PECL Memcache install failed\"" - "yes | ./vendor/bin/ci-pecl-install memcached || echo \"PECL Memcached install failed\"" - "yes | ./vendor/bin/ci-pecl-install couchbase-3.2.2 couchbase || echo \"PECL Couchbase install failed\"" # @todo UPGRADE TO COUCHBASE 4.x.x once we upgraded from Bionic to Focal install: - - "[[ $TRAVIS_PHP_VERSION != \"nightly\" ]] && ./bin/ci/scripts/install_dependencies.sh || ./bin/ci/scripts/install_dependencies_lite.sh" + - ./bin/ci/scripts/install_dependencies.sh script: - composer run-script quality diff --git a/CHANGELOG.md b/CHANGELOG.md index 99c9c629..bfe1d800 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ - __Extensions__ (💡 New in 9.2) - Created an extension mechanism to allow some drivers to be loaded independently, see [README.md](README.md) - Created extension for `Couchbasev4` support to its own [sub-repository](https://github.com/PHPSocialNetwork/couchbasev4-extension). - - **IMPORTANT**: *AS OF v9.2* the following drivers has been **MOVED** to their own sub-repositories as a standalone extension: `Arangodb`, `Couchdb`, `Cassandra`, `Dynamodb`, `Firestore`, `Mongodb`, `Solr`. However `Couchbasev3` will stay in the core for compatibility reasons but will be deprecated. + - **IMPORTANT**: *AS OF v9.2* the following drivers has been **MOVED** to their own sub-repositories as a standalone extension: `Arangodb`, `Couchdb`, `Dynamodb`, `Firestore`, `Mongodb`, `Solr`. However `Couchbasev3` will stay in the core for compatibility reasons but will be deprecated. - **IMPORTANT**: *AS OF v10* extensions will have their namespaces permanently moved from `Phpfastcache\Drivers\EXT_NAME\{Config, Driver, Event, Item}` to `Phpfastcache\Extensions\Drivers\EXT_NAME\{Config, Driver, Event, Item}`. For now an alias is ensuring compatibility. - __Events__ - EventManager is now scoped to its own poll if retrieved through `ExtendedCacheItemPoolTrait::->getEventManager()`. Global EventManager `EventManager::getInstance()` remains unchanged, see [EVENTS.md](./docs/EVENTS.md). diff --git a/EXTENSIONS.MD b/EXTENSIONS.MD index b7450c52..71d56946 100644 --- a/EXTENSIONS.MD +++ b/EXTENSIONS.MD @@ -7,7 +7,6 @@ The 9.2 make the beginning of a new external extensions: - `Arangodb` - `Couchbasev4` - `Couchdb` -- `Cassandra` - `Dynamodb` - `Firestore` - `Mongodb` diff --git a/README.md b/README.md index 67bf2e99..e5122083 100644 --- a/README.md +++ b/README.md @@ -15,26 +15,26 @@ The simplicity of abstraction: One class for many backend cache. You don't need ### Supported drivers at this day * :bulb: Feel free to propose a driver by making a new **[Pull Request](https://github.com/PHPSocialNetwork/phpfastcache/compare)**, they are welcome ! -| Regular drivers | High performances drivers | Development drivers _(Core)_ | Cluster-Aggregated drivers _(Core)_ | -|---------------------------------------------------------------------------------|------------------------------------------------------------------------------------------|--------------------------------------------|---------------------------------------| -| `Apcu` _(Core)_
_(APC support removed)_ | `Arangodb` _([Extension](https://github.com/PHPSocialNetwork/arangodb-extension))_ | `Devnull` | `FullReplicationCluster` | -| `Dynamodb` (AWS) | `Cassandra` | `Devrandom` | `SemiReplicationCluster` | -| `Files` _(Core)_ | `CouchBasev3` _(Core)_
_(Will be deprecated as of v10)_ | `Memory`
(Previously named `Memstatic`) | `MasterSlaveReplicationCluster` | -| `Firestore` (GCP) | `CouchBasev4` _([Extension](https://github.com/PHPSocialNetwork/couchbasev4-extension))_ | | `RandomReplicationCluster` | -| `Leveldb` _(Core)_ | `Couchdb` _([Extension](https://github.com/PHPSocialNetwork/couchdb-extension))_ | | | -| `Memcache(d)` _(Core)_ | `Mongodb` _([Extension](https://github.com/PHPSocialNetwork/mongodb-extension))_ | | | -| `Solr` _([Extension](https://github.com/PHPSocialNetwork/solr-extension))_ | `Predis` _(Core)_ | | | -| `Sqlite` _(Core)_ | `Redis`/`RedisCluster` _(Core)_ | | | -| `Wincache` _(Core)_
(**Deprecated** as of v9.2, will be removed as of v10) | `Ssdb` _(Core)_ | | | -| `Zend Disk Cache` _(Core)_ | `Zend Memory Cache` _(Core)_ | | | -| | | | | +| Regular drivers | High performances drivers | Development drivers _(Core)_ | Cluster-Aggregated drivers _(Core)_ | +|--------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------|--------------------------------------------|---------------------------------------| +| `Apcu` _(Core)_
_(APC support removed)_ | `Arangodb` _([Extension](https://github.com/PHPSocialNetwork/arangodb-extension))_ | `Devnull` | `FullReplicationCluster` | +| `Dynamodb` _([Extension](https://github.com/PHPSocialNetwork/dynamodb-extension))_ | `Cassandra`
_(PHP extension is no more maintained by Datastax, might be deprecated in v10)_ | `Devrandom` | `SemiReplicationCluster` | +| `Files` _(Core)_ | `CouchBasev3` _(Core)_
_(Will be deprecated as of v10)_ | `Memory`
(Previously named `Memstatic`) | `MasterSlaveReplicationCluster` | +| `Firestore` _([Extension](https://github.com/PHPSocialNetwork/firestore-extension))_ | `CouchBasev4` _([Extension](https://github.com/PHPSocialNetwork/couchbasev4-extension))_ | | `RandomReplicationCluster` | +| `Leveldb` _(Core)_ | `Couchdb` _([Extension](https://github.com/PHPSocialNetwork/couchdb-extension))_ | | | +| `Memcache(d)` _(Core)_ | `Mongodb` _([Extension](https://github.com/PHPSocialNetwork/mongodb-extension))_ | | | +| `Solr` _([Extension](https://github.com/PHPSocialNetwork/solr-extension))_ | `Predis` _(Core)_ | | | +| `Sqlite` _(Core)_ | `Redis`/`RedisCluster` _(Core)_ | | | +| `Wincache` _(Core)_
(**Deprecated** as of v9.2, will be removed as of v10) | `Ssdb` _(Core)_ | | | +| `Zend Disk Cache` _(Core)_ | `Zend Memory Cache` _(Core)_ | | | +| | | | | \* Driver descriptions available in [DOCS/DRIVERS.md](./docs/DRIVERS.md) :new: As of v9.2 a new Couchbase extension has been released: [Couchbasev4](https://github.com/PHPSocialNetwork/couchbasev4-extension) This new extension **is the beginning of a new era** for Phpfastcache along with some others:\ -Many drivers has been moved from the core to their own sub-repository as a standalone extension: `Arangodb`, `Couchdb`, `Cassandra`, `Dynamodb`, `Firestore`, `Mongodb`, `Solr`.\ +Many drivers has been moved from the core to their own sub-repository as a standalone extension: `Arangodb`, `Couchdb`, `Dynamodb`, `Firestore`, `Mongodb`, `Solr`.\ They can be easily added through composer, ex: `composer install phpfastcache/couchbasev4-extension` However `Couchbasev3` **will stay in the core** for compatibility reasons but will be deprecated. diff --git a/bin/ci/scripts/install_dependencies.sh b/bin/ci/scripts/install_dependencies.sh index 4839e4c9..4856d73e 100755 --- a/bin/ci/scripts/install_dependencies.sh +++ b/bin/ci/scripts/install_dependencies.sh @@ -3,7 +3,4 @@ composer self-update composer validate composer install -##### -# Travis CI have php mongodb extension locked to 1.10, so we must set the mongodb/mongodb minimum version to 1.9 :( -##### -composer require -W phpfastcache/phpssdb:~1.2 predis/predis:~1.1 mongodb/mongodb:~1.9 aws/aws-sdk-php:~3.2 google/cloud-firestore:~1.39 +composer require -W phpfastcache/phpssdb:~1.2 predis/predis:~1.1 diff --git a/bin/ci/scripts/install_dependencies_lite.sh b/bin/ci/scripts/install_dependencies_lite.sh deleted file mode 100755 index 445b4496..00000000 --- a/bin/ci/scripts/install_dependencies_lite.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash - -composer self-update -composer validate -composer install diff --git a/bin/ci/scripts/setup_gcp.sh b/bin/ci/scripts/setup_gcp.sh deleted file mode 100755 index 09795515..00000000 --- a/bin/ci/scripts/setup_gcp.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -if [ -z ${BASE64_GOOGLE_APPLICATION_CREDENTIALS+x} ] || [ -z ${GOOGLE_APPLICATION_CREDENTIALS+x} ]; -then - echo "GCP secret variables are not set, ignoring..." -else - printenv BASE64_GOOGLE_APPLICATION_CREDENTIALS | base64 --decode > "${GOOGLE_APPLICATION_CREDENTIALS}" -fi diff --git a/composer.json b/composer.json index 6d7299bb..535f91fb 100644 --- a/composer.json +++ b/composer.json @@ -35,7 +35,7 @@ "ext-gettext": "*", "phpmd/phpmd": "@stable", "squizlabs/php_codesniffer": "@stable", - "phpstan/phpstan": "^1.5", + "phpstan/phpstan": "@stable", "jetbrains/phpstorm-stubs": "dev-master", "phpfastcache/phpfastcache-devtools": "^9.2" }, @@ -45,25 +45,20 @@ "ext-intl": "*", "ext-memcached": "*", "ext-cassandra": "*", - "ext-grpc": "*", "ext-memcache": "*", - "ext-mongodb": "*", "ext-redis": "*", - "ext-xcache": "*", "ext-sqlite": "*", "ext-wincache": "*", "ext-leveldb": "*", - "ext-couchbase": "*", - "ext-couchbase_v3": "*", + "ext-couchbase": "^3.0", "predis/predis": "^1.1", - "mongodb/mongodb": "^1.9", "phpfastcache/phpssdb": "~1.1.0", - "solarium/solarium": "~6.1", - "doctrine/couchdb": "^dev-master#9eeb9e5", - "google/cloud-firestore": "^1.20", - "aws/aws-sdk-php": "~3.0", "phpfastcache/arangodb-extension": "^9.2", + "phpfastcache/couchbasev4-extension": "^9.2", "phpfastcache/couchdb-extension": "^9.2", + "phpfastcache/dynamodb-extension": "^9.2", + "phpfastcache/firestore-extension": "^9.2", + "phpfastcache/mongodb-extension": "^9.2", "phpfastcache/solr-extension": "^9.2" }, "conflict": { diff --git a/docs/DRIVERS.md b/docs/DRIVERS.md index e35b5fb5..37ea35bb 100644 --- a/docs/DRIVERS.md +++ b/docs/DRIVERS.md @@ -5,8 +5,10 @@ * The Alternative Php User Cache (APCU) driver. A memory cache for regular performances. * Arangodb **(Added in v9)** * A very high-performance NoSQL driver using a key-value pair system. + * :new: Is now a composer extension separated from the Phpfastcache core as of v9.2: `phpfastcache/arangodb-extension` * Cassandra * A very high-performance NoSQL driver using a key-value pair system. Please note that the Driver rely on php's Datastax extension: https://github.com/datastax/php-driver + * As of PHP an unofficial fork has been launched due to Datastax lack of maintenance: https://github.com/he4rt/scylladb-php-driver * Cookie **(REMOVED in v9)** * A cookie driver to store non-sensitive scalar (only) data. Limited storage up to 4Ko. * Couchbase **(REMOVED in v9)** @@ -19,6 +21,7 @@ * :new: It is now a [separated extension](https://github.com/PHPSocialNetwork/couchbasev4-extension) which is no longer part of the Phpfastcache's core. * Couchdb * A very high-performance NoSQL driver using a key-value pair system. + * :new: Is now a composer extension separated from the Phpfastcache core as of v9.2: `phpfastcache/couchdb-extension` * Devfalse **(REMOVED in v9)** * A development driver that return false for everything except driverCheck(). * Devnull @@ -29,10 +32,12 @@ * A development driver with configurable factor chance and data length. * Dynamodb **(Added in v9)** * An AWS cloud NoSQL driver using a key-value pair system. Be careful when flushing the table as it will delete and recreate the table due to a Dynamodb limitation. + * :new: Is now a composer extension separated from the Phpfastcache core as of v9.2: `phpfastcache/dynamodb-extension` * Files * A file driver that use serialization for storing data for regular performances. A _$path_ config must be specified, else the system temporary directory will be used. * Firestore **(Added in v9)** * A GCP cloud NoSQL driver using a key-value pair system. Collections are created automatically on-the-fly. + * :new: Is now a composer extension separated from the Phpfastcache core as of v9.2: `phpfastcache/firestore-extension` * Leveldb * A NoSQL driver using a key-value pair system. A _$path_ config must be specified, else the system temporary directory will be used. * Memcache @@ -43,6 +48,7 @@ * The Memstatic driver is a memory static driver that expires when the script execution ends. * Mongodb * A very high-performance NoSQL driver using a key-value pair system. + * :new: Is now a composer extension separated from the Phpfastcache core as of v9.2: `phpfastcache/mongodb-extension` * Predis * A high-performance memory driver using a in-memory data structure storage. Less efficient than Redis driver as it is an embedded library. * Redis/Rediscluster @@ -52,6 +58,7 @@ * A very high-performance NoSQL driver using a key-value pair system. * Solr **(Added in v9.1)** * A Solr driver that use Solarium as PHP client for good performances. + * :new: Is now a composer extension separated from the Phpfastcache core as of v9.2: `phpfastcache/solr-extension` * Sqlite * A Sqlite driver that use serialization for storing data for regular performances. A _$path_ config must be specified, else the system temporary directory will be used. * Ssdb diff --git a/docs/EVENTS.md b/docs/EVENTS.md index f2efb2e1..88477acc 100644 --- a/docs/EVENTS.md +++ b/docs/EVENTS.md @@ -317,15 +317,7 @@ See [Arangodb extension event documentation](https://github.com/PHPSocialNetwork See [Couchdb extension event documentation](https://github.com/PHPSocialNetwork/couchdb-extension#events). #### Dynamodb -- onDynamodbCreateTable(*Callable* **$callback**) - - **Callback arguments** - - *ExtendedCacheItemPoolInterface* **$itemPool** - - *EventReferenceParameter($params)* **$params** _via EventReferenceParameter object_ **(type modification forbidden)** - - **Scope** - - Dynamodb Driver - - **Description** - - Allow you to alter the parameters built used to create the table - - **Risky Circular Methods**: None +See [Dynamodb extension event documentation](https://github.com/PHPSocialNetwork/dynamodb-extension#events). #### Solr See [Solr extension event documentation](https://github.com/PHPSocialNetwork/solr-extension#events). diff --git a/lib/Phpfastcache/Drivers/Dynamodb/Config.php b/lib/Phpfastcache/Drivers/Dynamodb/Config.php deleted file mode 100644 index eaa5e4e5..00000000 --- a/lib/Phpfastcache/Drivers/Dynamodb/Config.php +++ /dev/null @@ -1,230 +0,0 @@ - - * @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors - */ - -declare(strict_types=1); - -namespace Phpfastcache\Drivers\Dynamodb; - -use Phpfastcache\Config\ConfigurationOption; -use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface; -use Phpfastcache\Exceptions\PhpfastcacheLogicException; - -/** - * @SuppressWarnings(PHPMD.TooManyFields) - */ -class Config extends ConfigurationOption -{ - protected ?string $awsAccessKeyId = null; - protected ?string $awsSecretAccessKey = null; - protected bool $allowEnvCredentialOverride = false; - protected ?string $endpoint = null; -// List of endpoints here: https://docs.aws.amazon.com/general/latest/gr/ddb.html - - protected string $region; - protected string $table; - protected bool $debugEnabled = false; - protected string $version = 'latest'; - protected string $partitionKey = ExtendedCacheItemPoolInterface::DRIVER_KEY_WRAPPER_INDEX; - public function __construct(array $parameters = []) - { - parent::__construct($parameters); - $this->awsAccessKeyId = $this->getSuperGlobalAccessor()('SERVER', 'AWS_ACCESS_KEY_ID'); - $this->awsSecretAccessKey = $this->getSuperGlobalAccessor()('SERVER', 'AWS_SECRET_ACCESS_KEY'); - } - - /** - * @return string|null - */ - public function getAwsAccessKeyId(): ?string - { - return $this->awsAccessKeyId; - } - - /** - * @param string|null $awsAccessKeyId - * @return Config - * @throws PhpfastcacheLogicException - */ - public function setAwsAccessKeyId(?string $awsAccessKeyId): Config - { - if ($awsAccessKeyId !== null) { - if (!getenv('AWS_ACCESS_KEY_ID')) { - if (!$this->isAllowEnvCredentialOverride()) { - throw new PhpfastcacheLogicException('You are not allowed to override AWS environment variables.'); - } - \putenv("AWS_ACCESS_KEY_ID=$awsAccessKeyId"); - } - - return $this->setProperty('awsAccessKeyId', getenv('AWS_ACCESS_KEY_ID')); - } - return $this; - } - - /** - * @return string|null - */ - public function getAwsSecretAccessKey(): ?string - { - return $this->awsSecretAccessKey; - } - - /** - * @param string|null $awsSecretAccessKey - * @return Config - * @throws PhpfastcacheLogicException - */ - public function setAwsSecretAccessKey(?string $awsSecretAccessKey): Config - { - if ($awsSecretAccessKey !== null) { - if (!getenv('AWS_SECRET_ACCESS_KEY')) { - if (!$this->isAllowEnvCredentialOverride()) { - throw new PhpfastcacheLogicException('You are not allowed to override AWS environment variables.'); - } - \putenv("AWS_SECRET_ACCESS_KEY=$awsSecretAccessKey"); - } - - return $this->setProperty('awsSecretAccessKey', getenv('AWS_SECRET_ACCESS_KEY')); - } - return $this; - } - - /** - * @return bool - */ - public function isAllowEnvCredentialOverride(): bool - { - return $this->allowEnvCredentialOverride; - } - - /** - * @param bool $allowEnvCredentialOverride - * @return Config - * @throws PhpfastcacheLogicException - */ - public function setAllowEnvCredentialOverride(bool $allowEnvCredentialOverride): Config - { - return $this->setProperty('allowEnvCredentialOverride', $allowEnvCredentialOverride); - } - - /** - * @return ?string - */ - public function getEndpoint(): ?string - { - return $this->endpoint; - } - - /** - * @param ?string $endpoint - * @return Config - * @throws PhpfastcacheLogicException - */ - public function setEndpoint(?string $endpoint): Config - { - if (!\str_starts_with($endpoint, 'https://') && \str_ends_with($endpoint, 'amazonaws.com')) { - $endpoint = 'https://' . $endpoint; - } - return $this->setProperty('endpoint', $endpoint); - } - - /** - * @return string - */ - public function getRegion(): string - { - return $this->region; - } - - /** - * @param string $region - * @return Config - * @throws PhpfastcacheLogicException - */ - public function setRegion(string $region): Config - { - return $this->setProperty('region', $region); - } - - /** - * @return string - */ - public function getTable(): string - { - return $this->table; - } - - /** - * @param string $table - * @return Config - * @throws PhpfastcacheLogicException - */ - public function setTable(string $table): Config - { - return $this->setProperty('table', $table); - } - - /** - * @return bool - */ - public function isDebugEnabled(): bool - { - return $this->debugEnabled; - } - - /** - * @param bool $debugEnabled - * @return Config - * @throws PhpfastcacheLogicException - */ - public function setDebugEnabled(bool $debugEnabled): Config - { - return $this->setProperty('debugEnabled', $debugEnabled); - } - - /** - * @return string - */ - public function getVersion(): string - { - return $this->version; - } - - /** - * @param string $version - * @return Config - * @throws PhpfastcacheLogicException - */ - public function setVersion(string $version): Config - { - return $this->setProperty('version', $version); - } - - /** - * @return string - */ - public function getPartitionKey(): string - { - return $this->partitionKey; - } - - /** - * @param string $partitionKey - * @return Config - * @throws PhpfastcacheLogicException - */ - public function setPartitionKey(string $partitionKey): Config - { - return $this->setProperty('partitionKey', $partitionKey); - } -} diff --git a/lib/Phpfastcache/Drivers/Dynamodb/Driver.php b/lib/Phpfastcache/Drivers/Dynamodb/Driver.php deleted file mode 100644 index 4a64f7e5..00000000 --- a/lib/Phpfastcache/Drivers/Dynamodb/Driver.php +++ /dev/null @@ -1,306 +0,0 @@ - - * @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors - */ - -declare(strict_types=1); - -namespace Phpfastcache\Drivers\Dynamodb; - -use Aws\Sdk as AwsSdk; -use Aws\DynamoDb\DynamoDbClient as AwsDynamoDbClient; -use Aws\DynamoDb\Marshaler as AwsMarshaler; -use Aws\DynamoDb\Exception\DynamoDbException as AwsDynamoDbException; -use Phpfastcache\Cluster\AggregatablePoolInterface; -use Phpfastcache\Core\Item\ExtendedCacheItemInterface; -use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface; -use Phpfastcache\Core\Pool\TaggableCacheItemPoolTrait; -use Phpfastcache\Entities\DriverStatistic; -use Phpfastcache\Event\EventReferenceParameter; -use Phpfastcache\Exceptions\PhpfastcacheDriverConnectException; -use Phpfastcache\Exceptions\PhpfastcacheDriverException; -use Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException; -use Phpfastcache\Exceptions\PhpfastcacheLogicException; -use Psr\Http\Message\UriInterface; - -/** - * Class Driver - * @method Config getConfig() - * @property AwsDynamoDbClient $instance - * @SuppressWarnings(PHPMD.CouplingBetweenObjects) - */ -class Driver implements AggregatablePoolInterface -{ - use TaggableCacheItemPoolTrait; - - protected const TTL_FIELD_NAME = 't'; - - protected AwsSdk $awsSdk; - - protected AwsMarshaler $marshaler; - - /** - * @return bool - */ - public function driverCheck(): bool - { - return \class_exists(AwsSdk::class) && \class_exists(AwsDynamoDbClient::class); - } - - /** - * @return bool - * @throws PhpfastcacheDriverConnectException - * @throws PhpfastcacheDriverException - * @throws PhpfastcacheLogicException - * @throws PhpfastcacheInvalidArgumentException - */ - protected function driverConnect(): bool - { - $wsAccessKey = $this->getConfig()->getSuperGlobalAccessor()('SERVER', 'AWS_ACCESS_KEY_ID'); - $awsSecretKey = $this->getConfig()->getSuperGlobalAccessor()('SERVER', 'AWS_SECRET_ACCESS_KEY'); - - if (empty($wsAccessKey)) { - throw new PhpfastcacheDriverConnectException('The environment configuration AWS_ACCESS_KEY_ID must be set'); - } - - if (empty($awsSecretKey)) { - throw new PhpfastcacheDriverConnectException('The environment configuration AWS_SECRET_ACCESS_KEY must be set'); - } - - $this->awsSdk = new AwsSdk([ - 'endpoint' => $this->getConfig()->getEndpoint(), - 'region' => $this->getConfig()->getRegion(), - 'version' => $this->getConfig()->getVersion(), - 'debug' => $this->getConfig()->isDebugEnabled(), - ]); - $this->instance = $this->awsSdk->createDynamoDb(); - $this->marshaler = new AwsMarshaler(); - - if (!$this->hasTable()) { - $this->createTable(); - } - - if (!$this->hasTtlEnabled()) { - $this->enableTtl(); - } - - return true; - } - - /** - * @param ExtendedCacheItemInterface $item - * @return bool - * @throws PhpfastcacheLogicException - */ - protected function driverWrite(ExtendedCacheItemInterface $item): bool - { - $awsItem = $this->marshaler->marshalItem( - \array_merge( - $this->encodeDocument($this->driverPreWrap($item, true)), - ['t' => $item->getExpirationDate()->getTimestamp()] - ) - ); - - $result = $this->instance->putItem([ - 'TableName' => $this->getConfig()->getTable(), - 'Item' => $awsItem - ]); - - return ($result->get('@metadata')['statusCode'] ?? null) === 200; - } - - /** - * @param ExtendedCacheItemInterface $item - * @return ?array - * @throws \Exception - */ - protected function driverRead(ExtendedCacheItemInterface $item): ?array - { - $key = $this->marshaler->marshalItem([ - $this->getConfig()->getPartitionKey() => $item->getKey() - ]); - - $result = $this->instance->getItem([ - 'TableName' => $this->getConfig()->getTable(), - 'Key' => $key - ]); - - $awsItem = $result->get('Item'); - - if ($awsItem !== null) { - return $this->decodeDocument( - $this->marshaler->unmarshalItem($awsItem) - ); - } - - return null; - } - - /** - * @param string $key - * @param string $encodedKey - * @return bool - */ - protected function driverDelete(string $key, string $encodedKey): bool - { - $dynKey = $this->marshaler->marshalItem([ - $this->getConfig()->getPartitionKey() => $key - ]); - - $result = $this->instance->deleteItem([ - 'TableName' => $this->getConfig()->getTable(), - 'Key' => $dynKey - ]); - - return ($result->get('@metadata')['statusCode'] ?? null) === 200; - } - - /** - * @return bool - * @throws PhpfastcacheDriverException - */ - protected function driverClear(): bool - { - $params = [ - 'TableName' => $this->getConfig()->getTable(), - ]; - - $result = $this->instance->deleteTable($params); - - $this->instance->waitUntil('TableNotExists', $params); - - $this->createTable(); - $this->enableTtl(); - - return ($result->get('@metadata')['statusCode'] ?? null) === 200; - } - - protected function hasTable(): bool - { - return \count($this->instance->listTables(['TableNames' => [$this->getConfig()->getTable()]])->get('TableNames')) > 0; - } - - protected function createTable(): void - { - $params = [ - 'TableName' => $this->getConfig()->getTable(), - 'KeySchema' => [ - [ - 'AttributeName' => $this->getConfig()->getPartitionKey(), - 'KeyType' => 'HASH' - ] - ], - 'AttributeDefinitions' => [ - [ - 'AttributeName' => $this->getConfig()->getPartitionKey(), - 'AttributeType' => 'S' - ], - ], - 'ProvisionedThroughput' => [ - 'ReadCapacityUnits' => 10, - 'WriteCapacityUnits' => 10 - ] - ]; - - $this->eventManager->dispatch(Event::DYNAMODB_CREATE_TABLE, $this, new EventReferenceParameter($params)); - - $this->instance->createTable($params); - $this->instance->waitUntil('TableExists', $params); - } - - protected function hasTtlEnabled(): bool - { - $ttlDesc = $this->instance->describeTimeToLive(['TableName' => $this->getConfig()->getTable()])->get('TimeToLiveDescription'); - - if (!isset($ttlDesc['AttributeName'], $ttlDesc['TimeToLiveStatus'])) { - return false; - } - - return $ttlDesc['TimeToLiveStatus'] === 'ENABLED' && $ttlDesc['AttributeName'] === self::TTL_FIELD_NAME; - } - - /** - * @throws PhpfastcacheDriverException - */ - protected function enableTtl(): void - { - try { - $this->instance->updateTimeToLive([ - 'TableName' => $this->getConfig()->getTable(), - 'TimeToLiveSpecification' => [ - "AttributeName" => self::TTL_FIELD_NAME, - "Enabled" => true - ], - ]); - } catch (AwsDynamoDbException $e) { - /** - * Error 400 can be an acceptable error of a - * Dynamodb restriction: "Time to live has been modified multiple times within a fixed interval" - * @see https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_UpdateTimeToLive.html - */ - if ($e->getStatusCode() !== 400) { - throw new PhpfastcacheDriverException( - 'Failed to enable TTL with the following error: ' . $e->getMessage() - ); - } - } - } - - public function getStats(): DriverStatistic - { - /** @var UriInterface $endpoint */ - $endpoint = $this->instance->getEndpoint(); - $table = $this->instance->describeTable(['TableName' => $this->getConfig()->getTable()])->get('Table'); - - $info = \sprintf( - 'Dynamo server "%s" | Table "%s" with %d item(s) stored', - $endpoint->getHost(), - $table['TableName'] ?? 'Unknown table name', - $table['ItemCount'] ?? 'Unknown item count', - ); - - $data = [ - 'dynamoEndpoint' => $endpoint, - 'dynamoTable' => $table, - 'dynamoConfig' => $this->instance->getConfig(), - 'dynamoApi' => $this->instance->getApi()->toArray(), - ]; - - return (new DriverStatistic()) - ->setData(implode(', ', array_keys($this->itemInstances))) - ->setInfo($info) - ->setRawData($data) - ->setSize($data['dynamoTable']['TableSizeBytes'] ?? 0); - } - - /** - * @param array $data - * @return array - */ - protected function encodeDocument(array $data): array - { - $data[self::DRIVER_DATA_WRAPPER_INDEX] = $this->encode($data[self::DRIVER_DATA_WRAPPER_INDEX]); - - return $data; - } - - /** - * @param array $data - * @return array - */ - protected function decodeDocument(array $data): array - { - $data[self::DRIVER_DATA_WRAPPER_INDEX] = $this->unserialize($data[self::DRIVER_DATA_WRAPPER_INDEX]); - - return $data; - } -} diff --git a/lib/Phpfastcache/Drivers/Dynamodb/Event.php b/lib/Phpfastcache/Drivers/Dynamodb/Event.php deleted file mode 100644 index 1ccce6e7..00000000 --- a/lib/Phpfastcache/Drivers/Dynamodb/Event.php +++ /dev/null @@ -1,8 +0,0 @@ - - * @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors - */ - -declare(strict_types=1); - -namespace Phpfastcache\Drivers\Dynamodb; - -use Phpfastcache\Core\Item\ExtendedCacheItemInterface; -use Phpfastcache\Core\Item\TaggableCacheItemTrait; - -class Item implements ExtendedCacheItemInterface -{ - use TaggableCacheItemTrait; - - protected function getDriverClass(): string - { - return Driver::class; - } -} diff --git a/lib/Phpfastcache/Drivers/Firestore/Config.php b/lib/Phpfastcache/Drivers/Firestore/Config.php deleted file mode 100644 index 009bcde4..00000000 --- a/lib/Phpfastcache/Drivers/Firestore/Config.php +++ /dev/null @@ -1,211 +0,0 @@ - - * @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors - */ - -declare(strict_types=1); - -namespace Phpfastcache\Drivers\Firestore; - -use Google\Cloud\Firestore\FirestoreClient as GoogleFirestoreClient; -use Phpfastcache\Config\ConfigurationOption; -use Phpfastcache\Exceptions\PhpfastcacheLogicException; - -/** - * @SuppressWarnings(PHPMD.TooManyFields) - */ -class Config extends ConfigurationOption -{ - protected int $batchSize = 100; - protected ?string $googleCloudProject = null; - protected ?string $googleApplicationCredential = null; - protected bool $allowEnvCredentialOverride = false; - protected string $collectionName = 'phpfastcache'; - protected ?GoogleFirestoreClient $firestoreClient = null; - - /** - * @see \Google\Cloud\Firestore\FirestoreClient::DEFAULT_DATABASE - */ - protected string $databaseName = '(default)'; - - /** - * @inheritDoc - */ - public function __construct(array $parameters = []) - { - parent::__construct($parameters); - $this->googleCloudProject = $this->getSuperGlobalAccessor()('SERVER', 'GOOGLE_CLOUD_PROJECT'); - $this->googleApplicationCredential = $this->getSuperGlobalAccessor()('SERVER', 'GOOGLE_APPLICATION_CREDENTIALS'); - } - - public function getBatchSize(): int - { - return $this->batchSize; - } - - public function setBatchSize(int $batchSize): Config - { - return $this->setProperty('batchSize', $batchSize); - } - - /** - * @return string - * @deprecated As of 9.2, will be removed in v10. - * @see self::getCollectionName() - */ - public function getCollection(): string - { - return $this->collectionName; - } - - /** - * @param string $collectionName - * @return Config - * @throws PhpfastcacheLogicException - * @see self::setCollectionName() - * @deprecated As of 9.2, will be removed in v10. - */ - public function setCollection(string $collectionName): Config - { - if (isset($this->collectionName) && $collectionName !== $this->collectionName) { - trigger_error('getCollection/setCollection methods are deprecated, use getCollectionName/setCollectionName instead', E_USER_DEPRECATED); - } - return $this->setProperty('collectionName', $collectionName); - } - - /** - * @return string - */ - public function getCollectionName(): string - { - return $this->collectionName; - } - - /** - * @param string $collectionName - * @return Config - * @throws PhpfastcacheLogicException - */ - public function setCollectionName(string $collectionName): Config - { - return $this->setProperty('collectionName', $collectionName); - } - - /** - * @return string - */ - public function getDatabaseName(): string - { - return $this->databaseName; - } - - /** - * @param string $databaseName - * @return Config - * @throws PhpfastcacheLogicException - */ - public function setDatabaseName(string $databaseName): Config - { - return $this->setProperty('databaseName', $databaseName); - } - - - - /** - * @return string|null - */ - public function getGoogleCloudProject(): ?string - { - return $this->googleCloudProject; - } - - /** - * @param string|null $googleCloudProject - * @return Config - * @throws PhpfastcacheLogicException - */ - public function setGoogleCloudProject(?string $googleCloudProject): Config - { - if ($googleCloudProject !== null) { - if (!getenv('GOOGLE_CLOUD_PROJECT')) { - if (!$this->isAllowEnvCredentialOverride()) { - throw new PhpfastcacheLogicException('You are not allowed to override GCP environment variables.'); - } - \putenv("GOOGLE_CLOUD_PROJECT=$googleCloudProject"); - } - return $this->setProperty('googleCloudProject', getenv('GOOGLE_CLOUD_PROJECT')); - } - return $this; - } - - /** - * @return string|null - */ - public function getGoogleApplicationCredential(): ?string - { - return $this->googleApplicationCredential; - } - - /** - * @param string|null $googleApplicationCredential - * @return Config - * @throws PhpfastcacheLogicException - */ - public function setGoogleApplicationCredential(?string $googleApplicationCredential): Config - { - if ($googleApplicationCredential !== null) { - if (!getenv('GOOGLE_APPLICATION_CREDENTIALS')) { - if (!$this->isAllowEnvCredentialOverride()) { - throw new PhpfastcacheLogicException('You are not allowed to override GCP environment variables.'); - } - \putenv("GOOGLE_APPLICATION_CREDENTIALS=$googleApplicationCredential"); - } - return $this->setProperty('googleApplicationCredential', getenv('GOOGLE_APPLICATION_CREDENTIALS')); - } - return $this; - } - - /** - * @return bool - */ - public function isAllowEnvCredentialOverride(): bool - { - return $this->allowEnvCredentialOverride; - } - - /** - * @param bool $allowEnvCredentialOverride - * @return Config - */ - public function setAllowEnvCredentialOverride(bool $allowEnvCredentialOverride): Config - { - return $this->setProperty('allowEnvCredentialOverride', $allowEnvCredentialOverride); - } - - /** - * @return GoogleFirestoreClient|null - */ - public function getFirestoreClient(): ?GoogleFirestoreClient - { - return $this->firestoreClient; - } - - /** - * @param GoogleFirestoreClient|null $firestoreClient - * @return Config - * @throws PhpfastcacheLogicException - */ - public function setRedisClient(?GoogleFirestoreClient $firestoreClient): Config - { - return $this->setProperty('firestoreClient', $firestoreClient); - } -} diff --git a/lib/Phpfastcache/Drivers/Firestore/Driver.php b/lib/Phpfastcache/Drivers/Firestore/Driver.php deleted file mode 100644 index c55be226..00000000 --- a/lib/Phpfastcache/Drivers/Firestore/Driver.php +++ /dev/null @@ -1,247 +0,0 @@ - - * @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors - */ - -declare(strict_types=1); - -namespace Phpfastcache\Drivers\Firestore; - -use Google\Cloud\Core\Blob as GoogleBlob; -use Google\Cloud\Core\Timestamp as GoogleTimestamp; -use Google\Cloud\Firestore\DocumentSnapshot; -use Google\Cloud\Firestore\FirestoreClient as GoogleFirestoreClient; -use Phpfastcache\Cluster\AggregatablePoolInterface; -use Phpfastcache\Core\Item\ExtendedCacheItemInterface; -use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface; -use Phpfastcache\Core\Pool\TaggableCacheItemPoolTrait; -use Phpfastcache\Entities\DriverStatistic; -use Phpfastcache\Event\EventReferenceParameter; -use Phpfastcache\Exceptions\PhpfastcacheDriverCheckException; -use Phpfastcache\Exceptions\PhpfastcacheDriverConnectException; -use Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException; -use Phpfastcache\Exceptions\PhpfastcacheLogicException; - -/** - * Class Driver - * @method Config getConfig() - * @property GoogleFirestoreClient $instance - */ -class Driver implements AggregatablePoolInterface -{ - use TaggableCacheItemPoolTrait; - - public const MINIMUM_FIRESTORE_CLIENT_VERSION = '1.35.0'; - - /** - * @return bool - */ - public function driverCheck(): bool - { - if (!\class_exists(GoogleFirestoreClient::class) || !\extension_loaded('grpc')) { - return false; - } - - if (!version_compare(GoogleFirestoreClient::VERSION, self::MINIMUM_FIRESTORE_CLIENT_VERSION, '>=')) { - throw new PhpfastcacheDriverCheckException( - sprintf( - 'Firestore client version must be at least %s or greater.', - self::MINIMUM_FIRESTORE_CLIENT_VERSION - ) - ); - } - return true; - } - - /** - * @return bool - * @throws PhpfastcacheDriverConnectException - * @throws PhpfastcacheInvalidArgumentException - * @throws PhpfastcacheLogicException - */ - protected function driverConnect(): bool - { - if ($this->getConfig()->getFirestoreClient()) { - $this->instance = $this->getConfig()->getFirestoreClient(); - } else { - $gcpId = $this->getConfig()->getSuperGlobalAccessor()('SERVER', 'GOOGLE_CLOUD_PROJECT'); - $gacPath = $this->getConfig()->getSuperGlobalAccessor()('SERVER', 'GOOGLE_APPLICATION_CREDENTIALS'); - - if (empty($gcpId)) { - throw new PhpfastcacheDriverConnectException('The environment configuration GOOGLE_CLOUD_PROJECT must be set'); - } - - if (empty($gacPath) || !\is_readable($gacPath)) { - throw new PhpfastcacheDriverConnectException( - 'The environment configuration GOOGLE_APPLICATION_CREDENTIALS must be set and the JSON file must be readable.' - ); - } - - $options = ['database' => $this->getConfig()->getDatabaseName()]; - - $this->eventManager->dispatch(Event::FIRESTORE_CLIENT_OPTIONS, $this, new EventReferenceParameter($options)); - - $this->instance = new GoogleFirestoreClient($options); - } - - return true; - } - - /** - * @param ExtendedCacheItemInterface $item - * @return bool - */ - protected function driverWrite(ExtendedCacheItemInterface $item): bool - { - $this->instance->collection($this->getConfig()->getCollectionName()) - ->document($item->getKey()) - ->set( - $this->driverPreWrap($item), - ['merge' => true] - ); - - return true; - } - - /** - * @param ExtendedCacheItemInterface $item - * @return ?array - * @throws \Exception - */ - protected function driverRead(ExtendedCacheItemInterface $item): ?array - { - $doc = $this->instance->collection($this->getConfig()->getCollectionName()) - ->document($item->getKey()); - - $snapshotData = $doc->snapshot()->data(); - - if (\is_array($snapshotData)) { - return $this->decodeFirestoreDocument($snapshotData); - } - - return null; - } - - /** - * @return array - * @throws PhpfastcacheInvalidArgumentException - */ - protected function driverReadAllKeys(string $pattern = ''): iterable - { - if ($pattern !== '') { - $this->throwUnsupportedDriverReadAllPattern(); - } - $data = []; - $documents = $this->instance->collection($this->getConfig()->getCollectionName()) - ->limit(ExtendedCacheItemPoolInterface::MAX_ALL_KEYS_COUNT) - ->documents(); - - /** @var DocumentSnapshot[] $documents */ - foreach ($documents as $document) { - $data[] = $document->id(); - } - - return $data; - } - - /** - * @param ExtendedCacheItemInterface ...$items - * @return array> - * @throws \Phpfastcache\Exceptions\PhpfastcacheDriverException - * @throws \RedisException - */ - protected function driverReadMultiple(ExtendedCacheItemInterface ...$items): array - { - $data = []; - $keys = $this->getKeys($items); - $documents = $this->instance->collection($this->getConfig()->getCollectionName()) - ->limit(ExtendedCacheItemPoolInterface::MAX_ALL_KEYS_COUNT) - ->where(ExtendedCacheItemPoolInterface::DRIVER_KEY_WRAPPER_INDEX, 'in', $keys) - ->documents(); - - /** @var DocumentSnapshot[] $documents */ - foreach ($documents as $document) { - $data[$document->id()] = $this->decodeFirestoreDocument($document->data()); - } - - return $data; - } - - /** - * @param string $key - * @param string $encodedKey - * @return bool - */ - protected function driverDelete(string $key, string $encodedKey): bool - { - $this->instance->collection($this->getConfig()->getCollectionName()) - ->document($key) - ->delete(); - - return true; - } - - /** - * @return bool - */ - protected function driverClear(): bool - { - $batchSize = $this->getConfig()->getBatchSize(); - $collection = $this->instance->collection($this->getConfig()->getCollectionName()); - do { - $documents = $collection->limit($batchSize)->documents(); - /** @var DocumentSnapshot $document */ - foreach ($documents as $document) { - $document->reference()->delete(); - } - } while (!$documents->isEmpty()); - - return true; - } - - /** - * @param array $snapshotData - * @return array - */ - protected function decodeFirestoreDocument(array $snapshotData): array - { - return \array_map(static function ($datum) { - if ($datum instanceof GoogleTimestamp) { - $date = $datum->get(); - if ($date instanceof \DateTimeImmutable) { - return \DateTime::createFromImmutable($date); - } - return $date; - } - - if ($datum instanceof GoogleBlob) { - return (string) $datum; - } - - return $datum; - }, $snapshotData); - } - - public function getStats(): DriverStatistic - { - $info = sprintf( - 'Firestore client v%s, collection "%s". No additional info provided by Google Firestore', - defined($this->instance::class . '::VERSION') ? $this->instance::VERSION : '[unknown version]', - $this->getConfig()->getCollectionName(), - ); - return (new DriverStatistic()) - ->setData(implode(', ', array_keys($this->itemInstances))) - ->setInfo($info) - ->setRawData([]) - ->setSize(0); - } -} diff --git a/lib/Phpfastcache/Drivers/Firestore/Event.php b/lib/Phpfastcache/Drivers/Firestore/Event.php deleted file mode 100644 index 9e775e58..00000000 --- a/lib/Phpfastcache/Drivers/Firestore/Event.php +++ /dev/null @@ -1,8 +0,0 @@ - - * @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors - */ - -declare(strict_types=1); - -namespace Phpfastcache\Drivers\Firestore; - -use Phpfastcache\Core\Item\ExtendedCacheItemInterface; -use Phpfastcache\Core\Item\TaggableCacheItemTrait; - -class Item implements ExtendedCacheItemInterface -{ - use TaggableCacheItemTrait; - - protected function getDriverClass(): string - { - return Driver::class; - } -} diff --git a/tests/cases/Mongodb.test.php b/tests/cases/Casssandra.test.php similarity index 65% rename from tests/cases/Mongodb.test.php rename to tests/cases/Casssandra.test.php index 58c37a9a..9e04e5e3 100644 --- a/tests/cases/Mongodb.test.php +++ b/tests/cases/Casssandra.test.php @@ -13,14 +13,12 @@ */ use Phpfastcache\CacheManager; -use Phpfastcache\Drivers\Mongodb\Config; use Phpfastcache\Tests\Helper\TestHelper; -use Phpfastcache\Tests\Config\ConfigFactory; chdir(__DIR__); require_once __DIR__ . '/../../vendor/autoload.php'; -$testHelper = new TestHelper('Mongodb driver'); - -$cacheInstance = CacheManager::getInstance('Mongodb', ConfigFactory::getDefaultConfig('Mongodb')); -$testHelper->runCRUDTests($cacheInstance); +$testHelper = new TestHelper('Apcu test (CRUD)'); +$pool = CacheManager::getInstance('Cassandra'); +$pool->clear(); +$testHelper->runCRUDTests($pool); $testHelper->terminateTest(); diff --git a/tests/cases/Dynamodb.test.php b/tests/cases/Dynamodb.test.php deleted file mode 100644 index f1a32e2d..00000000 --- a/tests/cases/Dynamodb.test.php +++ /dev/null @@ -1,48 +0,0 @@ - - * @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors - */ - -use Phpfastcache\CacheManager; -use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface; -use Phpfastcache\Drivers\Dynamodb\Config as DynamodbConfig; -use Phpfastcache\Exceptions\PhpfastcacheDriverConnectException; -use Phpfastcache\Tests\Helper\TestHelper; - -chdir(__DIR__); -require_once __DIR__ . '/../../vendor/autoload.php'; -$testHelper = new TestHelper('Amazon Dynamodb driver'); - -$config = new DynamodbConfig(); - -try { - $config->setItemDetailedDate(true); - $config->setRegion('eu-west-3'); - $config->setEndpoint('dynamodb.eu-west-3.amazonaws.com'); - $config->setTable('phpfastcache'); - $cacheInstance = CacheManager::getInstance('Dynamodb', $config); - - $cacheInstance->getEventManager()->onDynamodbCreateTable(static function(ExtendedCacheItemPoolInterface $pool, array $params) use ($testHelper){ - $testHelper->printDebugText( - sprintf( - 'Table created with the following parameters: %s', - json_encode($params, JSON_THROW_ON_ERROR) - ) - ); - }); - - $testHelper->runCRUDTests($cacheInstance, false); -} catch (PhpfastcacheDriverConnectException $e) { - $testHelper->assertSkip('Dynamodb server unavailable: ' . $e->getMessage()); - $testHelper->terminateTest(); -} -$testHelper->terminateTest(); diff --git a/tests/cases/Firestore.test.php b/tests/cases/Firestore.test.php deleted file mode 100644 index 276d75bf..00000000 --- a/tests/cases/Firestore.test.php +++ /dev/null @@ -1,43 +0,0 @@ - - * @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors - */ - -use Phpfastcache\CacheManager; -use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface; -use Phpfastcache\Drivers\Firestore\Config as FirestoreConfig; -use Phpfastcache\Exceptions\PhpfastcacheDriverConnectException; -use Phpfastcache\Tests\Helper\TestHelper; - -chdir(__DIR__); -require_once __DIR__ . '/../../vendor/autoload.php'; -$testHelper = new TestHelper('Google Firestore driver'); - -/** - * This driver awaits some fixes on Google side related to psr/cache version - * - * @see https://github.com/googleapis/google-auth-library-php/pull/364 - * @see https://github.com/googleapis/google-auth-library-php/issues/363 - */ - -$config = new FirestoreConfig(); - -try { - $config->setItemDetailedDate(true); - $config->setCollectionName('phpfastcache'); - $cacheInstance = CacheManager::getInstance('Firestore', $config); - $testHelper->runCRUDTests($cacheInstance); -} catch (PhpfastcacheDriverConnectException $e) { - $testHelper->assertSkip('Firestore server unavailable: ' . $e->getMessage()); - $testHelper->terminateTest(); -} -$testHelper->terminateTest(); diff --git a/tests/cases/GetAllItems.test.php b/tests/cases/GetAllItems.test.php index 86d3b12a..a24e2a6e 100644 --- a/tests/cases/GetAllItems.test.php +++ b/tests/cases/GetAllItems.test.php @@ -42,13 +42,10 @@ }); $drivers = [ - 'Couchdb', - 'Mongodb', - 'Memstatic', + 'Memory', 'Predis', 'Redis', 'RedisCluster', - 'Solr', 'Firestore' ];