diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md
deleted file mode 100644
index ec6a415f4..000000000
--- a/.github/ISSUE_TEMPLATE.md
+++ /dev/null
@@ -1,26 +0,0 @@
-**Configuration**
-- **PhpFastCache version:** "...replace me (Can be retrieved using method `\Phpfastcache\Api::GetVersion()`)..."
-- **PhpFastCache API version:** "...replace me (Can be retrieved using method `\Phpfastcache\Api::getPhpFastCacheVersion()`)..."
-- **PHP version:** "...replace me (Can be retrieved using command line `php -v | sed -n 1p`)..."
-- **Operating system:** " ...replace me (You REALLY should know it)... "
-
-**Describe the bug**
-
-> ... A clear and concise description of what the bug is, goes here ...
-... You can also read the [wiki](https://github.com/PHPSocialNetwork/phpfastcache/wiki) ...
-
-**To Reproduce**
-Steps to reproduce the behavior:
-1. Go to '...'
-2. Click on '....'
-3. Scroll down to '....'
-4. See error
-
-**Expected behavior**
-A clear and concise description of what you expected to happen.
-
-**Screenshots**
-If applicable, add screenshots to help explain your problem.
-
-**Additional context**
-Add any other context about the problem here.
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index 38153d6c9..5a3a82837 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -41,7 +41,7 @@ jobs:
run: ./vendor/bin/phpmd lib/ ansi phpmd.xml
- name: Run PHPSTAN (lite)
- run: ./vendor/bin/phpstan analyse lib/ -l 2 -c phpstan_lite.neon 2>&1
+ run: ./vendor/bin/phpstan analyse lib/ -l 4 -c phpstan_lite.neon 2>&1
- name: Run TESTS
env:
diff --git a/.travis.yml b/.travis.yml
index 34eef7a9a..9eb277ab8 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -37,6 +37,7 @@ before_install:
# - ./bin/ci/scripts/install_arangodb.sh;
- composer install
- composer require phwoolcon/ci-pecl-cacher -n
+ - "./bin/ci/scripts/install_solr.sh || echo \"Solr install failed\""
- "./bin/ci/scripts/install_arangodb.sh || echo \"Arangodb install failed\""
- "./bin/ci/scripts/install_ssdb.sh || echo \"SSDB install failed\""
- "./bin/ci/scripts/install_couchdb.sh || echo \"Couchdb install failed\""
@@ -58,5 +59,5 @@ install:
script:
- ./vendor/bin/phpcs lib/ --report=summary
- ./vendor/bin/phpmd lib/ ansi phpmd.xml
- - "[[ $TRAVIS_PHP_VERSION != \"nightly\" ]] && ./vendor/bin/phpstan analyse lib/ -l 2 -c phpstan.neon 2>&1 || ./vendor/bin/phpstan analyse lib/ -l 2 -c phpstan_lite.neon 2>&1"
+ - "[[ $TRAVIS_PHP_VERSION != \"nightly\" ]] && ./vendor/bin/phpstan analyse lib/ -l 4 -c phpstan.neon 2>&1 || ./vendor/bin/phpstan analyse lib/ -l 4 -c phpstan_lite.neon 2>&1"
- php -f ./bin/ci/run_tests.php
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c1ee6f254..90c53e2f9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,26 @@
+## 9.1.0
+##### 04 april 2022
+- __API__
+ - Upgraded Phpfastcache API to `4.1.0` ([see changes](CHANGELOG_API.md))
+- __Core__
+ - Added `\Phpfastcache\Helper\UninstanciableObjectTrait` trait which will contains base locked constructor for any classes that are nor meant to be instanciated.
+ - Deprecated `\Phpfastcache\Config\Config::class`
+ - Removed/reworked/improved dead/unreachable/redundant/obsolete code, thanks to `Phpstan`
+- __Drivers__
+ - **Added `Solr` driver support**
+- __Events__
+ - Added `\Phpfastcache\Event\EventInterface` for `\Phpfastcache\Event\Event` and subclasses below
+ - Added `\Phpfastcache\Drivers\Arangodb\Event` for Arangodb events
+ - Added `\Phpfastcache\Drivers\Dynamodb\Event` for Dynamodb events
+ - Added `\Phpfastcache\Drivers\Solr\Event` for Solr events
+ - Moved the following constant from `\Phpfastcache\Event\Event` to their respective drivers: `ARANGODB_CONNECTION`, `ARANGODB_COLLECTION_PARAMS`, `DYNAMODB_CREATE_TABLE`
+- __Cluster__
+ - Fixed #855 // ClusterReplication drivers are saving erroneous expiration date in low-level backends
+- __Misc__
+ - Full PSR-12 compliance is now enforced by PHPCS
+ - Multiple typo fixes (@mbiebl)
+ - Updated composer suggestions and CI builder dependencies
+
## 9.0.2
##### 04 march 2022
- __Core__
@@ -27,7 +50,7 @@
- __PSR-16__
- Upgraded `psr/simple-cache` dependency to `^2.0||^3.0` (for PHP-8 types)
- __API__
- - Upgraded Phpfastcache API `4.0.0` ([see changes](CHANGELOG_API.md))
+ - Upgraded Phpfastcache API to `4.0.0` ([see changes](CHANGELOG_API.md))
- Renamed `Api::getPhpFastCacheVersion()` to `Api::getPhpfastcacheVersion()`
- Renamed `Api::getPhpFastCacheChangelog()` to `Api::getPhpfastcacheChangelog()`
- Renamed `Api::getPhpFastCacheGitHeadHash()` to `Api::getPhpfastcacheGitHeadHash()`
diff --git a/CHANGELOG_API.md b/CHANGELOG_API.md
index 688f6ade7..d92af06e4 100644
--- a/CHANGELOG_API.md
+++ b/CHANGELOG_API.md
@@ -1,3 +1,10 @@
+## 4.1.0
+- Created `\Phpfastcache\Event\EventInterface` which will be used for `Phpfastcache\Event\Event` and any `Phpfastcache\Drivers\xxxxxxx\Event` classes
+- Extended `CacheItemPoolInterface::save()` with `ExtendedCacheItemPoolInterface::save()` for re-typing
+- Method `ExtendedCacheItemPoolInterface::getConfig()` now returns `ConfigurationOptionInterface` instead of `ConfigurationOption`
+- Method `ExtendedCacheItemPoolInterface::getDefaultConfig()` now returns `ConfigurationOptionInterface` instead of `ConfigurationOption`
+- Method `EventManagerInterface::getInstance()` now returns `EventManagerInterface` instead of `static`
+
## 4.0.0
- **[BC Break]** Upgraded `psr/cache` dependency to `^3.0` which required `ExtendedCacheItemPoolInterface` and `ExtendedCacheItemInterface` updates
- **[BC Break]** Increased minimum PHP compatibility to `^8.0` which also required `TaggableCacheItemPoolInterface` and `TaggableCacheItemInterface` updates
diff --git a/README.md b/README.md
index 2a869b1f0..62521a479 100644
--- a/README.md
+++ b/README.md
@@ -15,18 +15,18 @@ 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 | Cluster-Aggregated drivers |
-|---------------------------------|---------------------------------------------------------------|-------------------------------|-----------------------------------|
-| `Apcu` *(APC support removed)* | `Arangodb` | `Devnull` | `FullReplicationCluster` |
-| `Dynamodb` (AWS) | `Cassandra` | `Devrandom` | `SemiReplicationCluster` |
-| `Files` | `CouchBasev3`
_(`Couchbase` for SDK 2 support removed)_ | `Memstatic` | `MasterSlaveReplicationCluster` |
-| `Firestore` (GCP) | `Couchdb` | | `RandomReplicationCluster` |
-| `Leveldb` | `Mongodb` | | |
-| `Memcache(d)` | `Predis` | | |
-| `Sqlite` | `Redis` | | |
-| `Wincache` | `Ssdb` | | |
-| `Zend Disk Cache` | `Zend Memory Cache` | | |
-| | | | |
+| Regular drivers | High performances drivers | Development drivers | Cluster-Aggregated drivers |
+|------------------------------------------------------------------------|------------------------------------------------------------|-------------------------------|-----------------------------------|
+| `Apcu` _(APC support removed)_ | `Arangodb` | `Devnull` | `FullReplicationCluster` |
+| `Dynamodb` (AWS) | `Cassandra` | `Devrandom` | `SemiReplicationCluster` |
+| `Files` | `CouchBasev3`
_(`Couchbase` for SDK 2 support removed)_ | `Memstatic` | `MasterSlaveReplicationCluster` |
+| `Firestore` (GCP) | `Couchdb` | | `RandomReplicationCluster` |
+| `Leveldb` | `Mongodb` | | |
+| `Memcache(d)` | `Predis` | | |
+| `Solr` _(Via [Solarium 6.x](https://github.com/solariumphp/solarium))_ | `Redis` | | |
+| `Sqlite` | `Ssdb` | | |
+| `Wincache` | `Zend Memory Cache` | | |
+| `Zend Disk Cache` | | | | | | | |
\* Driver descriptions available in [DOCS/DRIVERS.md](./docs/DRIVERS.md)
@@ -46,82 +46,83 @@ Rich Development API
Phpfastcache provides you a lot of useful APIs:
### Item API (ExtendedCacheItemInterface)
-| Method | Return | Description |
-|--------------------------------------|------------------------------|----------------------------------------------------------------------------------------------------------------------------------------|
-| `addTag($tagName)` | ExtendedCacheItemInterface | Adds a tag |
-| `addTags(array $tagNames)` | ExtendedCacheItemInterface | Adds multiple tags |
-| `append($data)` | ExtendedCacheItemInterface | Appends data to a string or an array (push) |
-| `decrement($step = 1)` | ExtendedCacheItemInterface | Redundant joke... |
-| `expiresAfter($ttl)` | ExtendedCacheItemInterface | Allows you to extends the lifetime of an entry without altering its value (formerly known as touch()) |
-| `expiresAt($expiration)` | ExtendedCacheItemInterface | Sets the expiration time for this cache item (as a DateTimeInterface object) |
-| `get()` | mixed | The getter, obviously, returns your cache object |
-| `getCreationDate()` | \DatetimeInterface | Gets the creation date for this cache item (as a DateTimeInterface object) * |
-| `getDataAsJsonString()` | string | Return the data as a well-formatted json string |
-| `getEncodedKey()` | string | Returns the final and internal item identifier (key), generally used for debug purposes |
-| `getExpirationDate()` | ExtendedCacheItemInterface | Gets the expiration date as a Datetime object |
-| `getKey()` | string | Returns the item identifier (key) |
-| `getLength()` | int | Gets the data length if the data is a string, array, or objects that implement \Countable interface. |
-| `getModificationDate()` | \DatetimeInterface | Gets the modification date for this cache item (as a DateTimeInterface object) * |
-| `getTags()` | string[] | Gets the tags |
-| `getTagsAsString($separator = ', ')` | string | Gets the data as a string separated by $separator |
-| `getTtl()` | int | Gets the remaining Time To Live as an integer |
-| `increment($step = 1)` | ExtendedCacheItemInterface | To allow us to count on an integer item |
-| `isEmpty()` | bool | Checks if the data is empty or not despite the hit/miss status. |
-| `isExpired()` | bool | Checks if your cache entry is expired |
-| `isHit()` | bool | Checks if your cache entry exists and is still valid, it's the equivalent of isset() |
-| `isNull()` | bool | Checks if the data is null or not despite the hit/miss status. |
-| `prepend($data)` | ExtendedCacheItemInterface | Prepends data to a string or an array (unshift) |
-| `removeTag($tagName)` | ExtendedCacheItemInterface | Removes a tag |
-| `removeTags(array $tagNames)` | ExtendedCacheItemInterface | Removes multiple tags |
-| `set($value)` | ExtendedCacheItemInterface | The setter, for those who missed it, can be anything except resources or non-serializer object (ex: PDO objects, file pointers, etc). |
-| `setCreationDate($expiration)` | \DatetimeInterface | Sets the creation date for this cache item (as a DateTimeInterface object) * |
-| `setEventManager($evtMngr)` | ExtendedCacheItemInterface | Sets the event manager |
-| `setExpirationDate()` | ExtendedCacheItemInterface | Alias of expireAt() (for more code logic) |
-| `setModificationDate($expiration)` | \DatetimeInterface | Sets the modification date for this cache item (as a DateTimeInterface object) * |
-| `setTags(array $tags)` | ExtendedCacheItemInterface | Sets multiple tags |
+
+| Method | Return | Description |
+|--------------------------------------|-------------------------------|----------------------------------------------------------------------------------------------------------------------------------------|
+| `addTag($tagName)` | `ExtendedCacheItemInterface` | Adds a tag |
+| `addTags(array $tagNames)` | `ExtendedCacheItemInterface` | Adds multiple tags |
+| `append($data)` | `ExtendedCacheItemInterface` | Appends data to a string or an array (push) |
+| `decrement($step = 1)` | `ExtendedCacheItemInterface` | Redundant joke... |
+| `expiresAfter($ttl)` | `ExtendedCacheItemInterface` | Allows you to extends the lifetime of an entry without altering its value (formerly known as touch()) |
+| `expiresAt($expiration)` | `ExtendedCacheItemInterface` | Sets the expiration time for this cache item (as a DateTimeInterface object) |
+| `get()` | `mixed` | The getter, obviously, returns your cache object |
+| `getCreationDate()` | `\DatetimeInterface` | Gets the creation date for this cache item (as a DateTimeInterface object) * |
+| `getDataAsJsonString()` | `string` | Return the data as a well-formatted json string |
+| `getEncodedKey()` | `string` | Returns the final and internal item identifier (key), generally used for debug purposes |
+| `getExpirationDate()` | `ExtendedCacheItemInterface` | Gets the expiration date as a Datetime object |
+| `getKey()` | `string` | Returns the item identifier (key) |
+| `getLength()` | `int` | Gets the data length if the data is a string, array, or objects that implement `\Countable` interface. |
+| `getModificationDate()` | `\DatetimeInterface` | Gets the modification date for this cache item (as a DateTimeInterface object) * |
+| `getTags()` | `string[]` | Gets the tags |
+| `getTagsAsString($separator = ', ')` | `string` | Gets the data as a string separated by $separator |
+| `getTtl()` | `int` | Gets the remaining Time To Live as an integer |
+| `increment($step = 1)` | `ExtendedCacheItemInterface` | To allow us to count on an integer item |
+| `isEmpty()` | `bool` | Checks if the data is empty or not despite the hit/miss status. |
+| `isExpired()` | `bool` | Checks if your cache entry is expired |
+| `isHit()` | `bool` | Checks if your cache entry exists and is still valid, it's the equivalent of isset() |
+| `isNull()` | `bool` | Checks if the data is null or not despite the hit/miss status. |
+| `prepend($data)` | `ExtendedCacheItemInterface` | Prepends data to a string or an array (unshift) |
+| `removeTag($tagName)` | `ExtendedCacheItemInterface` | Removes a tag |
+| `removeTags(array $tagNames)` | `ExtendedCacheItemInterface` | Removes multiple tags |
+| `set($value)` | `ExtendedCacheItemInterface` | The setter, for those who missed it, can be anything except resources or non-serializer object (ex: PDO objects, file pointers, etc). |
+| `setCreationDate($expiration)` | `\DatetimeInterface` | Sets the creation date for this cache item (as a DateTimeInterface object) * |
+| `setEventManager($evtMngr)` | `ExtendedCacheItemInterface` | Sets the event manager |
+| `setExpirationDate()` | `ExtendedCacheItemInterface` | Alias of expireAt() (for more code logic) |
+| `setModificationDate($expiration)` | `\DatetimeInterface` | Sets the modification date for this cache item (as a DateTimeInterface object) * |
+| `setTags(array $tags)` | `ExtendedCacheItemInterface` | Sets multiple tags |
\* Require configuration directive "itemDetailedDate" to be enabled, else a \LogicException will be thrown
### ItemPool API (ExtendedCacheItemPoolInterface)
-| Methods (By Alphabetic Order) | Return | Description |
-|-----------------------------------------------------------------|--------------------------------|--------------------------------------------------------------------------------------------------|
-| `appendItemsByTag($tagName, $data)` | bool | Appends items by a tag |
-| `appendItemsByTags(array $tagNames, $data)` | bool | Appends items by one of multiple tag names |
-| `attachItem($item)` | void | (Re-)attaches an item to the pool |
-| `clear()` | bool | Allows you to completely empty the cache and restart from the beginning |
-| `commit()` | bool | Persists any deferred cache items |
-| `decrementItemsByTag($tagName, $step = 1)` | bool | Decrements items by a tag |
-| `decrementItemsByTags(array $tagNames, $step = 1)` | bool | Decrements items by one of multiple tag names |
-| `deleteItem($key)` | bool | Deletes an item |
-| `deleteItems(array $keys)` | bool | Deletes one or more items |
-| `deleteItemsByTag($tagName)` | bool | Deletes items by a tag |
-| `deleteItemsByTags(array $tagNames, int $strategy)` | bool | Deletes items by one of multiple tag names |
-| `detachItem($item)` | void | Detaches an item from the pool |
-| `getConfig()` | ConfigurationOption | Returns the configuration object |
-| `getConfigOption($optionName);` | mixed | Returns a configuration value by its key `$optionName` |
-| `getDefaultConfig()` | ConfigurationOption | Returns the default configuration object (not altered by the object instance) |
-| `getDriverName()` | string | Returns the current driver name (without the namespace) |
-| `getEventManager()` | EventManagerInterface | Gets the event manager |
-| `getHelp()` | string | Provides a very basic help for a specific driver |
-| `getInstanceId()` | string | Returns the instance ID |
-| `getItem($key)` | ExtendedCacheItemInterface | Retrieves an item and returns an empty item if not found |
-| `getItems(array $keys)` | ExtendedCacheItemInterface[] | Retrieves one or more item and returns an array of items |
-| `getItemsAsJsonString(array $keys)` | string | Returns A json string that represents an array of items |
-| `getItemsByTag($tagName, $strategy)` | ExtendedCacheItemInterface[] | Returns items by a tag |
-| `getItemsByTags(array $tagNames, $strategy)` | ExtendedCacheItemInterface[] | Returns items by one of multiple tag names |
-| `getItemsByTagsAsJsonString(array $tagNames, $strategy)` | string | Returns A json string that represents an array of items corresponding |
-| `getStats()` | DriverStatistic | Returns the cache statistics as an object, useful for checking disk space used by the cache etc. |
-| `hasEventManager()` | bool | Check the event manager |
-| `hasItem($key)` | bool | Tests if an item exists |
-| `incrementItemsByTag($tagName, $step = 1, $strategy)` | bool | Increments items by a tag |
-| `incrementItemsByTags(array $tagNames, $step = 1, $strategy)` | bool | Increments items by one of multiple tag names |
-| `isAttached($item)` | bool | Verify if an item is (still) attached |
-| `prependItemsByTag($tagName, $data, $strategy)` | bool | Prepends items by a tag |
-| `prependItemsByTags(array $tagNames, $data, $strategy)` | bool | Prepends items by one of multiple tag names |
-| `save(CacheItemInterface $item)` | bool | Persists a cache item immediately |
-| `saveDeferred(CacheItemInterface $item)` | bool | Sets a cache item to be persisted later |
-| `saveMultiple(...$items)` | bool | Persists multiple cache items immediately |
-| `setEventManager(EventManagerInterface $evtMngr)` | ExtendedCacheItemPoolInterface | Sets the event manager |
+| Methods (By Alphabetic Order) | Return | Description |
+|-----------------------------------------------------------------|-----------------------------------|--------------------------------------------------------------------------------------------------|
+| `appendItemsByTag($tagName, $data)` | `bool` | Appends items by a tag |
+| `appendItemsByTags(array $tagNames, $data)` | `bool` | Appends items by one of multiple tag names |
+| `attachItem($item)` | `void` | (Re-)attaches an item to the pool |
+| `clear()` | `bool` | Allows you to completely empty the cache and restart from the beginning |
+| `commit()` | `bool` | Persists any deferred cache items |
+| `decrementItemsByTag($tagName, $step = 1)` | `bool` | Decrements items by a tag |
+| `decrementItemsByTags(array $tagNames, $step = 1)` | `bool` | Decrements items by one of multiple tag names |
+| `deleteItem($key)` | `bool` | Deletes an item |
+| `deleteItems(array $keys)` | `bool` | Deletes one or more items |
+| `deleteItemsByTag($tagName)` | `bool` | Deletes items by a tag |
+| `deleteItemsByTags(array $tagNames, int $strategy)` | `bool` | Deletes items by one of multiple tag names |
+| `detachItem($item)` | `void` | Detaches an item from the pool |
+| `getConfig()` | `ConfigurationOption` | Returns the configuration object |
+| `getConfigOption($optionName);` | `mixed` | Returns a configuration value by its key `$optionName` |
+| `getDefaultConfig()` | `ConfigurationOption` | Returns the default configuration object (not altered by the object instance) |
+| `getDriverName()` | `string` | Returns the current driver name (without the namespace) |
+| `getEventManager()` | `EventManagerInterface` | Gets the event manager |
+| `getHelp()` | `string` | Provides a very basic help for a specific driver |
+| `getInstanceId()` | `string` | Returns the instance ID |
+| `getItem($key)` | `ExtendedCacheItemInterface` | Retrieves an item and returns an empty item if not found |
+| `getItems(array $keys)` | `ExtendedCacheItemInterface[]` | Retrieves one or more item and returns an array of items |
+| `getItemsAsJsonString(array $keys)` | `string` | Returns A json string that represents an array of items |
+| `getItemsByTag($tagName, $strategy)` | `ExtendedCacheItemInterface[]` | Returns items by a tag |
+| `getItemsByTags(array $tagNames, $strategy)` | `ExtendedCacheItemInterface[]` | Returns items by one of multiple tag names |
+| `getItemsByTagsAsJsonString(array $tagNames, $strategy)` | `string` | Returns A json string that represents an array of items corresponding |
+| `getStats()` | `DriverStatistic` | Returns the cache statistics as an object, useful for checking disk space used by the cache etc. |
+| `hasEventManager()` | `bool` | Check the event manager |
+| `hasItem($key)` | `bool` | Tests if an item exists |
+| `incrementItemsByTag($tagName, $step = 1, $strategy)` | `bool` | Increments items by a tag |
+| `incrementItemsByTags(array $tagNames, $step = 1, $strategy)` | `bool` | Increments items by one of multiple tag names |
+| `isAttached($item)` | `bool` | Verify if an item is (still) attached |
+| `prependItemsByTag($tagName, $data, $strategy)` | `bool` | Prepends items by a tag |
+| `prependItemsByTags(array $tagNames, $data, $strategy)` | `bool` | Prepends items by one of multiple tag names |
+| `save(CacheItemInterface $item)` | `bool` | Persists a cache item immediately |
+| `saveDeferred(CacheItemInterface $item)` | `bool` | Sets a cache item to be persisted later |
+| `saveMultiple(...$items)` | `bool` | Persists multiple cache items immediately |
+| `setEventManager(EventManagerInterface $evtMngr)` | `ExtendedCacheItemPoolInterface` | Sets the event manager |
:new: in **V8**: Multiple strategies (`$strategy`) are now supported for tagging:
- `TaggableCacheItemPoolInterface::TAG_STRATEGY_ONE` allows you to get cache item(s) by at least **ONE** of the specified matching tag(s). **Default behavior.**
diff --git a/bin/ci/scripts/install_couchdb.sh b/bin/ci/scripts/install_couchdb.sh
index 56c9562e9..6a5e108b0 100755
--- a/bin/ci/scripts/install_couchdb.sh
+++ b/bin/ci/scripts/install_couchdb.sh
@@ -10,7 +10,7 @@ echo "# Running Docker couchdb image"
docker run -d -p $COUCHDB_PORT:$COUCHDB_PORT couchdb:$COUCHDB_VERSION --with-haproxy --with-admin-party-please -n 1
check_db() {
- # Allow 4xx errors not to break the connexion check
+ # Allow 4xx errors not to break the connection check
curl --silent http://$COUCHDB_HOST:$COUCHDB_PORT > /dev/null
echo $?
}
diff --git a/bin/ci/scripts/install_dependencies.sh b/bin/ci/scripts/install_dependencies.sh
index 3a1f31cfc..f3e97caaa 100755
--- a/bin/ci/scripts/install_dependencies.sh
+++ b/bin/ci/scripts/install_dependencies.sh
@@ -3,4 +3,7 @@
composer self-update
composer validate
composer install
-composer require -W doctrine/couchdb:dev-master phpfastcache/phpssdb:~1.1.0 predis/predis:~1.1.0 mongodb/mongodb:^1.9 triagens/arangodb:^3.8 aws/aws-sdk-php:~3.0 google/cloud-firestore:^1.20
+#####
+# 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 doctrine/couchdb:dev-master phpfastcache/phpssdb:~1.1 predis/predis:~1.1 mongodb/mongodb:~1.9 triagens/arangodb:~3.8 aws/aws-sdk-php:~3.2 google/cloud-firestore:~1.20 solarium/solarium:~6.1
diff --git a/bin/ci/scripts/install_solr.sh b/bin/ci/scripts/install_solr.sh
new file mode 100755
index 000000000..9ac16b044
--- /dev/null
+++ b/bin/ci/scripts/install_solr.sh
@@ -0,0 +1,55 @@
+#!/bin/bash
+
+set -e
+
+export SOLR_PORT=8983
+export SOLR_HOST=127.0.0.1
+export SOLR_VERSION=8.11.1
+export SOLR_CORE=phpfastcache
+
+download() {
+ FILE="$2.tgz"
+ if [ -f $FILE ];
+ then
+ echo "File $FILE exists."
+ tar -zxf $FILE
+ else
+ echo "File $FILE does not exist. Downloading solr from $1..."
+ curl -O $1
+ tar -zxf $FILE
+ fi
+ echo "Downloaded!"
+}
+
+is_solr_up(){
+ echo "Checking if solr is up on http://localhost:$SOLR_PORT/solr/admin/cores"
+ http_code=`echo $(curl -s -o /dev/null -w "%{http_code}" "http://localhost:$SOLR_PORT/solr/admin/cores")`
+ return `test $http_code = "200"`
+}
+
+wait_for_solr(){
+ while ! is_solr_up; do
+ sleep 3
+ done
+}
+
+run_solr() {
+ dir_name=$1
+ ./$dir_name/bin/solr -p $SOLR_PORT -h $SOLR_HOST
+ wait_for_solr
+ ./$dir_name/bin/solr create_core -c $SOLR_CORE -p $SOLR_PORT
+ echo "Started"
+}
+
+download_and_run() {
+ version=$1
+ url="http://archive.apache.org/dist/lucene/solr/${version}/solr-${version}.tgz"
+ dir_name="solr-${version}"
+ download $url $dir_name
+
+ run_solr $dir_name
+}
+
+
+
+download_and_run $SOLR_VERSION
diff --git a/composer.json b/composer.json
index d1bf11eef..81fd2b013 100644
--- a/composer.json
+++ b/composer.json
@@ -2,7 +2,7 @@
"name": "phpfastcache/phpfastcache",
"type" : "library",
"description": "PHP Abstract Cache Class - Reduce your database call using cache system. Phpfastcache handles a lot of drivers such as Apc(u), Cassandra, CouchBase, Couchdb, Mongodb, Files, (P)redis, Leveldb, Memcache(d), Ssdb, Sqlite, Wincache, Xcache, Zend Data Cache.",
- "keywords": ["abstract", "cache","caching","php cache","mysql cache","apc","apcu","arangodb","dynamodb","memcache","memcached","wincache","files cache","pdo cache","cache class","redis","predis","cookie", "mongodb", "cassandra", "couchdb", "couchbase", "LevelDb", "Ssdb", "Wincache", "xcache","zend","zend disk cache","zend memory cache","zend data cache","zend server"],
+ "keywords": ["abstract", "cache","caching","php cache","mysql cache","apc","apcu","arangodb","dynamodb","memcache","memcached","wincache","files cache","pdo cache","cache class","redis","predis","cookie", "mongodb", "cassandra", "couchdb", "couchbase", "LevelDb", "Solr", "Ssdb", "Wincache", "xcache","zend","zend disk cache","zend memory cache","zend data cache","zend server"],
"homepage": "https://www.phpfastcache.com",
"license": "MIT",
"minimum-stability": "stable",
@@ -26,17 +26,18 @@
"ext-json": "*"
},
"require-dev": {
- "league/climate": "^3.5",
+ "league/climate": "^3.8",
"ext-gettext": "*",
"phpmd/phpmd": "@stable",
- "squizlabs/php_codesniffer": "~3.0",
- "phpstan/phpstan": "^0.12.98",
+ "squizlabs/php_codesniffer": "@stable",
+ "phpstan/phpstan": "^1.5",
"jetbrains/phpstorm-stubs": "dev-master"
},
"suggest": {
"ext-apcu": "*",
"ext-intl": "*",
"ext-memcached": "*",
+ "ext-cassandra": "*",
"ext-memcache": "*",
"ext-mongodb": "*",
"ext-redis": "*",
@@ -49,13 +50,15 @@
"predis/predis": "^1.1",
"mongodb/mongodb": "^1.9",
"phpfastcache/phpssdb": "~1.1.0",
+ "solarium/solarium": "~6.1",
"doctrine/couchdb": "^dev-master#9eeb9e5",
"triagens/arangodb": "^3.8",
"google/cloud-firestore": "^1.20",
"aws/aws-sdk-php": "~3.0"
},
"conflict": {
- "doctrine/couchdb": "getItem(array());
}catch(\InvalidArgumentException $e){
- //Catched exception code
+ //Caught exception code
}
```
@@ -140,7 +140,7 @@ $instance = CacheManager::getInstance('Files');
try{
$item = $instance->getItem(array());
}catch(\phpFastCache\Exceptions\phpFastCacheInvalidArgumentException $e){
- //Catched exception code
+ //Caught exception code
}
```
@@ -159,7 +159,7 @@ $instance = CacheManager::getInstance('Files');
try{
$item = $instance->getItem(array());
}catch(\LogicException $e){
- //Catched exception code
+ //Caught exception code
}
```
@@ -175,7 +175,7 @@ $instance = CacheManager::getInstance('Files');
try{
$item = $instance->getItem(array());
}catch(\phpFastCache\Exceptions\phpFastCacheLogicException $e){
- //Catched exception code
+ //Caught exception code
}
```
diff --git a/docs/migration/MigratingFromV6ToV7.md b/docs/migration/MigratingFromV6ToV7.md
index 97992b12b..333d3ac69 100644
--- a/docs/migration/MigratingFromV6ToV7.md
+++ b/docs/migration/MigratingFromV6ToV7.md
@@ -107,7 +107,7 @@ $cacheInstace = CacheManager::getInstance('Files', new Config([
```
#### For non-global option you MUST use the specific Config object provided for each drivers
```php
-// The recommanded way is to use an alias to not confuse yourself
+// The recommended way is to use an alias to not confuse yourself
use Phpfastcache\Drivers\Files\Config as FilesConfig;
$config = new FilesConfig();
diff --git a/lib/Phpfastcache/Api.php b/lib/Phpfastcache/Api.php
index 19342bf26..49e56094a 100644
--- a/lib/Phpfastcache/Api.php
+++ b/lib/Phpfastcache/Api.php
@@ -11,28 +11,24 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache;
use Phpfastcache\Exceptions\PhpfastcacheIOException;
use Phpfastcache\Exceptions\PhpfastcacheLogicException;
+use Phpfastcache\Helper\UninstanciableObjectTrait;
/**
* Class Api
- * @package phpFastCache
+ * @package Phpfastcache
*/
class Api
{
- protected static string $version = '4.0.0';
+ use UninstanciableObjectTrait;
- /**
- * Api constructor.
- */
- final protected function __construct()
- {
- // The Api is not meant to be instantiated
- }
+ protected static string $version = '4.1.0';
/**
* This method will return the current
diff --git a/lib/Phpfastcache/CacheContract.php b/lib/Phpfastcache/CacheContract.php
index 57eee9e0c..f9672e397 100644
--- a/lib/Phpfastcache/CacheContract.php
+++ b/lib/Phpfastcache/CacheContract.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache;
diff --git a/lib/Phpfastcache/CacheManager.php b/lib/Phpfastcache/CacheManager.php
index 67e87322a..d936e4136 100644
--- a/lib/Phpfastcache/CacheManager.php
+++ b/lib/Phpfastcache/CacheManager.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache;
@@ -25,13 +26,18 @@
use Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException;
use Phpfastcache\Exceptions\PhpfastcacheLogicException;
use Phpfastcache\Exceptions\PhpfastcacheUnsupportedOperationException;
+use Phpfastcache\Helper\UninstanciableObjectTrait;
use Phpfastcache\Util\ClassNamespaceResolverTrait;
+/**
+ * @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
+ */
class CacheManager
{
- public const CORE_DRIVER_NAMESPACE = 'Phpfastcache\Drivers\\';
-
use ClassNamespaceResolverTrait;
+ use UninstanciableObjectTrait;
+
+ public const CORE_DRIVER_NAMESPACE = 'Phpfastcache\Drivers\\';
protected static ConfigurationOptionInterface $config;
@@ -52,14 +58,6 @@ class CacheManager
*/
protected static array $driverCustoms = [];
- /**
- * CacheManager constructor.
- */
- final protected function __construct()
- {
- // The cache manager is not meant to be instantiated
- }
-
/**
* @param string $instanceId
* @return ExtendedCacheItemPoolInterface
@@ -96,16 +94,18 @@ public static function getInstances(): array
*/
public static function getInstance(string $driver, ?ConfigurationOptionInterface $config = null, ?string $instanceId = null): ExtendedCacheItemPoolInterface
{
+ if (\class_exists($driver) && \str_starts_with($driver, 'Phpfastcache')) {
+ $driverClass = $driver;
+ } else {
+ $driver = self::normalizeDriverName($driver);
+ $driverClass = self::validateDriverClass(self::getDriverClass($driver));
+ }
$config = self::validateConfig($config);
- $driver = self::standardizeDriverName($driver);
- $instanceId = $instanceId ?: md5($driver . \serialize(\array_filter($config->toArray(), static fn ($val) => !\is_callable($val))));
+ $instanceId = $instanceId ?: self::getInstanceHash($driverClass, $config);
if (!isset(self::$instances[$instanceId])) {
- $driverClass = self::validateDriverClass(self::getDriverClass($driver));
-
- if (\class_exists($driverClass)) {
- $configClass = $driverClass::getConfigClass();
- if ($configClass !== $config::class) {
+ if (\is_a($driverClass, ExtendedCacheItemPoolInterface::class, true)) {
+ if (($configClass = $driverClass::getConfigClass()) !== $config::class) {
$config = new $configClass($config->toArray());
}
self::$instances[$instanceId] = new $driverClass(
@@ -114,13 +114,32 @@ public static function getInstance(string $driver, ?ConfigurationOptionInterface
EventManager::getInstance()
);
} else {
- throw new PhpfastcacheDriverNotFoundException(sprintf('The driver "%s" does not exists', $driver));
+ throw new PhpfastcacheDriverNotFoundException(sprintf(
+ 'The driver "%s" does not exist or does not implement %s',
+ $driver,
+ ExtendedCacheItemPoolInterface::class
+ ));
}
}
return self::$instances[$instanceId];
}
+ /**
+ * @param string $driverClass
+ * @param ConfigurationOptionInterface $config
+ * @return string
+ */
+ protected static function getInstanceHash(string $driverClass, ConfigurationOptionInterface $config): string
+ {
+ return \md5($driverClass . \serialize(
+ \array_filter(
+ $config->toArray(),
+ static fn ($val) => $config->isValueSerializable($val)
+ )
+ ));
+ }
+
/**
* @param ConfigurationOptionInterface|null $config
* @return ConfigurationOptionInterface
@@ -146,7 +165,7 @@ public static function getDefaultConfig(): ConfigurationOptionInterface
* @param string $driverName
* @return string
*/
- public static function standardizeDriverName(string $driverName): string
+ public static function normalizeDriverName(string $driverName): string
{
return \ucfirst(\strtolower(\trim($driverName)));
}
@@ -245,7 +264,7 @@ static function (ExtendedCacheItemPoolInterface $cachePool) use ($cachePoolInsta
*/
public static function setDefaultConfig(ConfigurationOptionInterface $config): void
{
- if (is_subclass_of($config, ConfigurationOption::class)) {
+ if (\is_subclass_of($config, ConfigurationOption::class)) {
throw new PhpfastcacheInvalidArgumentException('Default configuration cannot be a child class of ConfigurationOption::class');
}
self::$config = $config;
@@ -261,7 +280,7 @@ public static function setDefaultConfig(ConfigurationOptionInterface $config): v
*/
public static function addCustomDriver(string $driverName, string $className): void
{
- $driverName = self::standardizeDriverName($driverName);
+ $driverName = self::normalizeDriverName($driverName);
if (empty($driverName)) {
throw new PhpfastcacheInvalidArgumentException("Can't add a custom driver because its name is empty");
@@ -269,7 +288,7 @@ public static function addCustomDriver(string $driverName, string $className): v
if (!\class_exists($className)) {
throw new PhpfastcacheInvalidArgumentException(
- \sprintf("Can't add '%s' because the class '%s' does not exists", $driverName, $className)
+ \sprintf("Can't add '%s' because the class '%s' does not exist", $driverName, $className)
);
}
@@ -335,14 +354,14 @@ public static function getDriverList(bool $fqcnAsKey = false): array
*/
public static function removeCustomDriver(string $driverName): void
{
- $driverName = self::standardizeDriverName($driverName);
+ $driverName = self::normalizeDriverName($driverName);
if (empty($driverName)) {
throw new PhpfastcacheInvalidArgumentException("Can't remove a custom driver because its name is empty");
}
if (!isset(self::$driverCustoms[$driverName])) {
- throw new PhpfastcacheLogicException(\sprintf("Driver '%s' does not exists", $driverName));
+ throw new PhpfastcacheLogicException(\sprintf("Driver '%s' does not exist", $driverName));
}
unset(self::$driverCustoms[$driverName]);
@@ -358,7 +377,7 @@ public static function removeCustomDriver(string $driverName): void
*/
public static function addCoreDriverOverride(string $driverName, string $className): void
{
- $driverName = self::standardizeDriverName($driverName);
+ $driverName = self::normalizeDriverName($driverName);
if (empty($driverName)) {
throw new PhpfastcacheInvalidArgumentException("Can't add a core driver override because its name is empty");
@@ -366,7 +385,7 @@ public static function addCoreDriverOverride(string $driverName, string $classNa
if (!\class_exists($className)) {
throw new PhpfastcacheInvalidArgumentException(
- \sprintf("Can't override '%s' because the class '%s' does not exists", $driverName, $className)
+ \sprintf("Can't override '%s' because the class '%s' does not exist", $driverName, $className)
);
}
@@ -400,7 +419,7 @@ public static function addCoreDriverOverride(string $driverName, string $classNa
*/
public static function removeCoreDriverOverride(string $driverName): void
{
- $driverName = self::standardizeDriverName($driverName);
+ $driverName = self::normalizeDriverName($driverName);
if (empty($driverName)) {
throw new PhpfastcacheInvalidArgumentException("Can't remove a core driver override because its name is empty");
diff --git a/lib/Phpfastcache/Cluster/AggregatablePoolInterface.php b/lib/Phpfastcache/Cluster/AggregatablePoolInterface.php
index f8ca23340..a83e101a8 100644
--- a/lib/Phpfastcache/Cluster/AggregatablePoolInterface.php
+++ b/lib/Phpfastcache/Cluster/AggregatablePoolInterface.php
@@ -2,7 +2,7 @@
/**
*
- * This file is part of phpFastCache.
+ * This file is part of Phpfastcache.
*
* @license MIT License (MIT)
*
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
*
*/
+
declare(strict_types=1);
namespace Phpfastcache\Cluster;
@@ -19,5 +20,4 @@
interface AggregatablePoolInterface extends CacheItemPoolInterface
{
-
}
diff --git a/lib/Phpfastcache/Cluster/AggregatorInterface.php b/lib/Phpfastcache/Cluster/AggregatorInterface.php
index 785235db9..0e7550bef 100644
--- a/lib/Phpfastcache/Cluster/AggregatorInterface.php
+++ b/lib/Phpfastcache/Cluster/AggregatorInterface.php
@@ -2,7 +2,7 @@
/**
*
- * This file is part of phpFastCache.
+ * This file is part of Phpfastcache.
*
* @license MIT License (MIT)
*
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
*
*/
+
declare(strict_types=1);
namespace Phpfastcache\Cluster;
@@ -19,7 +20,6 @@
interface AggregatorInterface
{
-
/**
* Full replication mechanism
*
diff --git a/lib/Phpfastcache/Cluster/ClusterAggregator.php b/lib/Phpfastcache/Cluster/ClusterAggregator.php
index ba98ed4a5..f24801944 100644
--- a/lib/Phpfastcache/Cluster/ClusterAggregator.php
+++ b/lib/Phpfastcache/Cluster/ClusterAggregator.php
@@ -2,7 +2,7 @@
/**
*
- * This file is part of phpFastCache.
+ * This file is part of Phpfastcache.
*
* @license MIT License (MIT)
*
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
*
*/
+
declare(strict_types=1);
namespace Phpfastcache\Cluster;
diff --git a/lib/Phpfastcache/Cluster/ClusterPoolAbstract.php b/lib/Phpfastcache/Cluster/ClusterPoolAbstract.php
index 48e5be4d7..7f7379ebf 100644
--- a/lib/Phpfastcache/Cluster/ClusterPoolAbstract.php
+++ b/lib/Phpfastcache/Cluster/ClusterPoolAbstract.php
@@ -2,7 +2,7 @@
/**
*
- * This file is part of phpFastCache.
+ * This file is part of Phpfastcache.
*
* @license MIT License (MIT)
*
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
*
*/
+
declare(strict_types=1);
namespace Phpfastcache\Cluster;
@@ -37,9 +38,6 @@
use Psr\Cache\CacheItemInterface;
use Psr\Cache\InvalidArgumentException;
-/**
- * @property ConfigurationOption $config
- */
abstract class ClusterPoolAbstract implements ClusterPoolInterface
{
use TaggableCacheItemPoolTrait;
@@ -106,7 +104,7 @@ public function getClusterPools(): array
/**
* @inheritDoc
*/
- public function getConfigs() : array
+ public function getConfigs(): array
{
$configs = [];
@@ -184,7 +182,7 @@ protected function getStandardizedItem(ExtendedCacheItemInterface $item, Extende
*/
if ($driverPool === $this) {
/** @var ExtendedCacheItemInterface $itemPool */
- $itemClass = $driverPool->getItemClass();
+ $itemClass = $driverPool::getItemClass();
$itemPool = new $itemClass($this, $item->getKey(), $this->getEventManager());
$item->cloneInto($itemPool, $driverPool);
@@ -241,9 +239,4 @@ public function getStats(): DriverStatistic
return $stats;
}
-
- public function getConfig() : ConfigurationOption
- {
- return $this->config;
- }
}
diff --git a/lib/Phpfastcache/Cluster/ClusterPoolInterface.php b/lib/Phpfastcache/Cluster/ClusterPoolInterface.php
index a91843404..f5a82d109 100644
--- a/lib/Phpfastcache/Cluster/ClusterPoolInterface.php
+++ b/lib/Phpfastcache/Cluster/ClusterPoolInterface.php
@@ -2,7 +2,7 @@
/**
*
- * This file is part of phpFastCache.
+ * This file is part of Phpfastcache.
*
* @license MIT License (MIT)
*
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
*
*/
+
declare(strict_types=1);
namespace Phpfastcache\Cluster;
diff --git a/lib/Phpfastcache/Cluster/ClusterPoolTrait.php b/lib/Phpfastcache/Cluster/ClusterPoolTrait.php
index 9e29ed243..28c2958bb 100644
--- a/lib/Phpfastcache/Cluster/ClusterPoolTrait.php
+++ b/lib/Phpfastcache/Cluster/ClusterPoolTrait.php
@@ -2,7 +2,7 @@
/**
*
- * This file is part of phpFastCache.
+ * This file is part of Phpfastcache.
*
* @license MIT License (MIT)
*
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
*
*/
+
declare(strict_types=1);
namespace Phpfastcache\Cluster;
@@ -20,7 +21,6 @@
trait ClusterPoolTrait
{
-
protected function driverCheck(): bool
{
return true;
diff --git a/lib/Phpfastcache/Cluster/Drivers/FullReplication/Driver.php b/lib/Phpfastcache/Cluster/Drivers/FullReplication/Driver.php
index 8528031c4..1d61d3b21 100644
--- a/lib/Phpfastcache/Cluster/Drivers/FullReplication/Driver.php
+++ b/lib/Phpfastcache/Cluster/Drivers/FullReplication/Driver.php
@@ -2,7 +2,7 @@
/**
*
- * This file is part of phpFastCache.
+ * This file is part of Phpfastcache.
*
* @license MIT License (MIT)
*
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
*
*/
+
declare(strict_types=1);
namespace Phpfastcache\Cluster\Drivers\FullReplication;
@@ -30,7 +31,7 @@ public function getItem(string $key): ExtendedCacheItemInterface
{
/** @var ExtendedCacheItemPoolInterface[] $poolsToResync */
$poolsToResync = [];
- /** @var ExtendedCacheItemInterface $item */
+ /** @var ?ExtendedCacheItemInterface $item */
$item = null;
foreach ($this->clusterPools as $driverPool) {
@@ -44,7 +45,8 @@ public function getItem(string $key): ExtendedCacheItemInterface
$itemData = $item->get();
$poolItemData = $poolItem->get();
- if (\is_object($itemData)
+ if (
+ \is_object($itemData)
) {
if ($item->get() != $poolItemData) {
$poolsToResync[] = $driverPool;
@@ -72,7 +74,12 @@ public function getItem(string $key): ExtendedCacheItemInterface
}
}
- return $this->getStandardizedItem($item ?? new Item($this, $key, $this->getEventManager()), $this);
+ if ($item === null) {
+ $item = new Item($this, $key, $this->getEventManager());
+ $item->expiresAfter((int) abs($this->getConfig()->getDefaultTtl()));
+ }
+
+ return $this->getStandardizedItem($item, $this);
}
/**
diff --git a/lib/Phpfastcache/Cluster/Drivers/FullReplication/Item.php b/lib/Phpfastcache/Cluster/Drivers/FullReplication/Item.php
index d1bc9e911..1a5c3498e 100644
--- a/lib/Phpfastcache/Cluster/Drivers/FullReplication/Item.php
+++ b/lib/Phpfastcache/Cluster/Drivers/FullReplication/Item.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Cluster\Drivers\FullReplication;
diff --git a/lib/Phpfastcache/Cluster/Drivers/MasterSlaveReplication/Driver.php b/lib/Phpfastcache/Cluster/Drivers/MasterSlaveReplication/Driver.php
index 1a3be9325..fda9985ca 100644
--- a/lib/Phpfastcache/Cluster/Drivers/MasterSlaveReplication/Driver.php
+++ b/lib/Phpfastcache/Cluster/Drivers/MasterSlaveReplication/Driver.php
@@ -2,7 +2,7 @@
/**
*
- * This file is part of phpFastCache.
+ * This file is part of Phpfastcache.
*
* @license MIT License (MIT)
*
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
*
*/
+
declare(strict_types=1);
namespace Phpfastcache\Cluster\Drivers\MasterSlaveReplication;
@@ -26,11 +27,9 @@
use Phpfastcache\Exceptions\PhpfastcacheDriverException;
use Phpfastcache\Exceptions\PhpfastcacheExceptionInterface;
use Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException;
-use Phpfastcache\Exceptions\PhpfastcacheInvalidConfigurationException;
use Phpfastcache\Exceptions\PhpfastcacheIOException;
use Phpfastcache\Exceptions\PhpfastcacheReplicationException;
use Psr\Cache\CacheItemInterface;
-use ReflectionException;
class Driver extends ClusterPoolAbstract
{
@@ -61,7 +60,9 @@ public function __construct(string $clusterName, EventManager $em, ExtendedCache
public function getItem(string $key): ExtendedCacheItemInterface
{
return $this->getStandardizedItem(
- $this->makeOperation(static fn (ExtendedCacheItemPoolInterface $pool) => $pool->getItem($key)) ?? new Item($this, $key, $this->getEventManager()),
+ $this->makeOperation(static function (ExtendedCacheItemPoolInterface $pool) use ($key) {
+ return $pool->getItem($key);
+ }) ?? (new Item($this, $key, $this->getEventManager()))->expiresAfter((int) abs($this->getConfig()->getDefaultTtl())),
$this
);
}
diff --git a/lib/Phpfastcache/Cluster/Drivers/MasterSlaveReplication/Item.php b/lib/Phpfastcache/Cluster/Drivers/MasterSlaveReplication/Item.php
index 751d0ef20..1c4174a61 100644
--- a/lib/Phpfastcache/Cluster/Drivers/MasterSlaveReplication/Item.php
+++ b/lib/Phpfastcache/Cluster/Drivers/MasterSlaveReplication/Item.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Cluster\Drivers\MasterSlaveReplication;
diff --git a/lib/Phpfastcache/Cluster/Drivers/RandomReplication/Driver.php b/lib/Phpfastcache/Cluster/Drivers/RandomReplication/Driver.php
index b70be4555..3b03e658a 100644
--- a/lib/Phpfastcache/Cluster/Drivers/RandomReplication/Driver.php
+++ b/lib/Phpfastcache/Cluster/Drivers/RandomReplication/Driver.php
@@ -2,7 +2,7 @@
/**
*
- * This file is part of phpFastCache.
+ * This file is part of Phpfastcache.
*
* @license MIT License (MIT)
*
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
*
*/
+
declare(strict_types=1);
namespace Phpfastcache\Cluster\Drivers\RandomReplication;
@@ -27,6 +28,7 @@ class Driver extends MasterSlaveReplicationDriver
/**
* RandomReplicationCluster constructor.
* @param string $clusterName
+ * @param EventManagerInterface $em
* @param ExtendedCacheItemPoolInterface ...$driverPools
* @throws ReflectionException
*/
diff --git a/lib/Phpfastcache/Cluster/Drivers/RandomReplication/Item.php b/lib/Phpfastcache/Cluster/Drivers/RandomReplication/Item.php
index ff8aa0614..bcc17a829 100644
--- a/lib/Phpfastcache/Cluster/Drivers/RandomReplication/Item.php
+++ b/lib/Phpfastcache/Cluster/Drivers/RandomReplication/Item.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Cluster\Drivers\RandomReplication;
diff --git a/lib/Phpfastcache/Cluster/Drivers/SemiReplication/Driver.php b/lib/Phpfastcache/Cluster/Drivers/SemiReplication/Driver.php
index edc8058f2..7ca6dec01 100644
--- a/lib/Phpfastcache/Cluster/Drivers/SemiReplication/Driver.php
+++ b/lib/Phpfastcache/Cluster/Drivers/SemiReplication/Driver.php
@@ -2,7 +2,7 @@
/**
*
- * This file is part of phpFastCache.
+ * This file is part of Phpfastcache.
*
* @license MIT License (MIT)
*
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
*
*/
+
declare(strict_types=1);
namespace Phpfastcache\Cluster\Drivers\SemiReplication;
@@ -26,12 +27,12 @@ class Driver extends ClusterPoolAbstract
{
/**
* @inheritDoc
- * @throws PhpfastcacheReplicationException
* @throws InvalidArgumentException
+ * @throws PhpfastcacheReplicationException
*/
public function getItem(string $key): ExtendedCacheItemInterface
{
- /** @var ExtendedCacheItemInterface $item */
+ /** @var ?ExtendedCacheItemInterface $item */
$item = null;
$eCount = 0;
@@ -51,7 +52,12 @@ public function getItem(string $key): ExtendedCacheItemInterface
throw new PhpfastcacheReplicationException('Every pools thrown an exception');
}
- return $this->getStandardizedItem($item ?? new Item($this, $key, $this->getEventManager()), $this);
+ if ($item === null) {
+ $item = new Item($this, $key, $this->getEventManager());
+ $item->expiresAfter((int) abs($this->getConfig()->getDefaultTtl()));
+ }
+
+ return $this->getStandardizedItem($item, $this);
}
/**
diff --git a/lib/Phpfastcache/Cluster/Drivers/SemiReplication/Item.php b/lib/Phpfastcache/Cluster/Drivers/SemiReplication/Item.php
index 875e9498c..3720d530d 100644
--- a/lib/Phpfastcache/Cluster/Drivers/SemiReplication/Item.php
+++ b/lib/Phpfastcache/Cluster/Drivers/SemiReplication/Item.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Cluster\Drivers\SemiReplication;
diff --git a/lib/Phpfastcache/Cluster/ItemAbstract.php b/lib/Phpfastcache/Cluster/ItemAbstract.php
index c45edbd54..ba2706ef9 100644
--- a/lib/Phpfastcache/Cluster/ItemAbstract.php
+++ b/lib/Phpfastcache/Cluster/ItemAbstract.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Cluster;
diff --git a/lib/Phpfastcache/Config/AbstractConfigurationOption.php b/lib/Phpfastcache/Config/AbstractConfigurationOption.php
index dff96cdea..7e4165ca0 100644
--- a/lib/Phpfastcache/Config/AbstractConfigurationOption.php
+++ b/lib/Phpfastcache/Config/AbstractConfigurationOption.php
@@ -1,4 +1,5 @@
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Config;
@@ -20,14 +22,11 @@
abstract class AbstractConfigurationOption implements LockableConfigurationInterface
{
private bool $lockedObject = false;
-
private ExtendedCacheItemPoolInterface $locker;
-
public function lock(ExtendedCacheItemPoolInterface $poolInstance): static
{
$this->lockedObject = true;
$this->locker = $poolInstance;
-
return $this;
}
@@ -52,13 +51,12 @@ protected function enforceLockedProperty(string $method): void
if ($cause) {
$moreInfo = \sprintf('Caused line %d in %s', $cause['line'], $cause['file']);
}
- throw new PhpfastcacheLogicException(
- \sprintf(
- 'You can no longer change the configuration "%s" as the cache pool instance is now running. %s',
- \lcfirst(\substr($method, 3)),
- $moreInfo ?? ''
- )
- );
+
+ throw new PhpfastcacheLogicException(\sprintf(
+ 'You can no longer change the configuration "%s" as the cache pool instance is now running. %s',
+ \lcfirst(\substr($method, 3)),
+ $moreInfo ?? ''
+ ));
}
}
}
diff --git a/lib/Phpfastcache/Config/Config.php b/lib/Phpfastcache/Config/Config.php
index 0dac40aff..91ed2753d 100644
--- a/lib/Phpfastcache/Config/Config.php
+++ b/lib/Phpfastcache/Config/Config.php
@@ -11,8 +11,17 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Config;
\class_alias(ConfigurationOption::class, \Phpfastcache\Config\Config::class);
+\trigger_error(
+ \sprintf(
+ '%s class is deprecated and will be removed in v10, use %s instead.',
+ \Phpfastcache\Config\Config::class,
+ ConfigurationOption::class
+ ),
+ \E_USER_DEPRECATED
+);
diff --git a/lib/Phpfastcache/Config/ConfigurationOption.php b/lib/Phpfastcache/Config/ConfigurationOption.php
index 4f635caf7..b11b30be1 100644
--- a/lib/Phpfastcache/Config/ConfigurationOption.php
+++ b/lib/Phpfastcache/Config/ConfigurationOption.php
@@ -1,4 +1,5 @@
isAnonymous());
+ }
+
/**
* @param string $optionName
* @return bool
@@ -337,6 +346,7 @@ protected function getDefaultSuperGlobalAccessor(): \Closure
'SERVER' => $keyName !== null ? $_SERVER[$keyName] ?? null : $_SERVER,
'REQUEST' => $keyName !== null ? $_REQUEST[$keyName] ?? null : $_REQUEST,
'COOKIE' => $keyName !== null ? $_COOKIE[$keyName] ?? null : $_COOKIE,
+ default => null,
};
});
}
diff --git a/lib/Phpfastcache/Config/ConfigurationOptionInterface.php b/lib/Phpfastcache/Config/ConfigurationOptionInterface.php
index 440da0242..f67214d8b 100644
--- a/lib/Phpfastcache/Config/ConfigurationOptionInterface.php
+++ b/lib/Phpfastcache/Config/ConfigurationOptionInterface.php
@@ -11,11 +11,14 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Config;
+use Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException;
use Phpfastcache\Exceptions\PhpfastcacheInvalidConfigurationException;
+use Phpfastcache\Exceptions\PhpfastcacheLogicException;
interface ConfigurationOptionInterface extends LockableConfigurationInterface
{
@@ -29,12 +32,23 @@ public function __construct(array $parameters = []);
*/
public function toArray(): array;
+ /**
+ * @param mixed $val
+ * @return bool
+ */
+ public function isValueSerializable(mixed $val): bool;
+
/**
* @param string $optionName
* @return bool
*/
public function isValidOption(string $optionName): bool;
-
+
+ /**
+ * @return bool
+ */
+ public function isItemDetailedDate(): bool;
+
/**
* @param bool $itemDetailedDate
* @return ConfigurationOption
@@ -122,4 +136,19 @@ public function isUseStaticItemCaching(): bool;
* @return ConfigurationOption
*/
public function setUseStaticItemCaching(bool $useStaticItemCaching): static;
+
+ /**
+ * @return object
+ * @throws PhpfastcacheInvalidArgumentException
+ * @throws PhpfastcacheLogicException
+ */
+ public function getSuperGlobalAccessor(): object;
+
+ /**
+ * @param ?object $superGlobalAccessor
+ * @return static
+ * @throws PhpfastcacheInvalidArgumentException
+ * @throws PhpfastcacheLogicException
+ */
+ public function setSuperGlobalAccessor(?object $superGlobalAccessor): static;
}
diff --git a/lib/Phpfastcache/Config/IOConfigurationOptionInterface.php b/lib/Phpfastcache/Config/IOConfigurationOptionInterface.php
index 62e450938..24cc7e5cb 100644
--- a/lib/Phpfastcache/Config/IOConfigurationOptionInterface.php
+++ b/lib/Phpfastcache/Config/IOConfigurationOptionInterface.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Config;
diff --git a/lib/Phpfastcache/Config/IOConfigurationOptionTrait.php b/lib/Phpfastcache/Config/IOConfigurationOptionTrait.php
index ca6c2c8b5..cd089f245 100644
--- a/lib/Phpfastcache/Config/IOConfigurationOptionTrait.php
+++ b/lib/Phpfastcache/Config/IOConfigurationOptionTrait.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Config;
@@ -89,12 +90,12 @@ public function setCacheFileExtension(string $cacheFileExtension): static
$this->enforceLockedProperty(__FUNCTION__);
$safeFileExtensions = \explode('|', IOConfigurationOptionInterface::SAFE_FILE_EXTENSIONS);
- if (str_contains($cacheFileExtension, '.')) {
+ if (\str_contains($cacheFileExtension, '.')) {
throw new PhpfastcacheInvalidConfigurationException('cacheFileExtension cannot contain a dot "."');
}
if (!\in_array($cacheFileExtension, $safeFileExtensions, true)) {
throw new PhpfastcacheInvalidConfigurationException(
- "Extension \"$cacheFileExtension\" is not safe, currently allowed extension names: " . \implode(', ', $safeFileExtensions)
+ "Extension \"$cacheFileExtension\" is unsafe, currently allowed extension names: " . \implode(', ', $safeFileExtensions)
);
}
diff --git a/lib/Phpfastcache/Config/LockableConfigurationInterface.php b/lib/Phpfastcache/Config/LockableConfigurationInterface.php
index bfd590f20..428451bc0 100644
--- a/lib/Phpfastcache/Config/LockableConfigurationInterface.php
+++ b/lib/Phpfastcache/Config/LockableConfigurationInterface.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Config;
diff --git a/lib/Phpfastcache/Core/Item/CacheItemTrait.php b/lib/Phpfastcache/Core/Item/CacheItemTrait.php
index ca088d5c3..01b84d000 100644
--- a/lib/Phpfastcache/Core/Item/CacheItemTrait.php
+++ b/lib/Phpfastcache/Core/Item/CacheItemTrait.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Core\Item;
diff --git a/lib/Phpfastcache/Core/Item/ExtendedCacheItemInterface.php b/lib/Phpfastcache/Core/Item/ExtendedCacheItemInterface.php
index 490908bda..f97ccaed2 100644
--- a/lib/Phpfastcache/Core/Item/ExtendedCacheItemInterface.php
+++ b/lib/Phpfastcache/Core/Item/ExtendedCacheItemInterface.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Core\Item;
@@ -32,7 +33,6 @@ interface ExtendedCacheItemInterface extends
JsonSerializable,
TaggableCacheItemInterface
{
-
/**
* Returns the encoded key for the current cache item.
* Is a MD5 (default),SHA1,SHA256 hash if "defaultKeyHashFunction" config option is configured
diff --git a/lib/Phpfastcache/Core/Item/ExtendedCacheItemTrait.php b/lib/Phpfastcache/Core/Item/ExtendedCacheItemTrait.php
index 6421d897a..82c05e1e7 100644
--- a/lib/Phpfastcache/Core/Item/ExtendedCacheItemTrait.php
+++ b/lib/Phpfastcache/Core/Item/ExtendedCacheItemTrait.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Core\Item;
@@ -176,7 +177,7 @@ public function getTtl(): int
public function isExpired(): bool
{
- return $this->expirationDate->getTimestamp() < (new DateTime())->getTimestamp();
+ return $this->getTtl() <= 0;
}
public function isNull(): bool
@@ -318,12 +319,12 @@ public function cloneInto(ExtendedCacheItemInterface $itemTarget, ?ExtendedCache
->set($this->getRawValue())
->setHit($this->isHit())
->setTags($this->getTags())
- ->expiresAt($this->getExpirationDate())
+ ->expiresAt(clone $this->getExpirationDate())
->setDriver($itemPoolTarget ?? $this->driver);
if ($this->driver->getConfig()->isItemDetailedDate()) {
- $itemTarget->setCreationDate($this->getCreationDate())
- ->setModificationDate($this->getModificationDate());
+ $itemTarget->setCreationDate(clone $this->getCreationDate())
+ ->setModificationDate(clone $this->getModificationDate());
}
}
diff --git a/lib/Phpfastcache/Core/Item/TaggableCacheItemInterface.php b/lib/Phpfastcache/Core/Item/TaggableCacheItemInterface.php
index a84fccf71..faa8cf03b 100644
--- a/lib/Phpfastcache/Core/Item/TaggableCacheItemInterface.php
+++ b/lib/Phpfastcache/Core/Item/TaggableCacheItemInterface.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Core\Item;
diff --git a/lib/Phpfastcache/Core/Item/TaggableCacheItemTrait.php b/lib/Phpfastcache/Core/Item/TaggableCacheItemTrait.php
index b674153fe..7e509057a 100644
--- a/lib/Phpfastcache/Core/Item/TaggableCacheItemTrait.php
+++ b/lib/Phpfastcache/Core/Item/TaggableCacheItemTrait.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Core\Item;
@@ -20,6 +21,7 @@
trait TaggableCacheItemTrait
{
use ExtendedCacheItemTrait;
+
/**
* @var string[]
*/
diff --git a/lib/Phpfastcache/Core/Pool/CacheItemPoolTrait.php b/lib/Phpfastcache/Core/Pool/CacheItemPoolTrait.php
index f558fdc19..a41ed40c6 100644
--- a/lib/Phpfastcache/Core/Pool/CacheItemPoolTrait.php
+++ b/lib/Phpfastcache/Core/Pool/CacheItemPoolTrait.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Core\Pool;
@@ -20,17 +21,13 @@
use Phpfastcache\Entities\DriverIO;
use Phpfastcache\Entities\ItemBatch;
use Phpfastcache\Event\Event;
-use Phpfastcache\Event\EventManagerDispatcherTrait;
use Phpfastcache\Event\EventReferenceParameter;
use Phpfastcache\Exceptions\PhpfastcacheCoreException;
use Phpfastcache\Exceptions\PhpfastcacheDriverException;
use Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException;
use Phpfastcache\Exceptions\PhpfastcacheIOException;
use Phpfastcache\Exceptions\PhpfastcacheLogicException;
-use Phpfastcache\Util\ClassNamespaceResolverTrait;
use Psr\Cache\CacheItemInterface;
-use ReflectionClass;
-use ReflectionObject;
use RuntimeException;
trait CacheItemPoolTrait
@@ -43,12 +40,12 @@ trait CacheItemPoolTrait
protected static string $unsupportedKeyChars = '{}()/\@:';
/**
- * @var ExtendedCacheItemInterface[]
+ * @var ExtendedCacheItemInterface[]|CacheItemInterface[]
*/
protected array $deferredList = [];
/**
- * @var ExtendedCacheItemInterface[]
+ * @var ExtendedCacheItemInterface[]|CacheItemInterface[]
*/
protected array $itemInstances = [];
@@ -60,7 +57,7 @@ trait CacheItemPoolTrait
*/
public function setItem(CacheItemInterface $item): static
{
- if ($this->getItemClass() === $item::class) {
+ if (self::getItemClass() === $item::class) {
if (!$this->getConfig()->isUseStaticItemCaching()) {
throw new PhpfastcacheLogicException(
'The static item caching option (useStaticItemCaching) is disabled so you cannot attach an item.'
@@ -202,7 +199,7 @@ public function getItem(string $key): ExtendedCacheItemInterface
* Reset the Item
*/
$item->set(null)
- ->expiresAfter(abs((int)$this->getConfig()->getDefaultTtl()))
+ ->expiresAfter((int) abs($this->getConfig()->getDefaultTtl()))
->setHit(false)
->setTags([]);
if ($this->getConfig()->isItemDetailedDate()) {
@@ -218,7 +215,7 @@ public function getItem(string $key): ExtendedCacheItemInterface
$item->setHit(true);
}
} else {
- $item->expiresAfter(abs($this->getConfig()->getDefaultTtl()));
+ $item->expiresAfter((int) abs($this->getConfig()->getDefaultTtl()));
}
}
} else {
@@ -230,10 +227,9 @@ public function getItem(string $key): ExtendedCacheItemInterface
$this->eventManager->dispatch(Event::CACHE_GET_ITEM, $this, $item);
$item->isHit() ? $this->getIO()->incReadHit() : $this->getIO()->incReadMiss();
-
- return $item;
}
- throw new PhpfastcacheInvalidArgumentException(\sprintf('Item %s was not build due to an unknown error', \gettype($key)));
+
+ return $item;
}
/**
@@ -357,7 +353,7 @@ public function commit(): bool
$return = true;
foreach ($this->deferredList as $key => $item) {
$result = $this->save($item);
- if ($return !== true) {
+ if ($result !== true) {
unset($this->deferredList[$key]);
$return = $result;
}
@@ -418,6 +414,10 @@ public function save(CacheItemInterface $item): bool
if ($this->driverWrite($item) && $this->driverWriteTags($item)) {
$item->setHit(true);
+ if ($this->getConfig()->isItemDetailedDate()) {
+ $item->setModificationDate(new \DateTime());
+ }
+
$this->getIO()->incWriteHit();
return true;
diff --git a/lib/Phpfastcache/Core/Pool/DriverBaseTrait.php b/lib/Phpfastcache/Core/Pool/DriverBaseTrait.php
index b56828ba1..0b10f4295 100644
--- a/lib/Phpfastcache/Core/Pool/DriverBaseTrait.php
+++ b/lib/Phpfastcache/Core/Pool/DriverBaseTrait.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Core\Pool;
@@ -102,9 +103,9 @@ public function getDriverName(): string
}
/**
- * @return ConfigurationOption
+ * @return ConfigurationOptionInterface
*/
- public function getDefaultConfig(): ConfigurationOption
+ public function getDefaultConfig(): ConfigurationOptionInterface
{
$className = $this::getConfigClass();
@@ -142,40 +143,42 @@ public static function getItemClass(): string
public function driverPreWrap(ExtendedCacheItemInterface $item, bool $stringifyDate = false): array
{
$wrap = [
- self::DRIVER_KEY_WRAPPER_INDEX => $item->getKey(), // Stored but not really used, allow you to quickly identify the cache key
- self::DRIVER_DATA_WRAPPER_INDEX => $item->getRawValue(),
- self::DRIVER_TAGS_WRAPPER_INDEX => $item->getTags(),
+ ExtendedCacheItemPoolInterface::DRIVER_KEY_WRAPPER_INDEX => $item->getKey(), // Stored but not really used, allow you to quickly identify the cache key
+ ExtendedCacheItemPoolInterface::DRIVER_DATA_WRAPPER_INDEX => $item->getRawValue(),
+ TaggableCacheItemPoolInterface::DRIVER_TAGS_WRAPPER_INDEX => $item->getTags(),
self::DRIVER_EDATE_WRAPPER_INDEX => $item->getExpirationDate(),
];
if ($this->getConfig()->isItemDetailedDate()) {
- $wrap[self::DRIVER_MDATE_WRAPPER_INDEX] = new DateTime();
+ $wrap[ExtendedCacheItemPoolInterface::DRIVER_MDATE_WRAPPER_INDEX] = new DateTime();// Always on the latest date
/**
* If the creation date exists
* reuse it else set a new Date
*/
- $wrap[self::DRIVER_CDATE_WRAPPER_INDEX] = $item->getCreationDate() ?: new DateTime();
+ $wrap[ExtendedCacheItemPoolInterface::DRIVER_CDATE_WRAPPER_INDEX] = $item->getCreationDate();
} else {
- $wrap[self::DRIVER_MDATE_WRAPPER_INDEX] = null;
- $wrap[self::DRIVER_CDATE_WRAPPER_INDEX] = null;
+ $wrap[ExtendedCacheItemPoolInterface::DRIVER_MDATE_WRAPPER_INDEX] = null;
+ $wrap[ExtendedCacheItemPoolInterface::DRIVER_CDATE_WRAPPER_INDEX] = null;
}
if ($stringifyDate) {
- $wrap = \array_map(static function ($value) {
- if ($value instanceof DateTimeInterface) {
- return $value->format(DateTimeInterface::W3C);
+ \array_walk($wrap, static function (mixed &$value, string $key): void {
+ if ($value instanceof DateTimeInterface && $key !== ExtendedCacheItemPoolInterface::DRIVER_DATA_WRAPPER_INDEX) {
+ $value = $value->format(DateTimeInterface::W3C);
}
- return $value;
- }, $wrap);
+ });
}
return $wrap;
}
/**
- * @return ConfigurationOption
+ * @return ConfigurationOptionInterface
*/
- abstract public function getConfig(): ConfigurationOption;
+ public function getConfig(): ConfigurationOptionInterface
+ {
+ return $this->config;
+ }
/**
* @param ConfigurationOptionInterface $config
@@ -195,7 +198,7 @@ public function setConfig(ConfigurationOptionInterface $config): static
*/
public function driverUnwrapData(array $wrapper): mixed
{
- return $wrapper[self::DRIVER_DATA_WRAPPER_INDEX];
+ return $wrapper[ExtendedCacheItemPoolInterface::DRIVER_DATA_WRAPPER_INDEX];
}
/**
diff --git a/lib/Phpfastcache/Core/Pool/DriverPoolAbstractTrait.php b/lib/Phpfastcache/Core/Pool/DriverPoolAbstractTrait.php
index b3e9a48fb..fee56da0b 100644
--- a/lib/Phpfastcache/Core/Pool/DriverPoolAbstractTrait.php
+++ b/lib/Phpfastcache/Core/Pool/DriverPoolAbstractTrait.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Core\Pool;
diff --git a/lib/Phpfastcache/Core/Pool/ExtendedCacheItemPoolInterface.php b/lib/Phpfastcache/Core/Pool/ExtendedCacheItemPoolInterface.php
index b03704df8..36d24c321 100644
--- a/lib/Phpfastcache/Core/Pool/ExtendedCacheItemPoolInterface.php
+++ b/lib/Phpfastcache/Core/Pool/ExtendedCacheItemPoolInterface.php
@@ -11,12 +11,14 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Core\Pool;
use InvalidArgumentException;
use Phpfastcache\Config\ConfigurationOption;
+use Phpfastcache\Config\ConfigurationOptionInterface;
use Phpfastcache\Core\Item\ExtendedCacheItemInterface;
use Phpfastcache\Entities\DriverIO;
use Phpfastcache\Entities\DriverStatistic;
@@ -75,14 +77,14 @@ public static function getConfigClass(): string;
public static function getItemClass(): string;
/**
- * @return ConfigurationOption
+ * @return ConfigurationOptionInterface
*/
- public function getConfig(): ConfigurationOption;
+ public function getConfig(): ConfigurationOptionInterface;
/**
- * @return ConfigurationOption
+ * @return ConfigurationOptionInterface
*/
- public function getDefaultConfig(): ConfigurationOption;
+ public function getDefaultConfig(): ConfigurationOptionInterface;
/**
* @return string
@@ -95,7 +97,7 @@ public function getDriverName(): string;
public function getInstanceId(): string;
/**
- * [phpFastCache phpDoc Override]
+ * [Phpfastcache phpDoc Override]
* Returns a Cache Item representing the specified key.
*
* This method must always return a CacheItemInterface object, even in case of
@@ -114,10 +116,10 @@ public function getInstanceId(): string;
public function getItem(string $key): ExtendedCacheItemInterface;
/**
- * [phpFastCache phpDoc Override]
+ * [Phpfastcache phpDoc Override]
* Returns a traversable set of cache items.
*
- * @param array $keys
+ * @param string[] $keys
* An indexed array of keys of items to retrieve.
*
* @return ExtendedCacheItemInterface[]
@@ -167,7 +169,7 @@ public function attachItem(CacheItemInterface $item): static;
/**
* Returns true if the item exists, is attached and the Spl Hash matches
* Returns false if the item exists, is attached and the Spl Hash mismatches
- * Returns null if the item does not exists
+ * Returns null if the item does not exist
*
* @param CacheItemInterface $item
* @return bool
@@ -175,6 +177,17 @@ public function attachItem(CacheItemInterface $item): static;
*/
public function isAttached(CacheItemInterface $item): bool;
+ /**
+ * Persists a cache item immediately.
+ *
+ * @param ExtendedCacheItemInterface|CacheItemInterface $item
+ * The cache item to save.
+ *
+ * @return bool
+ * True if the item was successfully persisted. False if there was an error.
+ */
+ public function save(ExtendedCacheItemInterface|CacheItemInterface $item): bool;
+
/**
* Save multiple items, possible uses:
* saveMultiple([$item1, $item2, $item3]);
@@ -183,7 +196,7 @@ public function isAttached(CacheItemInterface $item): bool;
* @param ExtendedCacheItemInterface[] $items
* @return bool
*/
- public function saveMultiple(ExtendedCacheItemInterface...$items): bool;
+ public function saveMultiple(ExtendedCacheItemInterface ...$items): bool;
/**
* @return DriverIO
diff --git a/lib/Phpfastcache/Core/Pool/ExtendedCacheItemPoolTrait.php b/lib/Phpfastcache/Core/Pool/ExtendedCacheItemPoolTrait.php
index d15b645c0..aa0f55015 100644
--- a/lib/Phpfastcache/Core/Pool/ExtendedCacheItemPoolTrait.php
+++ b/lib/Phpfastcache/Core/Pool/ExtendedCacheItemPoolTrait.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Core\Pool;
@@ -121,7 +122,7 @@ public function isAttached(CacheItemInterface $item): bool
* @throws PhpfastcacheInvalidArgumentException
* @throws PhpfastcacheLogicException
*/
- public function saveMultiple(ExtendedCacheItemInterface...$items): bool
+ public function saveMultiple(ExtendedCacheItemInterface ...$items): bool
{
$this->eventManager->dispatch(Event::CACHE_SAVE_MULTIPLE_ITEMS, $this, new EventReferenceParameter($items));
diff --git a/lib/Phpfastcache/Core/Pool/IO/IOHelperTrait.php b/lib/Phpfastcache/Core/Pool/IO/IOHelperTrait.php
index 295d7df58..bc3120e4c 100644
--- a/lib/Phpfastcache/Core/Pool/IO/IOHelperTrait.php
+++ b/lib/Phpfastcache/Core/Pool/IO/IOHelperTrait.php
@@ -11,11 +11,12 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Core\Pool\IO;
-use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface;
+use Phpfastcache\Config\IOConfigurationOptionInterface;
use Phpfastcache\Core\Pool\TaggableCacheItemPoolTrait;
use Phpfastcache\Entities\DriverStatistic;
use Phpfastcache\Event\Event;
@@ -24,6 +25,9 @@
use Phpfastcache\Util\Directory;
use Phpfastcache\Util\SapiDetector;
+/**
+ * @method IOConfigurationOptionInterface getConfig()
+ */
trait IOHelperTrait
{
use TaggableCacheItemPoolTrait;
diff --git a/lib/Phpfastcache/Core/Pool/TaggableCacheItemPoolInterface.php b/lib/Phpfastcache/Core/Pool/TaggableCacheItemPoolInterface.php
index 4f83af975..abdca429e 100644
--- a/lib/Phpfastcache/Core/Pool/TaggableCacheItemPoolInterface.php
+++ b/lib/Phpfastcache/Core/Pool/TaggableCacheItemPoolInterface.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Core\Pool;
diff --git a/lib/Phpfastcache/Core/Pool/TaggableCacheItemPoolTrait.php b/lib/Phpfastcache/Core/Pool/TaggableCacheItemPoolTrait.php
index 2772400ff..458637ec1 100644
--- a/lib/Phpfastcache/Core/Pool/TaggableCacheItemPoolTrait.php
+++ b/lib/Phpfastcache/Core/Pool/TaggableCacheItemPoolTrait.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Core\Pool;
@@ -74,7 +75,7 @@ public function getItemsByTags(array $tagNames, int $strategy = TaggableCacheIte
if (\is_string($tagName)) {
$items[] = $this->fetchItemsByTagFromBackend($tagName);
} else {
- throw new PhpfastcacheInvalidArgumentException('$tagName must be a a string');
+ throw new PhpfastcacheInvalidArgumentException('$tagName must be a string');
}
}
@@ -138,7 +139,7 @@ protected function fetchItemsByTagFromBackend(string $tagName): array
*/
protected function getTagKey(string $key): string
{
- return self::DRIVER_TAGS_KEY_PREFIX . $key;
+ return TaggableCacheItemPoolInterface::DRIVER_TAGS_KEY_PREFIX . $key;
}
/**
@@ -156,7 +157,7 @@ public function deleteItemsByTags(array $tagNames, int $strategy = TaggableCache
foreach ($this->getItemsByTags($tagNames, $strategy) as $item) {
$result = $this->deleteItem($item->getKey());
- if ($return !== true) {
+ if ($result !== true) {
$return = $result;
}
}
@@ -178,7 +179,7 @@ public function deleteItemsByTag(string $tagName, int $strategy = TaggableCacheI
$return = true;
foreach ($this->getItemsByTag($tagName, $strategy) as $item) {
$result = $this->deleteItem($item->getKey());
- if ($return !== true) {
+ if ($result !== true) {
$return = $result;
}
}
@@ -224,7 +225,7 @@ public function incrementItemsByTags(array $tagNames, int $step = 1, int $strate
$return = true;
foreach ($tagNames as $tagName) {
$result = $this->incrementItemsByTag($tagName, $step, $strategy);
- if ($return !== true) {
+ if ($result !== true) {
$return = $result;
}
}
@@ -269,7 +270,7 @@ public function decrementItemsByTags(array $tagNames, int $step = 1, int $strate
$return = true;
foreach ($tagNames as $tagName) {
$result = $this->decrementItemsByTag($tagName, $step, $strategy);
- if ($return !== true) {
+ if ($result !== true) {
$return = $result;
}
}
@@ -314,7 +315,7 @@ public function appendItemsByTags(array $tagNames, array|string $data, int $stra
$return = true;
foreach ($tagNames as $tagName) {
$result = $this->appendItemsByTag($tagName, $data, $strategy);
- if ($return !== true) {
+ if ($result !== true) {
$return = $result;
}
}
@@ -359,7 +360,7 @@ public function prependItemsByTags(array $tagNames, array|string $data, int $str
$return = true;
foreach ($tagNames as $tagName) {
$result = $this->prependItemsByTag($tagName, $data, $strategy);
- if ($return !== true) {
+ if ($result !== true) {
$return = $result;
}
}
@@ -394,7 +395,7 @@ public function prependItemsByTag(string $tagName, array|string $data, int $stra
*/
protected function driverUnwrapTags(array $wrapper): array
{
- return $wrapper[self::DRIVER_TAGS_WRAPPER_INDEX];
+ return $wrapper[TaggableCacheItemPoolInterface::DRIVER_TAGS_WRAPPER_INDEX];
}
/**
@@ -424,7 +425,7 @@ protected function driverWriteTags(ExtendedCacheItemInterface $item): bool
* on tags item, it can lead
* to an infinite recursive calls
*/
- if (str_starts_with($item->getKey(), self::DRIVER_TAGS_KEY_PREFIX)) {
+ if (str_starts_with($item->getKey(), TaggableCacheItemPoolInterface::DRIVER_TAGS_KEY_PREFIX)) {
throw new PhpfastcacheLogicException('Trying to set tag(s) to an Tag item index: ' . $item->getKey());
}
diff --git a/lib/Phpfastcache/Drivers/Apcu/Config.php b/lib/Phpfastcache/Drivers/Apcu/Config.php
index 6e1d351ca..a0d47d9f9 100644
--- a/lib/Phpfastcache/Drivers/Apcu/Config.php
+++ b/lib/Phpfastcache/Drivers/Apcu/Config.php
@@ -1,4 +1,5 @@
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Apcu;
@@ -28,7 +29,7 @@
/**
* Class Driver
- * @property Config $config
+ * @method Config getConfig()
*/
class Driver implements ExtendedCacheItemPoolInterface, AggregatablePoolInterface
{
@@ -117,9 +118,4 @@ protected function driverClear(): bool
{
return @apcu_clear_cache();
}
-
- public function getConfig(): Config
- {
- return $this->config;
- }
}
diff --git a/lib/Phpfastcache/Drivers/Apcu/Item.php b/lib/Phpfastcache/Drivers/Apcu/Item.php
index 6cd749e11..d2c250a2d 100644
--- a/lib/Phpfastcache/Drivers/Apcu/Item.php
+++ b/lib/Phpfastcache/Drivers/Apcu/Item.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Apcu;
diff --git a/lib/Phpfastcache/Drivers/Arangodb/Config.php b/lib/Phpfastcache/Drivers/Arangodb/Config.php
index 2197faa63..3454424c0 100644
--- a/lib/Phpfastcache/Drivers/Arangodb/Config.php
+++ b/lib/Phpfastcache/Drivers/Arangodb/Config.php
@@ -1,4 +1,5 @@
database;
diff --git a/lib/Phpfastcache/Drivers/Arangodb/Driver.php b/lib/Phpfastcache/Drivers/Arangodb/Driver.php
index bb319676c..53f9643c2 100644
--- a/lib/Phpfastcache/Drivers/Arangodb/Driver.php
+++ b/lib/Phpfastcache/Drivers/Arangodb/Driver.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Arangodb;
@@ -24,13 +25,11 @@
use ArangoDBClient\DocumentHandler as ArangoDocumentHandler;
use ArangoDBClient\Exception as ArangoException;
use ArangoDBClient\ServerException as ArangoServerException;
-
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\Event;
use Phpfastcache\Event\EventReferenceParameter;
use Phpfastcache\Exceptions\PhpfastcacheDriverConnectException;
use Phpfastcache\Exceptions\PhpfastcacheDriverException;
@@ -38,7 +37,7 @@
/**
* Class Driver
- * @property Config $config
+ * @method Config getConfig()
* @property ArangoConnection $instance
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
@@ -136,7 +135,7 @@ protected function driverRead(ExtendedCacheItemInterface $item): ?array
);
}
- return $this->decode($document);
+ return $this->decodeDocument($document);
}
/**
@@ -242,17 +241,16 @@ protected function createCollection($collectionName): bool
/**
* @param ArangoDocument $document
- * @return mixed
+ * @return array
* @throws \Exception
*/
- protected function decode(ArangoDocument $document): mixed
+ protected function decodeDocument(ArangoDocument $document): array
{
$value = [
self::DRIVER_KEY_WRAPPER_INDEX => $document->get(self::DRIVER_KEY_WRAPPER_INDEX),
self::DRIVER_TAGS_WRAPPER_INDEX => $document->get(self::DRIVER_TAGS_WRAPPER_INDEX),
- self::DRIVER_DATA_WRAPPER_INDEX => \unserialize(
+ self::DRIVER_DATA_WRAPPER_INDEX => $this->decode(
$document->get(self::DRIVER_DATA_WRAPPER_INDEX),
- ['allowed_classes' => true]
),
];
@@ -311,9 +309,4 @@ public function getStats(): DriverStatistic
->setRawData($rawData)
->setSize($rawData['collectionCount']);
}
-
- public function getConfig(): Config
- {
- return $this->config;
- }
}
diff --git a/lib/Phpfastcache/Drivers/Arangodb/Event.php b/lib/Phpfastcache/Drivers/Arangodb/Event.php
new file mode 100644
index 000000000..6e9c2c555
--- /dev/null
+++ b/lib/Phpfastcache/Drivers/Arangodb/Event.php
@@ -0,0 +1,9 @@
+
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Arangodb;
diff --git a/lib/Phpfastcache/Drivers/Cassandra/Config.php b/lib/Phpfastcache/Drivers/Cassandra/Config.php
index c60c74be9..3e8b7ea71 100644
--- a/lib/Phpfastcache/Drivers/Cassandra/Config.php
+++ b/lib/Phpfastcache/Drivers/Cassandra/Config.php
@@ -1,4 +1,5 @@
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Cassandra;
@@ -30,16 +31,16 @@
/**
* Class Driver
- * @property CassandraSession $instance Instance of driver service
- * @property Config $config
+ * @property CassandraSession|null $instance Instance of driver service
+ * @method Config getConfig()
*/
class Driver implements ExtendedCacheItemPoolInterface, AggregatablePoolInterface
{
+ use TaggableCacheItemPoolTrait;
+
protected const CASSANDRA_KEY_SPACE = 'phpfastcache';
protected const CASSANDRA_TABLE = 'cacheItems';
- use TaggableCacheItemPoolTrait;
-
/**
* @return bool
*/
@@ -55,10 +56,6 @@ public function driverCheck(): bool
*/
protected function driverConnect(): bool
{
- if ($this->instance instanceof CassandraSession) {
- throw new PhpfastcacheLogicException('Already connected to Couchbase server');
- }
-
$clientConfig = $this->getConfig();
$clusterBuilder = Cassandra::cluster()
@@ -81,7 +78,7 @@ protected function driverConnect(): bool
$clusterBuilder->withCredentials($clientConfig->getUsername(), $clientConfig->getPassword());
}
- $this->instance = $clusterBuilder->build()->connect();
+ $this->instance = $clusterBuilder->build()->connect('');
/**
* In case of emergency:
@@ -96,9 +93,10 @@ protected function driverConnect(): bool
"CREATE KEYSPACE IF NOT EXISTS %s WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };",
self::CASSANDRA_KEY_SPACE
)
- )
+ ),
+ []
);
- $this->instance->execute(new Cassandra\SimpleStatement(sprintf('USE %s;', self::CASSANDRA_KEY_SPACE)));
+ $this->instance->execute(new Cassandra\SimpleStatement(sprintf('USE %s;', self::CASSANDRA_KEY_SPACE)), []);
$this->instance->execute(
new Cassandra\SimpleStatement(
sprintf(
@@ -114,7 +112,8 @@ protected function driverConnect(): bool
);',
self::CASSANDRA_TABLE
)
- )
+ ),
+ []
);
return true;
@@ -304,9 +303,4 @@ public function getStats(): DriverStatistic
->setData(implode(', ', array_keys($this->itemInstances)))
->setInfo('The cache size represents only the cache data itself without counting data structures associated to the cache entries.');
}
-
- public function getConfig(): Config
- {
- return $this->config;
- }
}
diff --git a/lib/Phpfastcache/Drivers/Cassandra/Item.php b/lib/Phpfastcache/Drivers/Cassandra/Item.php
index e9ac89a39..f902fedb7 100644
--- a/lib/Phpfastcache/Drivers/Cassandra/Item.php
+++ b/lib/Phpfastcache/Drivers/Cassandra/Item.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Cassandra;
diff --git a/lib/Phpfastcache/Drivers/Couchbasev3/Config.php b/lib/Phpfastcache/Drivers/Couchbasev3/Config.php
index 605d44d9f..e812f2237 100644
--- a/lib/Phpfastcache/Drivers/Couchbasev3/Config.php
+++ b/lib/Phpfastcache/Drivers/Couchbasev3/Config.php
@@ -1,4 +1,5 @@
host;
diff --git a/lib/Phpfastcache/Drivers/Couchbasev3/Driver.php b/lib/Phpfastcache/Drivers/Couchbasev3/Driver.php
index aee6c0d7d..fb6f147c5 100644
--- a/lib/Phpfastcache/Drivers/Couchbasev3/Driver.php
+++ b/lib/Phpfastcache/Drivers/Couchbasev3/Driver.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Couchbasev3;
@@ -37,7 +38,7 @@
/**
* @property Cluster $instance Instance of driver service
- * @property Config $config
+ * @method Config getConfig()
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class Driver implements ExtendedCacheItemPoolInterface, AggregatablePoolInterface
@@ -273,9 +274,4 @@ protected function decodeDocument(array $data): array
return $data;
}
-
- public function getConfig(): Config
- {
- return $this->config;
- }
}
diff --git a/lib/Phpfastcache/Drivers/Couchbasev3/Item.php b/lib/Phpfastcache/Drivers/Couchbasev3/Item.php
index 0fb71b66f..5fd389471 100644
--- a/lib/Phpfastcache/Drivers/Couchbasev3/Item.php
+++ b/lib/Phpfastcache/Drivers/Couchbasev3/Item.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Couchbasev3;
diff --git a/lib/Phpfastcache/Drivers/Couchdb/Config.php b/lib/Phpfastcache/Drivers/Couchdb/Config.php
index 8dd8f662d..114308668 100644
--- a/lib/Phpfastcache/Drivers/Couchdb/Config.php
+++ b/lib/Phpfastcache/Drivers/Couchdb/Config.php
@@ -1,4 +1,5 @@
enforceLockedProperty(__FUNCTION__);
- /** @see https://docs.couchdb.org/en/latest/api/database/common.html#put--db */
+/** @see https://docs.couchdb.org/en/latest/api/database/common.html#put--db */
if (\preg_match('#^[a-z][a-z0-9_\-+\$()/]+$#', $database)) {
$this->database = $database;
return $this;
}
- throw new PhpfastcacheInvalidArgumentException(sprintf(
- "Error: illegal_database_name Name: '%s'.
- Only lowercase characters (a-z), digits (0-9), and any of the characters _, $, (, ), +, -, and / are allowed. Must begin with a letter.",
- $database
- ));
+ throw new PhpfastcacheInvalidArgumentException(sprintf("Error: illegal_database_name Name: '%s'.
+ Only lowercase characters (a-z), digits (0-9), and any of the characters _, $, (, ), +, -, and / are allowed. Must begin with a letter.", $database));
}
/**
diff --git a/lib/Phpfastcache/Drivers/Couchdb/Driver.php b/lib/Phpfastcache/Drivers/Couchdb/Driver.php
index 058c58277..2407b022a 100644
--- a/lib/Phpfastcache/Drivers/Couchdb/Driver.php
+++ b/lib/Phpfastcache/Drivers/Couchdb/Driver.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Couchdb;
@@ -30,14 +31,14 @@
/**
* Class Driver
* @property CouchdbClient $instance Instance of driver service
- * @property Config $config
+ * @method Config getConfig()
*/
class Driver implements ExtendedCacheItemPoolInterface, AggregatablePoolInterface
{
- public const COUCHDB_DEFAULT_DB_NAME = 'phpfastcache'; // Public because used in config
-
use TaggableCacheItemPoolTrait;
+ public const COUCHDB_DEFAULT_DB_NAME = 'phpfastcache'; // Public because used in config
+
/**
* @return bool
*/
@@ -249,7 +250,7 @@ protected function encodeDocument(array $data): array
/**
* Specific document decoder for Couchdb
- * since we dont store encoded version
+ * since we don't store encoded version
* for performance purposes
*
* @param $value
@@ -284,9 +285,4 @@ protected function decode($value): mixed
return $value;
}
-
- public function getConfig(): Config
- {
- return $this->config;
- }
}
diff --git a/lib/Phpfastcache/Drivers/Couchdb/Item.php b/lib/Phpfastcache/Drivers/Couchdb/Item.php
index db58a925d..511d16b27 100644
--- a/lib/Phpfastcache/Drivers/Couchdb/Item.php
+++ b/lib/Phpfastcache/Drivers/Couchdb/Item.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Couchdb;
diff --git a/lib/Phpfastcache/Drivers/Devnull/Config.php b/lib/Phpfastcache/Drivers/Devnull/Config.php
index 1a6081f95..d6dad2bf3 100644
--- a/lib/Phpfastcache/Drivers/Devnull/Config.php
+++ b/lib/Phpfastcache/Drivers/Devnull/Config.php
@@ -1,4 +1,5 @@
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Devnull;
@@ -23,7 +24,7 @@
/**
* Class Driver
- * @property Config $config Return the config object
+ * @method Config getConfig()
*/
class Driver implements ExtendedCacheItemPoolInterface
{
@@ -99,9 +100,4 @@ protected function driverConnect(): bool
{
return true;
}
-
- public function getConfig(): Config
- {
- return $this->config;
- }
}
diff --git a/lib/Phpfastcache/Drivers/Devnull/Item.php b/lib/Phpfastcache/Drivers/Devnull/Item.php
index e6788f649..948e73c4f 100644
--- a/lib/Phpfastcache/Drivers/Devnull/Item.php
+++ b/lib/Phpfastcache/Drivers/Devnull/Item.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Devnull;
diff --git a/lib/Phpfastcache/Drivers/Devrandom/Config.php b/lib/Phpfastcache/Drivers/Devrandom/Config.php
index fe2c9354f..7184a8fc9 100644
--- a/lib/Phpfastcache/Drivers/Devrandom/Config.php
+++ b/lib/Phpfastcache/Drivers/Devrandom/Config.php
@@ -1,4 +1,5 @@
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Devrandom;
@@ -24,7 +25,7 @@
use Psr\Cache\CacheItemInterface;
/**
- * @property Config $config Return the config object
+ * @method Config getConfig()
*/
class Driver implements ExtendedCacheItemPoolInterface
{
@@ -111,9 +112,4 @@ protected function driverConnect(): bool
{
return true;
}
-
- public function getConfig(): Config
- {
- return $this->config;
- }
}
diff --git a/lib/Phpfastcache/Drivers/Devrandom/Item.php b/lib/Phpfastcache/Drivers/Devrandom/Item.php
index dda9ccea5..75c82f98e 100644
--- a/lib/Phpfastcache/Drivers/Devrandom/Item.php
+++ b/lib/Phpfastcache/Drivers/Devrandom/Item.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Devrandom;
diff --git a/lib/Phpfastcache/Drivers/Dynamodb/Config.php b/lib/Phpfastcache/Drivers/Dynamodb/Config.php
index 7cafc6c41..5a175305e 100644
--- a/lib/Phpfastcache/Drivers/Dynamodb/Config.php
+++ b/lib/Phpfastcache/Drivers/Dynamodb/Config.php
@@ -1,4 +1,5 @@
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Dynamodb;
@@ -19,13 +20,11 @@
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\Event;
use Phpfastcache\Event\EventReferenceParameter;
use Phpfastcache\Exceptions\PhpfastcacheDriverConnectException;
use Phpfastcache\Exceptions\PhpfastcacheDriverException;
@@ -35,7 +34,7 @@
/**
* Class Driver
- * @property Config $config
+ * @method Config getConfig()
* @property AwsDynamoDbClient $instance
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
@@ -189,7 +188,7 @@ protected function hasTable(): bool
return \count($this->instance->listTables(['TableNames' => [$this->getConfig()->getTable()]])->get('TableNames')) > 0;
}
- protected function createTable() :void
+ protected function createTable(): void
{
$params = [
'TableName' => $this->getConfig()->getTable(),
@@ -295,9 +294,4 @@ protected function decodeDocument(array $data): array
return $data;
}
-
- public function getConfig(): Config
- {
- return $this->config;
- }
}
diff --git a/lib/Phpfastcache/Drivers/Dynamodb/Event.php b/lib/Phpfastcache/Drivers/Dynamodb/Event.php
new file mode 100644
index 000000000..1ccce6e73
--- /dev/null
+++ b/lib/Phpfastcache/Drivers/Dynamodb/Event.php
@@ -0,0 +1,8 @@
+
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Dynamodb;
diff --git a/lib/Phpfastcache/Drivers/Files/Config.php b/lib/Phpfastcache/Drivers/Files/Config.php
index ffce01dfc..728dc5d83 100644
--- a/lib/Phpfastcache/Drivers/Files/Config.php
+++ b/lib/Phpfastcache/Drivers/Files/Config.php
@@ -1,4 +1,5 @@
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Files;
@@ -27,7 +28,7 @@
use Phpfastcache\Util\Directory;
/**
- * @property Config $config
+ * @method Config getConfig()
*
* Important NOTE:
* We are using getKey instead of getEncodedKey since this backend create filename that are
@@ -126,9 +127,4 @@ protected function driverClear(): bool
{
return Directory::rrmdir($this->getPath(true));
}
-
- public function getConfig(): Config
- {
- return $this->config;
- }
}
diff --git a/lib/Phpfastcache/Drivers/Files/Item.php b/lib/Phpfastcache/Drivers/Files/Item.php
index cd33e92ab..409284558 100644
--- a/lib/Phpfastcache/Drivers/Files/Item.php
+++ b/lib/Phpfastcache/Drivers/Files/Item.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Files;
diff --git a/lib/Phpfastcache/Drivers/Firestore/Config.php b/lib/Phpfastcache/Drivers/Firestore/Config.php
index eb1f6ef0e..3abdddc4b 100644
--- a/lib/Phpfastcache/Drivers/Firestore/Config.php
+++ b/lib/Phpfastcache/Drivers/Firestore/Config.php
@@ -1,4 +1,5 @@
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Firestore;
@@ -29,7 +30,7 @@
/**
* Class Driver
- * @property Config $config
+ * @method Config getConfig()
* @property GoogleFirestoreClient $instance
*/
class Driver implements ExtendedCacheItemPoolInterface, AggregatablePoolInterface
@@ -161,9 +162,4 @@ public function getStats(): DriverStatistic
->setRawData([])
->setSize(0);
}
-
- public function getConfig(): Config
- {
- return $this->config;
- }
}
diff --git a/lib/Phpfastcache/Drivers/Firestore/Item.php b/lib/Phpfastcache/Drivers/Firestore/Item.php
index ed6da627f..673bf2c35 100644
--- a/lib/Phpfastcache/Drivers/Firestore/Item.php
+++ b/lib/Phpfastcache/Drivers/Firestore/Item.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Firestore;
diff --git a/lib/Phpfastcache/Drivers/Leveldb/Config.php b/lib/Phpfastcache/Drivers/Leveldb/Config.php
index f0e71569c..ec59bce2b 100644
--- a/lib/Phpfastcache/Drivers/Leveldb/Config.php
+++ b/lib/Phpfastcache/Drivers/Leveldb/Config.php
@@ -1,4 +1,5 @@
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Leveldb;
@@ -26,8 +27,8 @@
use Phpfastcache\Exceptions\PhpfastcacheLogicException;
/**
- * @property LeveldbClient $instance Instance of driver service
- * @property Config $config
+ * @property LeveldbClient|null $instance Instance of driver service
+ * @method Config getConfig()
*/
class Driver implements ExtendedCacheItemPoolInterface, AggregatablePoolInterface
{
@@ -130,13 +131,8 @@ protected function driverConnect(): bool
throw new PhpfastcacheLogicException('Already connected to Leveldb database');
}
- $this->instance = $this->instance ?: new LeveldbClient($this->getLeveldbFile());
+ $this->instance = new LeveldbClient($this->getLeveldbFile());
return true;
}
-
- public function getConfig(): Config
- {
- return $this->config;
- }
}
diff --git a/lib/Phpfastcache/Drivers/Leveldb/Item.php b/lib/Phpfastcache/Drivers/Leveldb/Item.php
index d1c5e104a..0eea950a2 100644
--- a/lib/Phpfastcache/Drivers/Leveldb/Item.php
+++ b/lib/Phpfastcache/Drivers/Leveldb/Item.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Leveldb;
diff --git a/lib/Phpfastcache/Drivers/Memcache/Config.php b/lib/Phpfastcache/Drivers/Memcache/Config.php
index 9ec4da3b5..31ad3eb66 100644
--- a/lib/Phpfastcache/Drivers/Memcache/Config.php
+++ b/lib/Phpfastcache/Drivers/Memcache/Config.php
@@ -1,4 +1,5 @@
enforceLockedProperty(__FUNCTION__);
$this->host = $host;
-
return $this;
}
diff --git a/lib/Phpfastcache/Drivers/Memcache/Driver.php b/lib/Phpfastcache/Drivers/Memcache/Driver.php
index c23f9ebb9..3020d7686 100644
--- a/lib/Phpfastcache/Drivers/Memcache/Driver.php
+++ b/lib/Phpfastcache/Drivers/Memcache/Driver.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Memcache;
@@ -36,7 +37,7 @@
/**
* @property MemcacheSoftware $instance
- * @property Config $config Return the config object
+ * @method Config getConfig()
*/
class Driver implements ExtendedCacheItemPoolInterface, AggregatablePoolInterface
{
@@ -127,10 +128,12 @@ protected function driverConnect(): bool
* Since Memcached does not throw
* any error if not connected ...
*/
- if (!$this->instance->getServerStatus(
- !empty($server['path']) ? $server['path'] : $server['host'],
- !empty($server['port']) ? $server['port'] : 0
- )) {
+ if (
+ !$this->instance->getServerStatus(
+ !empty($server['path']) ? $server['path'] : $server['host'],
+ !empty($server['port']) ? $server['port'] : 0
+ )
+ ) {
throw new PhpfastcacheDriverException('Memcache seems to not be connected');
}
}
@@ -175,7 +178,7 @@ protected function driverWrite(ExtendedCacheItemInterface $item): bool
/**
* @param ExtendedCacheItemInterface $item
- * @retur n bool
+ * @return bool
* @throws PhpfastcacheInvalidArgumentException
*/
protected function driverDelete(ExtendedCacheItemInterface $item): bool
@@ -192,9 +195,4 @@ protected function driverClear(): bool
{
return $this->instance->flush();
}
-
- public function getConfig(): Config
- {
- return $this->config;
- }
}
diff --git a/lib/Phpfastcache/Drivers/Memcache/Item.php b/lib/Phpfastcache/Drivers/Memcache/Item.php
index a93848b13..f299088b5 100644
--- a/lib/Phpfastcache/Drivers/Memcache/Item.php
+++ b/lib/Phpfastcache/Drivers/Memcache/Item.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Memcache;
diff --git a/lib/Phpfastcache/Drivers/Memcached/Config.php b/lib/Phpfastcache/Drivers/Memcached/Config.php
index 892c43438..fb51d2413 100644
--- a/lib/Phpfastcache/Drivers/Memcached/Config.php
+++ b/lib/Phpfastcache/Drivers/Memcached/Config.php
@@ -1,4 +1,5 @@
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Memcached;
@@ -37,7 +38,7 @@
/**
* @property MemcachedSoftware $instance
- * @property Config $config Return the config object
+ * @method Config getConfig()
*/
class Driver implements ExtendedCacheItemPoolInterface, AggregatablePoolInterface
{
@@ -193,9 +194,4 @@ protected function driverClear(): bool
{
return $this->instance->flush();
}
-
- public function getConfig(): Config
- {
- return $this->config;
- }
}
diff --git a/lib/Phpfastcache/Drivers/Memcached/Item.php b/lib/Phpfastcache/Drivers/Memcached/Item.php
index 1a0eb14d5..cb01697d4 100644
--- a/lib/Phpfastcache/Drivers/Memcached/Item.php
+++ b/lib/Phpfastcache/Drivers/Memcached/Item.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Memcached;
diff --git a/lib/Phpfastcache/Drivers/Memstatic/Config.php b/lib/Phpfastcache/Drivers/Memstatic/Config.php
index 5f0aba2f0..95c983eaa 100644
--- a/lib/Phpfastcache/Drivers/Memstatic/Config.php
+++ b/lib/Phpfastcache/Drivers/Memstatic/Config.php
@@ -1,4 +1,5 @@
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Memstatic;
@@ -25,7 +26,7 @@
/**
* Class Driver
- * @property Config $config
+ * @method Config getConfig()
*/
class Driver implements ExtendedCacheItemPoolInterface
{
@@ -115,9 +116,4 @@ public function getStats(): DriverStatistic
return $stat;
}
-
- public function getConfig(): Config
- {
- return $this->config;
- }
}
diff --git a/lib/Phpfastcache/Drivers/Memstatic/Item.php b/lib/Phpfastcache/Drivers/Memstatic/Item.php
index a393682a3..619c160cb 100644
--- a/lib/Phpfastcache/Drivers/Memstatic/Item.php
+++ b/lib/Phpfastcache/Drivers/Memstatic/Item.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Memstatic;
diff --git a/lib/Phpfastcache/Drivers/Mongodb/Config.php b/lib/Phpfastcache/Drivers/Mongodb/Config.php
index 09aa2ce19..bc444f81f 100644
--- a/lib/Phpfastcache/Drivers/Mongodb/Config.php
+++ b/lib/Phpfastcache/Drivers/Mongodb/Config.php
@@ -1,4 +1,5 @@
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Mongodb;
@@ -38,14 +39,14 @@
/**
* @property Client $instance Instance of driver service
- * @property Config $config Return the config object
+ * @method Config getConfig()
*/
class Driver implements ExtendedCacheItemPoolInterface, AggregatablePoolInterface
{
- public const MONGODB_DEFAULT_DB_NAME = 'phpfastcache'; // Public because used in config
-
use TaggableCacheItemPoolTrait;
+ public const MONGODB_DEFAULT_DB_NAME = 'phpfastcache'; // Public because used in config
+
/**
* @var Collection
*/
@@ -86,8 +87,8 @@ protected function driverConnect(): bool
$databaseName = $this->getConfig()->getDatabaseName();
$driverOptions = $this->getConfig()->getDriverOptions();
- $this->instance = $this->instance ?? new Client($this->buildConnectionURI($databaseName), ['connectTimeoutMS' => $timeout], $driverOptions);
- $this->database = $this->database ?? $this->instance->selectDatabase($databaseName);
+ $this->instance = new Client($this->buildConnectionURI($databaseName), ['connectTimeoutMS' => $timeout], $driverOptions);
+ $this->database = $this->instance->selectDatabase($databaseName);
if (!$this->collectionExists($collectionName)) {
$this->database->createCollection($collectionName);
@@ -161,7 +162,7 @@ protected function driverWrite(ExtendedCacheItemInterface $item): bool
self::DRIVER_CDATE_WRAPPER_INDEX => new UTCDateTime($item->getCreationDate()),
];
}
- $result = (array)$this->getCollection()->updateOne(
+ $result = $this->getCollection()->updateOne(
['_id' => $this->getMongoDbItemKey($item)],
[
'$set' => $set,
@@ -172,7 +173,7 @@ protected function driverWrite(ExtendedCacheItemInterface $item): bool
throw new PhpfastcacheDriverException('Got an exception while trying to write data to MongoDB server: ' . $e->getMessage(), 0, $e);
}
- return !isset($result['ok']) || (int) $result['ok'] === 1;
+ return $result->isAcknowledged();
}
/**
@@ -344,9 +345,4 @@ protected function collectionExists(string $collectionName): bool
return false;
}
-
- public function getConfig(): Config
- {
- return $this->config;
- }
}
diff --git a/lib/Phpfastcache/Drivers/Mongodb/Item.php b/lib/Phpfastcache/Drivers/Mongodb/Item.php
index a71539244..6b5901249 100644
--- a/lib/Phpfastcache/Drivers/Mongodb/Item.php
+++ b/lib/Phpfastcache/Drivers/Mongodb/Item.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Mongodb;
diff --git a/lib/Phpfastcache/Drivers/Predis/Config.php b/lib/Phpfastcache/Drivers/Predis/Config.php
index 0a5a66224..5a5326940 100644
--- a/lib/Phpfastcache/Drivers/Predis/Config.php
+++ b/lib/Phpfastcache/Drivers/Predis/Config.php
@@ -1,4 +1,5 @@
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Predis;
@@ -29,7 +30,7 @@
/**
* @property PredisClient $instance Instance of driver service
- * @property Config $config Return the config object
+ * @method Config getConfig()
*/
class Driver implements ExtendedCacheItemPoolInterface, AggregatablePoolInterface
{
@@ -191,9 +192,4 @@ protected function driverClear(): bool
{
return $this->instance->flushdb()->getPayload() === 'OK';
}
-
- public function getConfig(): Config
- {
- return $this->config;
- }
}
diff --git a/lib/Phpfastcache/Drivers/Predis/Item.php b/lib/Phpfastcache/Drivers/Predis/Item.php
index 0e34bbe32..91de8173d 100644
--- a/lib/Phpfastcache/Drivers/Predis/Item.php
+++ b/lib/Phpfastcache/Drivers/Predis/Item.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Predis;
diff --git a/lib/Phpfastcache/Drivers/Redis/Config.php b/lib/Phpfastcache/Drivers/Redis/Config.php
index c0e40fc0d..cfadc72e4 100644
--- a/lib/Phpfastcache/Drivers/Redis/Config.php
+++ b/lib/Phpfastcache/Drivers/Redis/Config.php
@@ -1,4 +1,5 @@
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Redis;
@@ -27,7 +28,7 @@
/**
* @property \Redis $instance
- * @property Config $config Return the config object
+ * @method Config getConfig()
*/
class Driver implements ExtendedCacheItemPoolInterface, AggregatablePoolInterface
{
@@ -161,7 +162,7 @@ protected function driverDelete(ExtendedCacheItemInterface $item): bool
{
$this->assertCacheItemType($item, Item::class);
- return (bool)$this->instance->del($item->getKey());
+ return (bool) $this->instance->del($item->getKey());
}
/**
@@ -171,9 +172,4 @@ protected function driverClear(): bool
{
return $this->instance->flushDB();
}
-
- public function getConfig(): Config
- {
- return $this->config;
- }
}
diff --git a/lib/Phpfastcache/Drivers/Redis/Item.php b/lib/Phpfastcache/Drivers/Redis/Item.php
index 5e2e343dc..d1c956e88 100644
--- a/lib/Phpfastcache/Drivers/Redis/Item.php
+++ b/lib/Phpfastcache/Drivers/Redis/Item.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Redis;
diff --git a/lib/Phpfastcache/Drivers/Solr/Config.php b/lib/Phpfastcache/Drivers/Solr/Config.php
new file mode 100644
index 000000000..d333e11ba
--- /dev/null
+++ b/lib/Phpfastcache/Drivers/Solr/Config.php
@@ -0,0 +1,212 @@
+
+ * @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
+ */
+
+declare(strict_types=1);
+
+namespace Phpfastcache\Drivers\Solr;
+
+use Phpfastcache\Config\ConfigurationOption;
+use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface;
+use Phpfastcache\Core\Pool\TaggableCacheItemPoolInterface;
+use Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException;
+use Phpfastcache\Exceptions\PhpfastcacheLogicException;
+use Psr\EventDispatcher\EventDispatcherInterface;
+
+class Config extends ConfigurationOption
+{
+ public const DEFAULT_MAPPING_SCHEMA = [
+ Driver::SOLR_DEFAULT_ID_FIELD => Driver::SOLR_DEFAULT_ID_FIELD,
+ Driver::SOLR_DISCRIMINATOR_FIELD => Driver::SOLR_DISCRIMINATOR_FIELD . '_s',
+ ExtendedCacheItemPoolInterface::DRIVER_KEY_WRAPPER_INDEX => ExtendedCacheItemPoolInterface::DRIVER_KEY_WRAPPER_INDEX . '_s',
+ ExtendedCacheItemPoolInterface::DRIVER_DATA_WRAPPER_INDEX => ExtendedCacheItemPoolInterface::DRIVER_DATA_WRAPPER_INDEX . '_s',
+ ExtendedCacheItemPoolInterface::DRIVER_EDATE_WRAPPER_INDEX => ExtendedCacheItemPoolInterface::DRIVER_EDATE_WRAPPER_INDEX . '_s',
+ ExtendedCacheItemPoolInterface::DRIVER_MDATE_WRAPPER_INDEX => ExtendedCacheItemPoolInterface::DRIVER_MDATE_WRAPPER_INDEX . '_s',
+ ExtendedCacheItemPoolInterface::DRIVER_CDATE_WRAPPER_INDEX => ExtendedCacheItemPoolInterface::DRIVER_CDATE_WRAPPER_INDEX . '_s',
+ TaggableCacheItemPoolInterface::DRIVER_TAGS_WRAPPER_INDEX => TaggableCacheItemPoolInterface::DRIVER_TAGS_WRAPPER_INDEX . '_ss',
+ ];
+ protected string $host = '127.0.0.1';
+ protected int $port = 8983;
+ protected string $coreName = 'phpfastcache';
+ protected string $endpointName = 'phpfastcache';
+ protected string $scheme = 'http';
+ protected string $path = '/';
+// Override of ConfigurationOption
+
+ protected array $mappingSchema = self::DEFAULT_MAPPING_SCHEMA;
+ protected EventDispatcherInterface $eventDispatcher;
+ public function __construct(array $parameters = [])
+ {
+ $this->eventDispatcher = $this->getDefaultEventDispatcher();
+ parent::__construct($parameters);
+ }
+
+ /**
+ * @return string
+ */
+ public function getHost(): string
+ {
+ return $this->host;
+ }
+
+ /**
+ * @param string $host
+ * @return Config
+ * @throws PhpfastcacheLogicException
+ */
+ public function setHost(string $host): Config
+ {
+ $this->enforceLockedProperty(__FUNCTION__);
+ $this->host = $host;
+ return $this;
+ }
+
+ /**
+ * @return int
+ */
+ public function getPort(): int
+ {
+ return $this->port;
+ }
+
+ /**
+ * @param int $port
+ * @return Config
+ * @throws PhpfastcacheLogicException
+ */
+ public function setPort(int $port): Config
+ {
+ $this->enforceLockedProperty(__FUNCTION__);
+ $this->port = $port;
+ return $this;
+ }
+
+ /**
+ * @return string
+ */
+ public function getCoreName(): string
+ {
+ return $this->coreName;
+ }
+
+ /**
+ * @param string $coreName
+ * @return Config
+ * @throws PhpfastcacheLogicException
+ */
+ public function setCoreName(string $coreName): Config
+ {
+ $this->enforceLockedProperty(__FUNCTION__);
+ $this->coreName = $coreName;
+ return $this;
+ }
+
+ /**
+ * @return string
+ */
+ public function getScheme(): string
+ {
+ return $this->scheme;
+ }
+
+ /**
+ * @param string $scheme
+ * @return Config
+ * @throws PhpfastcacheLogicException
+ */
+ public function setScheme(string $scheme): Config
+ {
+ $this->enforceLockedProperty(__FUNCTION__);
+ $this->scheme = $scheme;
+ return $this;
+ }
+
+ /**
+ * @return EventDispatcherInterface
+ */
+ public function getEventDispatcher(): EventDispatcherInterface
+ {
+ return $this->eventDispatcher;
+ }
+
+ /**
+ * @return EventDispatcherInterface
+ */
+ protected function getDefaultEventDispatcher(): EventDispatcherInterface
+ {
+ return new class implements EventDispatcherInterface {
+ public function dispatch(object $event): object
+ {
+ return $event;
+ }
+ };
+ }
+
+ /**
+ * @param EventDispatcherInterface $eventDispatcher
+ * @return Config
+ * @throws PhpfastcacheLogicException
+ */
+ public function setEventDispatcher(EventDispatcherInterface $eventDispatcher): Config
+ {
+ $this->enforceLockedProperty(__FUNCTION__);
+ $this->eventDispatcher = $eventDispatcher;
+ return $this;
+ }
+
+ /**
+ * @return string[]
+ */
+ public function getMappingSchema(): array
+ {
+ return $this->mappingSchema;
+ }
+
+ /**
+ * @param string[] $mappingSchema
+ * @return Config
+ * @throws PhpfastcacheLogicException
+ * @throws PhpfastcacheInvalidArgumentException
+ */
+ public function setMappingSchema(array $mappingSchema): Config
+ {
+ $this->enforceLockedProperty(__FUNCTION__);
+ $diff = array_diff(array_keys(self::DEFAULT_MAPPING_SCHEMA), array_keys($mappingSchema));
+ if ($diff) {
+ throw new PhpfastcacheInvalidArgumentException('Missing keys for the solr mapping schema: ' . \implode(', ', $diff));
+ }
+
+ $this->mappingSchema = $mappingSchema;
+ return $this;
+ }
+
+ /**
+ * @return string
+ */
+ public function getEndpointName(): string
+ {
+ return $this->endpointName;
+ }
+
+ /**
+ * @param string $endpointName
+ * @return Config
+ * @throws PhpfastcacheLogicException
+ */
+ public function setEndpointName(string $endpointName): Config
+ {
+ $this->enforceLockedProperty(__FUNCTION__);
+ $this->endpointName = $endpointName;
+ return $this;
+ }
+}
diff --git a/lib/Phpfastcache/Drivers/Solr/Driver.php b/lib/Phpfastcache/Drivers/Solr/Driver.php
new file mode 100644
index 000000000..ab228f4f0
--- /dev/null
+++ b/lib/Phpfastcache/Drivers/Solr/Driver.php
@@ -0,0 +1,287 @@
+
+ * @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
+ */
+
+declare(strict_types=1);
+
+namespace Phpfastcache\Drivers\Solr;
+
+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\PhpfastcacheDriverException;
+use Phpfastcache\Exceptions\PhpfastcacheInvalidTypeException;
+use Phpfastcache\Exceptions\PhpfastcacheLogicException;
+use Solarium\Client as SolariumClient;
+use Solarium\Core\Client\Adapter\Curl as SolariumCurlAdapter;
+use Solarium\Exception\ExceptionInterface as SolariumExceptionInterface;
+use Solarium\QueryType\Select\Result\Document as SolariumDocument;
+
+/**
+ * Class Driver
+ * @property SolariumClient $instance
+ * @method Config getConfig()
+ */
+class Driver implements ExtendedCacheItemPoolInterface, AggregatablePoolInterface
+{
+ use TaggableCacheItemPoolTrait;
+
+ public const MINIMUM_SOLARIUM_VERSION = '6.1.0';
+
+ public const SOLR_DEFAULT_ID_FIELD = 'id';
+
+ public const SOLR_DISCRIMINATOR_FIELD = 'type';
+
+ public const SOLR_DISCRIMINATOR_VALUE = '_pfc_';
+
+ /**
+ * Copy of configuration entry for performance optimization
+ * @var string[]
+ */
+ protected array $mappingSchema = [];
+
+ /**
+ * @return bool
+ * @throws PhpfastcacheDriverCheckException
+ */
+ public function driverCheck(): bool
+ {
+ if (!\class_exists(SolariumClient::class)) {
+ throw new PhpfastcacheDriverCheckException(
+ \sprintf(
+ 'Phpfastcache needs Solarium %s or greater to be installed',
+ self::MINIMUM_SOLARIUM_VERSION
+ )
+ );
+ }
+
+ return true;
+ }
+
+ /**
+ * @return bool
+ * @throws PhpfastcacheDriverConnectException
+ */
+ protected function driverConnect(): bool
+ {
+ $this->mappingSchema = $this->getConfig()->getMappingSchema();
+
+ $endpoint = [
+ 'endpoint' => [
+ $this->getConfig()->getEndpointName() => [
+ 'scheme' => $this->getConfig()->getScheme(),
+ 'host' => $this->getConfig()->getHost(),
+ 'port' => $this->getConfig()->getPort(),
+ 'path' => $this->getConfig()->getPath(),
+ 'core' => $this->getConfig()->getCoreName(),
+ ]
+ ]
+ ];
+
+ $this->eventManager->dispatch(Event::SOLR_BUILD_ENDPOINT, $this, new EventReferenceParameter($endpoint));
+
+ $this->instance = new SolariumClient(new SolariumCurlAdapter(), $this->getConfig()->getEventDispatcher(), $endpoint);
+
+ try {
+ return $this->instance->ping($this->instance->createPing())->getStatus() === 0;
+ } catch (SolariumExceptionInterface $e) {
+ throw new PhpfastcacheDriverConnectException($e->getMessage(), 0, $e);
+ }
+ }
+
+ /**
+ * @param ExtendedCacheItemInterface $item
+ * @return bool
+ * @throws PhpfastcacheLogicException
+ */
+ protected function driverWrite(ExtendedCacheItemInterface $item): bool
+ {
+ $update = $this->instance->createUpdate();
+
+ $doc = $update->createDocument();
+ $doc->{$this->getSolrField(self::SOLR_DEFAULT_ID_FIELD)} = $item->getEncodedKey();
+ $doc->{$this->getSolrField(self::SOLR_DISCRIMINATOR_FIELD)} = self::SOLR_DISCRIMINATOR_VALUE;
+ $doc->{$this->getSolrField(self::DRIVER_KEY_WRAPPER_INDEX)} = $item->getKey();
+ $doc->{$this->getSolrField(self::DRIVER_DATA_WRAPPER_INDEX)} = $this->encode($item->getRawValue());
+ $doc->{$this->getSolrField(self::DRIVER_TAGS_WRAPPER_INDEX)} = $item->getTags();
+ $doc->{$this->getSolrField(self::DRIVER_EDATE_WRAPPER_INDEX)} = $item->getExpirationDate()->format(\DateTimeInterface::ATOM);
+
+ if ($this->getConfig()->isItemDetailedDate()) {
+ $doc->{$this->getSolrField(self::DRIVER_MDATE_WRAPPER_INDEX)} = $item->getModificationDate()->format(\DateTimeInterface::ATOM);
+ $doc->{$this->getSolrField(self::DRIVER_CDATE_WRAPPER_INDEX)} = $item->getCreationDate()->format(\DateTimeInterface::ATOM);
+ }
+
+ $update->addDocument($doc);
+ $update->addCommit();
+
+ return $this->instance->update($update)->getStatus() === 0;
+ }
+
+ /**
+ * @param ExtendedCacheItemInterface $item
+ * @return null|array
+ * @throws \Exception
+ */
+ protected function driverRead(ExtendedCacheItemInterface $item): ?array
+ {
+ $query = $this->instance->createSelect()
+ ->setQuery($this->getSolrField(self::SOLR_DEFAULT_ID_FIELD) . ':' . $item->getEncodedKey())
+ ->setRows(1);
+
+ $results = $this->instance->execute($query);
+
+ if ($results instanceof \IteratorAggregate) {
+ $document = $results->getIterator()[0] ?? null;
+
+ if ($document instanceof SolariumDocument) {
+ return $this->decodeDocument($document);
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * @param SolariumDocument $document
+ * @return array
+ * @throws \Exception
+ */
+ protected function decodeDocument(SolariumDocument $document): array
+ {
+ $fields = $document->getFields();
+ $key = $fields[$this->getSolrField(self::DRIVER_KEY_WRAPPER_INDEX)];
+
+ if (\is_array($key)) {
+ throw new PhpfastcacheInvalidTypeException(
+ 'Your Solr core seems to be misconfigured, please check the Phpfastcache wiki to setup the expected schema:
+ https://github.com/PHPSocialNetwork/phpfastcache/wiki/%5BV9.1%CB%96%5D-Configuring-a-Solr-driver'
+ );
+ }
+
+ $value = [
+ self::DRIVER_KEY_WRAPPER_INDEX => $key,
+ self::DRIVER_TAGS_WRAPPER_INDEX => $fields[$this->getSolrField(self::DRIVER_TAGS_WRAPPER_INDEX)] ?? [],
+ self::DRIVER_DATA_WRAPPER_INDEX => $this->decode(
+ $fields[$this->getSolrField(self::DRIVER_DATA_WRAPPER_INDEX)],
+ ),
+ ];
+
+ $eDate = $fields[$this->getSolrField(self::DRIVER_EDATE_WRAPPER_INDEX)];
+
+ $value[ExtendedCacheItemPoolInterface::DRIVER_EDATE_WRAPPER_INDEX] = new \DateTime($eDate);
+
+ if ($this->getConfig()->isItemDetailedDate()) {
+ $cDate = $fields[$this->getSolrField(self::DRIVER_CDATE_WRAPPER_INDEX)];
+ if (!empty($cDate)) {
+ $value[ExtendedCacheItemPoolInterface::DRIVER_CDATE_WRAPPER_INDEX] = new \DateTime($cDate);
+ }
+
+ $mDate = $fields[$this->getSolrField(self::DRIVER_MDATE_WRAPPER_INDEX)];
+ if (!empty($mDate)) {
+ $value[ExtendedCacheItemPoolInterface::DRIVER_MDATE_WRAPPER_INDEX] = new \DateTime($mDate);
+ }
+ }
+
+ return $value;
+ }
+
+
+ /**
+ * @param ExtendedCacheItemInterface $item
+ * @return bool
+ */
+ protected function driverDelete(ExtendedCacheItemInterface $item): bool
+ {
+ $update = $this->instance->createUpdate();
+
+ $update->addDeleteQuery($this->getSolrField(self::SOLR_DEFAULT_ID_FIELD) . ':' . $item->getEncodedKey());
+ $update->addDeleteQuery($this->getSolrField(self::SOLR_DISCRIMINATOR_FIELD) . ':' . self::SOLR_DISCRIMINATOR_VALUE);
+ $update->addCommit();
+
+ return $this->instance->update($update)->getStatus() === 0;
+ }
+
+ /**
+ * @return bool
+ * @throws PhpfastcacheDriverException
+ */
+ protected function driverClear(): bool
+ {
+ // get an update query instance
+ $update = $this->instance->createUpdate();
+ $update->addDeleteQuery($this->getSolrField(self::SOLR_DISCRIMINATOR_FIELD) . ':' . self::SOLR_DISCRIMINATOR_VALUE);
+ $update->addCommit();
+
+ return $this->instance->update($update)->getStatus() === 0;
+ }
+
+ /**
+ * @param string $pfcField
+ * @return string
+ */
+ protected function getSolrField(string $pfcField): string
+ {
+ return $this->mappingSchema[$pfcField];
+ }
+
+ public function getStats(): DriverStatistic
+ {
+ /**
+ * Solr "phpfastcache" core info
+ */
+ $coreAdminQuery = $this->instance->createCoreAdmin();
+ $statusAction = $coreAdminQuery->createStatus();
+ $coreAdminQuery->setAction($statusAction);
+ $response = $this->instance->coreAdmin($coreAdminQuery);
+ $coreServerInfo = $response->getData()['status'][$this->getConfig()->getCoreName()];
+
+ /**
+ * Unfortunately Solarium does not offer
+ * an API to query the admin info system :(
+ */
+ $adminSystemInfoUrl = $this->getConfig()->getScheme()
+ . '://'
+ . $this->getConfig()->getHost()
+ . ':'
+ . $this->getConfig()->getPort()
+ . rtrim($this->getConfig()->getPath(), '/')
+ . '/solr/admin/info/system';
+
+ if (($content = @\file_get_contents($adminSystemInfoUrl)) !== false) {
+ try {
+ $serverSystemInfo = \json_decode($content, true, 512, \JSON_THROW_ON_ERROR);
+ } catch (\JsonException) {
+ $serverSystemInfo = [];
+ }
+ }
+
+ return (new DriverStatistic())
+ ->setData(implode(', ', array_keys($this->itemInstances)))
+ ->setInfo(sprintf(
+ 'Solarium %s and Solr %s for %s %s. %d document(s) stored in the "%s" core',
+ $this->instance::VERSION,
+ $serverSystemInfo['lucene']['solr-spec-version'] ?? '[unknown SOLR version]',
+ $serverSystemInfo['system']['name'] ?? '[unknown OS]',
+ $serverSystemInfo['system']['version'] ?? '[unknown OS version]',
+ $coreServerInfo['index']['numDocs'] ?? 0,
+ $this->getConfig()->getCoreName()
+ ))
+ ->setRawData($coreServerInfo)
+ ->setSize($coreServerInfo['index']['sizeInBytes'] ?? 0);
+ }
+}
diff --git a/lib/Phpfastcache/Drivers/Solr/Event.php b/lib/Phpfastcache/Drivers/Solr/Event.php
new file mode 100644
index 000000000..d7247d278
--- /dev/null
+++ b/lib/Phpfastcache/Drivers/Solr/Event.php
@@ -0,0 +1,8 @@
+
+ * @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
+ */
+
+declare(strict_types=1);
+
+namespace Phpfastcache\Drivers\Solr;
+
+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/Sqlite/Config.php b/lib/Phpfastcache/Drivers/Sqlite/Config.php
index 97281f497..f6c55774b 100644
--- a/lib/Phpfastcache/Drivers/Sqlite/Config.php
+++ b/lib/Phpfastcache/Drivers/Sqlite/Config.php
@@ -1,4 +1,5 @@
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Sqlite;
@@ -30,7 +31,7 @@
use Psr\Cache\CacheItemInterface;
/**
- * @property Config $config
+ * @method Config getConfig()
*/
class Driver implements ExtendedCacheItemPoolInterface, AggregatablePoolInterface
{
@@ -42,7 +43,7 @@ class Driver implements ExtendedCacheItemPoolInterface, AggregatablePoolInterfac
protected int $currentDB = 1;
- protected string $SqliteDir = '';
+ protected string $sqliteDir = '';
protected ?PDO $indexing;
@@ -62,7 +63,7 @@ public function driverCheck(): bool
*/
public function getSqliteDir(): string
{
- return $this->SqliteDir ?: $this->getPath();
+ return $this->sqliteDir ?: $this->getPath();
}
/**
@@ -83,7 +84,7 @@ protected function driverConnect(): bool
throw new PhpfastcacheIOException(sprintf('Sqlite cannot write in "%s", aborting...', $this->getPath()));
}
- $this->SqliteDir = $this->getPath();
+ $this->sqliteDir = $this->getPath();
return true;
}
@@ -143,10 +144,10 @@ public function getDb(string $keyword, bool $reset = false): PDO
if (!isset($this->instance[$instant])) {
// check DB Files ready or not
$tableCreated = false;
- if ($reset || !file_exists($this->SqliteDir . '/db' . $instant)) {
+ if ($reset || !file_exists($this->sqliteDir . '/db' . $instant)) {
$tableCreated = true;
}
- $pdo = new PDO('sqlite:' . $this->SqliteDir . '/db' . $instant);
+ $pdo = new PDO('sqlite:' . $this->sqliteDir . '/db' . $instant);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if ($tableCreated) {
@@ -169,11 +170,11 @@ public function getDbIndex($keyword)
{
if (!isset($this->indexing)) {
$tableCreated = false;
- if (!file_exists($this->SqliteDir . '/indexing')) {
+ if (!file_exists($this->sqliteDir . '/indexing')) {
$tableCreated = true;
}
- $pdo = new PDO("sqlite:" . $this->SqliteDir . '/' . self::INDEXING_FILE);
+ $pdo = new PDO("sqlite:" . $this->sqliteDir . '/' . self::INDEXING_FILE);
$pdo->setAttribute(
PDO::ATTR_ERRMODE,
PDO::ERRMODE_EXCEPTION
@@ -198,7 +199,7 @@ public function getDbIndex($keyword)
// check file size
- $size = file_exists($this->SqliteDir . '/db' . $db) ? filesize($this->SqliteDir . '/db' . $db) : 1;
+ $size = file_exists($this->sqliteDir . '/db' . $db) ? filesize($this->sqliteDir . '/db' . $db) : 1;
$size = round($size / 1024 / 1024, 1);
@@ -242,10 +243,10 @@ public function getDbIndex($keyword)
public function initIndexing(PDO $db)
{
// delete everything before reset indexing
- $dir = opendir($this->SqliteDir);
+ $dir = opendir($this->sqliteDir);
while ($file = readdir($dir)) {
if ($file !== '.' && $file !== '..' && $file !== 'indexing' && $file !== 'dbfastcache') {
- unlink($this->SqliteDir . '/' . $file);
+ unlink($this->sqliteDir . '/' . $file);
}
}
@@ -337,9 +338,4 @@ protected function driverClear(): bool
return true;
}
-
- public function getConfig(): Config
- {
- return $this->config;
- }
}
diff --git a/lib/Phpfastcache/Drivers/Sqlite/Item.php b/lib/Phpfastcache/Drivers/Sqlite/Item.php
index 979916167..01e2ebd98 100644
--- a/lib/Phpfastcache/Drivers/Sqlite/Item.php
+++ b/lib/Phpfastcache/Drivers/Sqlite/Item.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Sqlite;
diff --git a/lib/Phpfastcache/Drivers/Ssdb/Config.php b/lib/Phpfastcache/Drivers/Ssdb/Config.php
index 1e9989b09..c5c69772d 100644
--- a/lib/Phpfastcache/Drivers/Ssdb/Config.php
+++ b/lib/Phpfastcache/Drivers/Ssdb/Config.php
@@ -1,4 +1,5 @@
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Ssdb;
@@ -30,7 +31,7 @@
/**
* @property SimpleSSDB $instance Instance of driver service
- * @property Config $config Return the config object
+ * @method Config getConfig()
*/
class Driver implements ExtendedCacheItemPoolInterface, AggregatablePoolInterface
{
@@ -135,9 +136,4 @@ protected function driverClear(): bool
// Status not returned, then we assume its true
return true;
}
-
- public function getConfig(): Config
- {
- return $this->config;
- }
}
diff --git a/lib/Phpfastcache/Drivers/Ssdb/Item.php b/lib/Phpfastcache/Drivers/Ssdb/Item.php
index aed4a782b..03d074137 100644
--- a/lib/Phpfastcache/Drivers/Ssdb/Item.php
+++ b/lib/Phpfastcache/Drivers/Ssdb/Item.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Ssdb;
diff --git a/lib/Phpfastcache/Drivers/Wincache/Config.php b/lib/Phpfastcache/Drivers/Wincache/Config.php
index de6453393..512d5ce91 100644
--- a/lib/Phpfastcache/Drivers/Wincache/Config.php
+++ b/lib/Phpfastcache/Drivers/Wincache/Config.php
@@ -1,4 +1,5 @@
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Wincache;
@@ -25,7 +26,7 @@
use Phpfastcache\Exceptions\PhpfastcacheLogicException;
/**
- * @property Config $config Return the config object
+ * @method Config getConfig()
*/
class Driver implements ExtendedCacheItemPoolInterface, AggregatablePoolInterface
{
@@ -110,9 +111,4 @@ protected function driverClear(): bool
{
return wincache_ucache_clear();
}
-
- public function getConfig(): Config
- {
- return $this->config;
- }
}
diff --git a/lib/Phpfastcache/Drivers/Wincache/Item.php b/lib/Phpfastcache/Drivers/Wincache/Item.php
index 212173989..3e6ec7173 100644
--- a/lib/Phpfastcache/Drivers/Wincache/Item.php
+++ b/lib/Phpfastcache/Drivers/Wincache/Item.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Wincache;
diff --git a/lib/Phpfastcache/Drivers/Zenddisk/Config.php b/lib/Phpfastcache/Drivers/Zenddisk/Config.php
index 1989b4385..7ae7742cd 100644
--- a/lib/Phpfastcache/Drivers/Zenddisk/Config.php
+++ b/lib/Phpfastcache/Drivers/Zenddisk/Config.php
@@ -1,4 +1,5 @@
*
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Zenddisk;
@@ -24,7 +25,7 @@
/**
* Requires Zend Data Cache Functions from ZendServer
- * @property Config $config Return the config object
+ * @method Config getConfig()
*/
class Driver implements ExtendedCacheItemPoolInterface, AggregatablePoolInterface
{
@@ -117,9 +118,4 @@ protected function driverClear(): bool
{
return @zend_disk_cache_clear();
}
-
- public function getConfig(): Config
- {
- return $this->config;
- }
}
diff --git a/lib/Phpfastcache/Drivers/Zenddisk/Item.php b/lib/Phpfastcache/Drivers/Zenddisk/Item.php
index ad92d3d3e..f0fba9a9c 100644
--- a/lib/Phpfastcache/Drivers/Zenddisk/Item.php
+++ b/lib/Phpfastcache/Drivers/Zenddisk/Item.php
@@ -2,7 +2,7 @@
/**
*
- * This file is part of phpFastCache.
+ * This file is part of Phpfastcache.
*
* @license MIT License (MIT)
*
@@ -11,6 +11,7 @@
* @author Lucas Brucksch
*
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Zenddisk;
diff --git a/lib/Phpfastcache/Drivers/Zendshm/Config.php b/lib/Phpfastcache/Drivers/Zendshm/Config.php
index 2edce8814..73492526a 100644
--- a/lib/Phpfastcache/Drivers/Zendshm/Config.php
+++ b/lib/Phpfastcache/Drivers/Zendshm/Config.php
@@ -1,4 +1,5 @@
*
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Zendshm;
@@ -24,7 +25,7 @@
/**
* Requires Zend Data Cache Functions from ZendServer
- * @property Config $config Return the config object
+ * @method Config getConfig()
*/
class Driver implements ExtendedCacheItemPoolInterface, AggregatablePoolInterface
{
@@ -115,9 +116,4 @@ protected function driverClear(): bool
{
return @zend_shm_cache_clear();
}
-
- public function getConfig(): Config
- {
- return $this->config;
- }
}
diff --git a/lib/Phpfastcache/Drivers/Zendshm/Item.php b/lib/Phpfastcache/Drivers/Zendshm/Item.php
index c0ca852c8..3af071a71 100644
--- a/lib/Phpfastcache/Drivers/Zendshm/Item.php
+++ b/lib/Phpfastcache/Drivers/Zendshm/Item.php
@@ -2,7 +2,7 @@
/**
*
- * This file is part of phpFastCache.
+ * This file is part of Phpfastcache.
*
* @license MIT License (MIT)
*
@@ -11,6 +11,7 @@
* @author Lucas Brucksch
*
*/
+
declare(strict_types=1);
namespace Phpfastcache\Drivers\Zendshm;
diff --git a/lib/Phpfastcache/Entities/DriverIO.php b/lib/Phpfastcache/Entities/DriverIO.php
index a784c75c5..1d1361cb1 100644
--- a/lib/Phpfastcache/Entities/DriverIO.php
+++ b/lib/Phpfastcache/Entities/DriverIO.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Entities;
diff --git a/lib/Phpfastcache/Entities/DriverStatistic.php b/lib/Phpfastcache/Entities/DriverStatistic.php
index 0e3572187..295c189ef 100644
--- a/lib/Phpfastcache/Entities/DriverStatistic.php
+++ b/lib/Phpfastcache/Entities/DriverStatistic.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Entities;
diff --git a/lib/Phpfastcache/Entities/ItemBatch.php b/lib/Phpfastcache/Entities/ItemBatch.php
index 4902f4a38..4bf172466 100644
--- a/lib/Phpfastcache/Entities/ItemBatch.php
+++ b/lib/Phpfastcache/Entities/ItemBatch.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Entities;
diff --git a/lib/Phpfastcache/Event/Event.php b/lib/Phpfastcache/Event/Event.php
index 059d0b893..9e6b9e5cc 100644
--- a/lib/Phpfastcache/Event/Event.php
+++ b/lib/Phpfastcache/Event/Event.php
@@ -1,4 +1,5 @@
getConstants();
+ }
}
diff --git a/lib/Phpfastcache/Event/EventInterface.php b/lib/Phpfastcache/Event/EventInterface.php
new file mode 100644
index 000000000..1191176c7
--- /dev/null
+++ b/lib/Phpfastcache/Event/EventInterface.php
@@ -0,0 +1,22 @@
+
+ * @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
+ */
+
+declare(strict_types=1);
+
+namespace Phpfastcache\Event;
+
+interface EventInterface
+{
+ public static function getEvents(): array;
+}
diff --git a/lib/Phpfastcache/Event/EventManagerDispatcherInterface.php b/lib/Phpfastcache/Event/EventManagerDispatcherInterface.php
index 233282d63..a026b24c5 100644
--- a/lib/Phpfastcache/Event/EventManagerDispatcherInterface.php
+++ b/lib/Phpfastcache/Event/EventManagerDispatcherInterface.php
@@ -1,4 +1,5 @@
eventManager = $em;
-
return $this;
}
diff --git a/lib/Phpfastcache/Event/EventManagerInterface.php b/lib/Phpfastcache/Event/EventManagerInterface.php
index fefea7941..1241a05ac 100644
--- a/lib/Phpfastcache/Event/EventManagerInterface.php
+++ b/lib/Phpfastcache/Event/EventManagerInterface.php
@@ -1,4 +1,5 @@
parameter);
$newType = \gettype($newValue);
if ($newType !== $currentType) {
- throw new PhpfastcacheInvalidTypeException(
- \sprintf('You tried to change the variable type from "%s" to "%s" which is not allowed.', $currentType, $newType)
- );
+ throw new PhpfastcacheInvalidTypeException(\sprintf(
+ 'You tried to change the variable type from "%s" to "%s" which is not allowed.',
+ $currentType,
+ $newType
+ ));
}
}
diff --git a/lib/Phpfastcache/EventManager.php b/lib/Phpfastcache/EventManager.php
index 00b863768..99f73eaca 100644
--- a/lib/Phpfastcache/EventManager.php
+++ b/lib/Phpfastcache/EventManager.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache;
@@ -18,29 +19,24 @@
use Phpfastcache\Event\EventManagerInterface;
use Phpfastcache\Exceptions\PhpfastcacheEventManagerException;
use Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException;
+use Phpfastcache\Helper\UninstanciableObjectTrait;
class EventManager implements EventManagerInterface
{
+ use UninstanciableObjectTrait;
+
public const ON_EVERY_EVENT = '__every';
- protected static self $instance;
+ protected static EventManagerInterface $instance;
protected array $events = [
self::ON_EVERY_EVENT => []
];
/**
- * EventManager constructor.
- */
- final protected function __construct()
- {
- // The constructor should not be instantiated externally
- }
-
- /**
- * @return static
+ * @return EventManagerInterface
*/
- public static function getInstance(): static
+ public static function getInstance(): EventManagerInterface
{
return (self::$instance ?? self::$instance = new static());
}
@@ -85,7 +81,7 @@ public function dispatch(string $eventName, ...$args): void
*/
public function __call(string $name, array $arguments): void
{
- if (str_starts_with($name, 'on')) {
+ if (\str_starts_with($name, 'on')) {
$name = \substr($name, 2);
if (\is_callable($arguments[0])) {
if (isset($arguments[1]) && \is_string($arguments[0])) {
diff --git a/lib/Phpfastcache/Exceptions/PhpfastcacheCoreException.php b/lib/Phpfastcache/Exceptions/PhpfastcacheCoreException.php
index 15d2229c6..90f3d4df4 100644
--- a/lib/Phpfastcache/Exceptions/PhpfastcacheCoreException.php
+++ b/lib/Phpfastcache/Exceptions/PhpfastcacheCoreException.php
@@ -11,11 +11,11 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Exceptions;
class PhpfastcacheCoreException extends PhpfastcacheRootException
{
-
}
diff --git a/lib/Phpfastcache/Exceptions/PhpfastcacheDeprecatedException.php b/lib/Phpfastcache/Exceptions/PhpfastcacheDeprecatedException.php
index c0792e03f..bbf1f891f 100644
--- a/lib/Phpfastcache/Exceptions/PhpfastcacheDeprecatedException.php
+++ b/lib/Phpfastcache/Exceptions/PhpfastcacheDeprecatedException.php
@@ -11,11 +11,11 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Exceptions;
class PhpfastcacheDeprecatedException extends PhpfastcacheRootException
{
-
}
diff --git a/lib/Phpfastcache/Exceptions/PhpfastcacheDriverCheckException.php b/lib/Phpfastcache/Exceptions/PhpfastcacheDriverCheckException.php
index 1b9a7ea0a..4ca92edbd 100644
--- a/lib/Phpfastcache/Exceptions/PhpfastcacheDriverCheckException.php
+++ b/lib/Phpfastcache/Exceptions/PhpfastcacheDriverCheckException.php
@@ -11,11 +11,11 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Exceptions;
class PhpfastcacheDriverCheckException extends PhpfastcacheDriverException
{
-
}
diff --git a/lib/Phpfastcache/Exceptions/PhpfastcacheDriverConnectException.php b/lib/Phpfastcache/Exceptions/PhpfastcacheDriverConnectException.php
index 7146260fb..3ea062d9e 100644
--- a/lib/Phpfastcache/Exceptions/PhpfastcacheDriverConnectException.php
+++ b/lib/Phpfastcache/Exceptions/PhpfastcacheDriverConnectException.php
@@ -11,11 +11,11 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Exceptions;
class PhpfastcacheDriverConnectException extends PhpfastcacheDriverException
{
-
}
diff --git a/lib/Phpfastcache/Exceptions/PhpfastcacheDriverException.php b/lib/Phpfastcache/Exceptions/PhpfastcacheDriverException.php
index 9c44cf179..32f616390 100644
--- a/lib/Phpfastcache/Exceptions/PhpfastcacheDriverException.php
+++ b/lib/Phpfastcache/Exceptions/PhpfastcacheDriverException.php
@@ -11,11 +11,11 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Exceptions;
class PhpfastcacheDriverException extends PhpfastcacheRootException
{
-
}
diff --git a/lib/Phpfastcache/Exceptions/PhpfastcacheDriverNotFoundException.php b/lib/Phpfastcache/Exceptions/PhpfastcacheDriverNotFoundException.php
index 7626b4764..53f8893b6 100644
--- a/lib/Phpfastcache/Exceptions/PhpfastcacheDriverNotFoundException.php
+++ b/lib/Phpfastcache/Exceptions/PhpfastcacheDriverNotFoundException.php
@@ -11,11 +11,11 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Exceptions;
class PhpfastcacheDriverNotFoundException extends PhpfastcacheDriverException
{
-
}
diff --git a/lib/Phpfastcache/Exceptions/PhpfastcacheEventManagerException.php b/lib/Phpfastcache/Exceptions/PhpfastcacheEventManagerException.php
index fdd9a7582..96d2ae6e6 100644
--- a/lib/Phpfastcache/Exceptions/PhpfastcacheEventManagerException.php
+++ b/lib/Phpfastcache/Exceptions/PhpfastcacheEventManagerException.php
@@ -11,11 +11,11 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Exceptions;
class PhpfastcacheEventManagerException extends PhpfastcacheRootException
{
-
}
diff --git a/lib/Phpfastcache/Exceptions/PhpfastcacheExceptionInterface.php b/lib/Phpfastcache/Exceptions/PhpfastcacheExceptionInterface.php
index 1cfd5bab5..7848ca051 100644
--- a/lib/Phpfastcache/Exceptions/PhpfastcacheExceptionInterface.php
+++ b/lib/Phpfastcache/Exceptions/PhpfastcacheExceptionInterface.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Exceptions;
@@ -19,5 +20,4 @@
interface PhpfastcacheExceptionInterface extends CacheException
{
-
}
diff --git a/lib/Phpfastcache/Exceptions/PhpfastcacheIOException.php b/lib/Phpfastcache/Exceptions/PhpfastcacheIOException.php
index 3f3aceac9..2442e2585 100644
--- a/lib/Phpfastcache/Exceptions/PhpfastcacheIOException.php
+++ b/lib/Phpfastcache/Exceptions/PhpfastcacheIOException.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Exceptions;
diff --git a/lib/Phpfastcache/Exceptions/PhpfastcacheInstanceNotFoundException.php b/lib/Phpfastcache/Exceptions/PhpfastcacheInstanceNotFoundException.php
index 3b6bbb005..1d0a15240 100644
--- a/lib/Phpfastcache/Exceptions/PhpfastcacheInstanceNotFoundException.php
+++ b/lib/Phpfastcache/Exceptions/PhpfastcacheInstanceNotFoundException.php
@@ -11,11 +11,11 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Exceptions;
class PhpfastcacheInstanceNotFoundException extends PhpfastcacheRootException
{
-
}
diff --git a/lib/Phpfastcache/Exceptions/PhpfastcacheInvalidArgumentException.php b/lib/Phpfastcache/Exceptions/PhpfastcacheInvalidArgumentException.php
index 79f744c41..c57f2d3df 100644
--- a/lib/Phpfastcache/Exceptions/PhpfastcacheInvalidArgumentException.php
+++ b/lib/Phpfastcache/Exceptions/PhpfastcacheInvalidArgumentException.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Exceptions;
@@ -19,5 +20,4 @@
class PhpfastcacheInvalidArgumentException extends PhpfastcacheRootException implements InvalidArgumentException
{
-
}
diff --git a/lib/Phpfastcache/Exceptions/PhpfastcacheInvalidConfigurationException.php b/lib/Phpfastcache/Exceptions/PhpfastcacheInvalidConfigurationException.php
index 1f545ae69..6ab816b50 100644
--- a/lib/Phpfastcache/Exceptions/PhpfastcacheInvalidConfigurationException.php
+++ b/lib/Phpfastcache/Exceptions/PhpfastcacheInvalidConfigurationException.php
@@ -11,11 +11,11 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Exceptions;
class PhpfastcacheInvalidConfigurationException extends PhpfastcacheRootException
{
-
}
diff --git a/lib/Phpfastcache/Exceptions/PhpfastcacheInvalidTypeException.php b/lib/Phpfastcache/Exceptions/PhpfastcacheInvalidTypeException.php
index 81efa57ee..c7bd1bf06 100644
--- a/lib/Phpfastcache/Exceptions/PhpfastcacheInvalidTypeException.php
+++ b/lib/Phpfastcache/Exceptions/PhpfastcacheInvalidTypeException.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Exceptions;
@@ -19,5 +20,4 @@
class PhpfastcacheInvalidTypeException extends PhpfastcacheRootException implements InvalidArgumentException
{
-
}
diff --git a/lib/Phpfastcache/Exceptions/PhpfastcacheLogicException.php b/lib/Phpfastcache/Exceptions/PhpfastcacheLogicException.php
index e2772f4c4..7852434a4 100644
--- a/lib/Phpfastcache/Exceptions/PhpfastcacheLogicException.php
+++ b/lib/Phpfastcache/Exceptions/PhpfastcacheLogicException.php
@@ -11,11 +11,11 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Exceptions;
class PhpfastcacheLogicException extends PhpfastcacheRootException
{
-
}
diff --git a/lib/Phpfastcache/Exceptions/PhpfastcacheReplicationException.php b/lib/Phpfastcache/Exceptions/PhpfastcacheReplicationException.php
index 1424175de..ca4cc9cad 100644
--- a/lib/Phpfastcache/Exceptions/PhpfastcacheReplicationException.php
+++ b/lib/Phpfastcache/Exceptions/PhpfastcacheReplicationException.php
@@ -11,11 +11,11 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Exceptions;
class PhpfastcacheReplicationException extends PhpfastcacheRootException
{
-
}
diff --git a/lib/Phpfastcache/Exceptions/PhpfastcacheRootException.php b/lib/Phpfastcache/Exceptions/PhpfastcacheRootException.php
index 077fecaec..091174633 100644
--- a/lib/Phpfastcache/Exceptions/PhpfastcacheRootException.php
+++ b/lib/Phpfastcache/Exceptions/PhpfastcacheRootException.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Exceptions;
@@ -19,5 +20,4 @@
abstract class PhpfastcacheRootException extends Exception implements PhpfastcacheExceptionInterface
{
-
}
diff --git a/lib/Phpfastcache/Exceptions/PhpfastcacheSimpleCacheException.php b/lib/Phpfastcache/Exceptions/PhpfastcacheSimpleCacheException.php
index b5bd47d9d..0782c6df0 100644
--- a/lib/Phpfastcache/Exceptions/PhpfastcacheSimpleCacheException.php
+++ b/lib/Phpfastcache/Exceptions/PhpfastcacheSimpleCacheException.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Exceptions;
@@ -20,5 +21,4 @@
class PhpfastcacheSimpleCacheException extends Exception implements CacheException
{
-
}
diff --git a/lib/Phpfastcache/Exceptions/PhpfastcacheUnsupportedOperationException.php b/lib/Phpfastcache/Exceptions/PhpfastcacheUnsupportedOperationException.php
index abbb7ebbb..5609275a4 100644
--- a/lib/Phpfastcache/Exceptions/PhpfastcacheUnsupportedOperationException.php
+++ b/lib/Phpfastcache/Exceptions/PhpfastcacheUnsupportedOperationException.php
@@ -11,11 +11,11 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Exceptions;
class PhpfastcacheUnsupportedOperationException extends PhpfastcacheRootException
{
-
}
diff --git a/lib/Phpfastcache/Helper/CacheConditionalHelper.php b/lib/Phpfastcache/Helper/CacheConditionalHelper.php
index f50a8e32e..2199fc4e6 100644
--- a/lib/Phpfastcache/Helper/CacheConditionalHelper.php
+++ b/lib/Phpfastcache/Helper/CacheConditionalHelper.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Helper;
diff --git a/lib/Phpfastcache/Helper/Psr16Adapter.php b/lib/Phpfastcache/Helper/Psr16Adapter.php
index 3e4fa13ea..fa9da13dc 100644
--- a/lib/Phpfastcache/Helper/Psr16Adapter.php
+++ b/lib/Phpfastcache/Helper/Psr16Adapter.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Helper;
@@ -188,15 +189,11 @@ public function setMultiple(iterable $values, null|int|\DateInterval $ttl = null
public function deleteMultiple(iterable $keys): bool
{
try {
- if ($keys instanceof Traversable) {
- return $this->internalCacheInstance->deleteItems(\iterator_to_array($keys));
- }
-
if (\is_array($keys)) {
return $this->internalCacheInstance->deleteItems($keys);
}
- throw new PhpfastcacheInvalidArgumentException('$keys must be an array/Traversable instance.');
+ return $this->internalCacheInstance->deleteItems(\iterator_to_array($keys));
} catch (PhpfastcacheInvalidArgumentException $e) {
throw new PhpfastcacheSimpleCacheException($e->getMessage(), 0, $e);
}
diff --git a/lib/Phpfastcache/Helper/UninstanciableObjectTrait.php b/lib/Phpfastcache/Helper/UninstanciableObjectTrait.php
new file mode 100644
index 000000000..43cd7f229
--- /dev/null
+++ b/lib/Phpfastcache/Helper/UninstanciableObjectTrait.php
@@ -0,0 +1,42 @@
+
+ * @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
+ */
+
+declare(strict_types=1);
+
+namespace Phpfastcache\Helper;
+
+use DateInterval;
+use DateTime;
+use Phpfastcache\CacheManager;
+use Phpfastcache\Config\ConfigurationOptionInterface;
+use Phpfastcache\Core\Item\ExtendedCacheItemInterface;
+use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface;
+use Phpfastcache\Exceptions\PhpfastcacheDriverCheckException;
+use Phpfastcache\Exceptions\PhpfastcacheDriverException;
+use Phpfastcache\Exceptions\PhpfastcacheDriverNotFoundException;
+use Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException;
+use Phpfastcache\Exceptions\PhpfastcacheLogicException;
+use Phpfastcache\Exceptions\PhpfastcacheRootException;
+use Phpfastcache\Exceptions\PhpfastcacheSimpleCacheException;
+use Psr\Cache\InvalidArgumentException;
+use Psr\SimpleCache\CacheInterface;
+use Traversable;
+
+trait UninstanciableObjectTrait
+{
+ final protected function __construct()
+ {
+ // The target class is not meant to be instantiated
+ }
+}
diff --git a/lib/Phpfastcache/Proxy/PhpfastcacheAbstractProxy.php b/lib/Phpfastcache/Proxy/PhpfastcacheAbstractProxy.php
index ea6e5ea0b..effcb5b56 100644
--- a/lib/Phpfastcache/Proxy/PhpfastcacheAbstractProxy.php
+++ b/lib/Phpfastcache/Proxy/PhpfastcacheAbstractProxy.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Proxy;
diff --git a/lib/Phpfastcache/Proxy/PhpfastcacheAbstractProxyInterface.php b/lib/Phpfastcache/Proxy/PhpfastcacheAbstractProxyInterface.php
index 48f7807e7..8b2646b49 100644
--- a/lib/Phpfastcache/Proxy/PhpfastcacheAbstractProxyInterface.php
+++ b/lib/Phpfastcache/Proxy/PhpfastcacheAbstractProxyInterface.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Proxy;
diff --git a/lib/Phpfastcache/Util/ClassNamespaceResolverInterface.php b/lib/Phpfastcache/Util/ClassNamespaceResolverInterface.php
index faf2513da..3b7a1aa47 100644
--- a/lib/Phpfastcache/Util/ClassNamespaceResolverInterface.php
+++ b/lib/Phpfastcache/Util/ClassNamespaceResolverInterface.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Util;
diff --git a/lib/Phpfastcache/Util/ClassNamespaceResolverTrait.php b/lib/Phpfastcache/Util/ClassNamespaceResolverTrait.php
index 9149423d4..548d92974 100644
--- a/lib/Phpfastcache/Util/ClassNamespaceResolverTrait.php
+++ b/lib/Phpfastcache/Util/ClassNamespaceResolverTrait.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Util;
diff --git a/lib/Phpfastcache/Util/Directory.php b/lib/Phpfastcache/Util/Directory.php
index 308260385..4a133787e 100644
--- a/lib/Phpfastcache/Util/Directory.php
+++ b/lib/Phpfastcache/Util/Directory.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Util;
diff --git a/lib/Phpfastcache/Util/MemcacheDriverCollisionDetectorTrait.php b/lib/Phpfastcache/Util/MemcacheDriverCollisionDetectorTrait.php
index d32c7b0e2..190ab9998 100644
--- a/lib/Phpfastcache/Util/MemcacheDriverCollisionDetectorTrait.php
+++ b/lib/Phpfastcache/Util/MemcacheDriverCollisionDetectorTrait.php
@@ -11,6 +11,7 @@
* @author Georges.L (Geolim4)
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
*/
+
declare(strict_types=1);
namespace Phpfastcache\Util;
diff --git a/lib/Phpfastcache/Util/SapiDetector.php b/lib/Phpfastcache/Util/SapiDetector.php
index 329bd98a1..894466c44 100644
--- a/lib/Phpfastcache/Util/SapiDetector.php
+++ b/lib/Phpfastcache/Util/SapiDetector.php
@@ -1,4 +1,5 @@
-
+
tests/*
bin/*
diff --git a/phpstan.neon b/phpstan.neon
index 1bb6198d2..2bf5e1b65 100644
--- a/phpstan.neon
+++ b/phpstan.neon
@@ -11,3 +11,9 @@ parameters:
-
message: '#Cannot call method getPayload\(\) on int#' # Issue in predis/predis => https://github.com/predis/predis/pull/710
path: lib/Phpfastcache/Drivers/Predis/Driver.php
+ -
+ message: '#Cannot assign offset (.*) to string|Offset (.*) on string#' # Issue in arangodb/arangodb-php => https://github.com/arangodb/arangodb-php/issues/293
+ path: lib/Phpfastcache/Drivers/Arangodb/Driver.php
+ -
+ message: '#(.*)class is deprecated and will be removed in v10(.*)#'
+ path: lib/Phpfastcache/Config/Config.php
diff --git a/phpstan_lite.neon b/phpstan_lite.neon
index 52afa2636..815390f0a 100644
--- a/phpstan_lite.neon
+++ b/phpstan_lite.neon
@@ -8,3 +8,6 @@ parameters:
- lib/Phpfastcache/Drivers/*/Config.php
ignoreErrors:
- '#PHPDoc tag @(.*)#' # (Really) Annoying PHPDoc tag issues...
+ -
+ message: '#(.*)class is deprecated and will be removed in v10(.*)#'
+ path: lib/Phpfastcache/Config/Config.php
diff --git a/quality.bat b/quality.bat
index fb6be7f2a..b861dbf8b 100644
--- a/quality.bat
+++ b/quality.bat
@@ -4,6 +4,6 @@ setlocal
call vendor\bin\phpcbf lib/ --report=summary
call vendor\bin\phpcs lib/ --report=summary
call vendor\bin\phpmd lib/ ansi phpmd.xml
-call vendor\bin\phpstan analyse lib/ -l 2 -c phpstan.neon 2>&1
+call vendor\bin\phpstan analyse lib/ -l 4 -c phpstan.neon 2>&1
endlocal
diff --git a/tests/ClusterFullReplication.test.php b/tests/ClusterFullReplication.test.php
index 6f0e12437..7909b9898 100644
--- a/tests/ClusterFullReplication.test.php
+++ b/tests/ClusterFullReplication.test.php
@@ -28,7 +28,6 @@
$clusterAggregator->aggregateDriver(CacheManager::getInstance('Files'));
$clusterAggregator->aggregateDriver(CacheManager::getInstance('Sqlite'));
$cluster = $clusterAggregator->getCluster(AggregatorInterface::STRATEGY_FULL_REPLICATION);
-$cluster->clear();
$testHelper->runCRUDTests($cluster);
diff --git a/tests/ClusterSemiReplication.test.php b/tests/ClusterSemiReplication.test.php
index 5a11cfdc4..05b100c83 100644
--- a/tests/ClusterSemiReplication.test.php
+++ b/tests/ClusterSemiReplication.test.php
@@ -1,4 +1,4 @@
-ClusterFullReplication.test.phpassertFail('The php classes of driver "Files2" does not exists');
+ $testHelper->assertFail('The php classes of driver "Files2" do not exist');
$testHelper->terminateTest();
} else {
$testHelper->assertPass('The php classes of driver "Files2" were found');
diff --git a/tests/CustomDriver.test.php b/tests/CustomDriver.test.php
index d087d2381..c8a0e5997 100644
--- a/tests/CustomDriver.test.php
+++ b/tests/CustomDriver.test.php
@@ -27,7 +27,7 @@
|| !class_exists(Phpfastcache\Drivers\Fakefiles\Driver::class)
|| !class_exists(Phpfastcache\Drivers\Fakefiles\Config::class)
) {
- $testHelper->assertFail('The php classes of driver "Fakefiles" does not exists');
+ $testHelper->assertFail('The php classes of driver "Fakefiles" do not exist');
$testHelper->terminateTest();
} else {
$testHelper->assertPass('The php classes of driver "Fakefiles" were found');
diff --git a/tests/DisabledStaticItemCaching.test.php b/tests/DisabledStaticItemCaching.test.php
index 8d5089315..02cdf03d2 100644
--- a/tests/DisabledStaticItemCaching.test.php
+++ b/tests/DisabledStaticItemCaching.test.php
@@ -42,7 +42,7 @@
$testHelper->runSubProcess('DisabledStaticItemCaching');
usleep(random_int(250000, 800000));
- // We dont want to clear cache instance since we disabled the static item caching
+ // We don't want to clear cache instance since we disabled the static item caching
$item = $driverInstance->getItem('TestUseStaticItemCaching');
/**
diff --git a/tests/ReadWriteOperations.test.php b/tests/ReadWriteOperations.test.php
index 3afe1abdf..6a0891217 100644
--- a/tests/ReadWriteOperations.test.php
+++ b/tests/ReadWriteOperations.test.php
@@ -48,6 +48,7 @@
$instances[ $dirIndex ][ $cacheInstanceName ] = CacheManager::getInstance('Files', new FilesConfig([
'path' => $dir . str_pad($i, 3, '0', STR_PAD_LEFT),
'secureFileManipulation' => true,
+ 'cacheFileExtension' => 'pfc',
'securityKey' => '_cache',
]));
diff --git a/tests/Solr.test.php b/tests/Solr.test.php
new file mode 100644
index 000000000..1fb0c820c
--- /dev/null
+++ b/tests/Solr.test.php
@@ -0,0 +1,68 @@
+
+ * @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
+ */
+
+use Phpfastcache\CacheManager;
+use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface;
+use Phpfastcache\Event\EventReferenceParameter;
+use Phpfastcache\EventManager;
+use Phpfastcache\Tests\Helper\TestHelper;
+use Phpfastcache\Drivers\Solr\Config as SolrConfig;
+
+chdir(__DIR__);
+require_once __DIR__ . '/../vendor/autoload.php';
+$testHelper = new TestHelper('Solr driver');
+
+/** @var SolrConfig $solrConfig */
+$solrConfig = $testHelper->preConfigure(new SolrConfig());
+$solrConfig->setCoreName('phpfastcache'); // Optional: Default value
+$solrConfig->setPort(8983); // Optional: Default value
+$solrConfig->setHost('127.0.0.1'); // Optional: Default value
+$solrConfig->setPath('/'); // Optional: Default value
+$solrConfig->setScheme('http'); // Optional: Default value
+
+
+/**
+ * Optional:
+ *
+ * You can change the mapping schema used by Phpfastcache.
+ * The keys are the Phpfastcache internal index. All required.
+ * The values are the name of your Solr schema.
+ */
+$solrConfig->setMappingSchema($solrConfig::DEFAULT_MAPPING_SCHEMA);
+
+/**
+ * Optional:
+ *
+ * You can change the PSR-14 event dispatcher service used (and required) by solarium, by your own one.
+ */
+// $solrConfig->setEventDispatcher($yourEventDispatcher);
+
+/**
+ * Test of custom events
+ */
+$onSolrBuildEndpointCalled = false;
+EventManager::getInstance()->onSolrBuildEndpoint(static function () use (&$onSolrBuildEndpointCalled, $testHelper){
+ $testHelper->assertPass('Event "onSolrBuildEndpoint" has been called.');
+ $onSolrBuildEndpointCalled = true;
+});
+
+$cacheInstance = CacheManager::getInstance('Solr', $solrConfig);
+
+if(!$onSolrBuildEndpointCalled) {
+ $testHelper->assertFail('Event "onSolrBuildEndpoint" has NOT been called.');
+}
+
+$testHelper->runCRUDTests($cacheInstance);
+
+$testHelper->terminateTest();
diff --git a/tests/lib/Helper/TestHelper.php b/tests/lib/Helper/TestHelper.php
index 1f67efb1a..c80449a00 100644
--- a/tests/lib/Helper/TestHelper.php
+++ b/tests/lib/Helper/TestHelper.php
@@ -17,6 +17,7 @@
use League\CLImate\CLImate;
use Phpfastcache\Api;
+use Phpfastcache\Config\ConfigurationOptionInterface;
use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface;
use Phpfastcache\Event\EventManagerInterface;
use Phpfastcache\Exceptions\PhpfastcacheDriverCheckException;
@@ -304,8 +305,12 @@ public function accessInaccessibleMember($obj, $prop): mixed
*/
public function errorHandler(int $errno, string $errstr, string $errfile, int $errline): void
{
- $errorType = '';
+ // Silenced errors
+ if (!(error_reporting() & $errno)){
+ return;
+ }
+ $errorType = '';
switch ($errno) {
case E_PARSE:
case E_ERROR:
@@ -392,6 +397,18 @@ public function runCRUDTests(ExtendedCacheItemPoolInterface|PhpfastcacheAbstract
$cacheItem = $pool->getItem($cacheKey);
$this->printInfoText('Using cache key: ' . $cacheKey);
+ /**
+ * Default TTL - 1sec is for dealing with potential script execution delay
+ * @see https://github.com/PHPSocialNetwork/phpfastcache/issues/855
+ */
+ if($cacheItem->getTtl() < $pool->getConfig()->getDefaultTtl() - 1) {
+ $this->assertFail(\sprintf(
+ 'The expected TTL of the cache item was ~%ds, got %ds',
+ $pool->getConfig()->getDefaultTtl(),
+ $cacheItem->getTtl()
+ ));
+ }
+
$cacheItem->set($cacheValue)
->addTags([$cacheTag, $cacheTag2]);
@@ -502,7 +519,7 @@ public function runCRUDTests(ExtendedCacheItemPoolInterface|PhpfastcacheAbstract
}
if ($poolClear) {
- if ($pool->deleteItem($cacheKey)) {
+ if ($pool->deleteItem($cacheKey) && !$pool->getItem($cacheKey)->isHit()) {
$this->assertPass('The pool successfully deleted the cache item.');
} else {
$this->assertFail('The pool failed to delete the cache item.');
@@ -534,6 +551,11 @@ public function runCRUDTests(ExtendedCacheItemPoolInterface|PhpfastcacheAbstract
)
);
$this->printInfoText('Driver info: ' . $pool->getStats()->getInfo() . '');
+ $poolSize = $pool->getStats()->getSize();
+
+ if($poolSize){
+ $this->printInfoText('Driver size (approximative): ' . round($pool->getStats()->getSize() / (1024 ** 2), 3) . ' Mo');
+ }
}
@@ -574,4 +596,12 @@ static function ($str) use ($minBlockLength) {
)
);
}
+
+ public function preConfigure(ConfigurationOptionInterface $configurationOption): ConfigurationOptionInterface
+ {
+ $configurationOption->setItemDetailedDate(true)
+ ->setUseStaticItemCaching(false);
+
+ return $configurationOption;
+ }
}