Rework of events (WIP) · TruCopilot/phpfastcache@9448a0c · GitHub
Skip to content

Commit 9448a0c

Browse files
committed
Rework of events (WIP)
1 parent a30ad45 commit 9448a0c

73 files changed

Lines changed: 1056 additions & 786 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/testsv2.yml‎

Lines changed: 1 addition & 1 deletion

‎CHANGELOG.md‎

Lines changed: 12 additions & 185 deletions
Original file line numberDiff line numberDiff line change
@@ -1,189 +1,16 @@
1-
## 9.2.3
2-
##### 11 january 2024
3-
- __Drivers__
4-
- **Added support of `Ravendb` as an extension with its own [sub-repository](https://github.com/PHPSocialNetwork/ravendb-extension).**
5-
- Deprecated `\Phpfastcache\Entities\DriverStatistic::getData()`. Will be removed as of v10.
6-
- Deprecated `\Phpfastcache\Entities\DriverStatistic::setData()`. Will be removed as of v10.
7-
- Added `\Phpfastcache\Entities\DriverStatistic::getCount(): int|null`. If applicable will return the count of cache objects stored in driver database/collection. Null otherwise.
8-
- Added `\Phpfastcache\Entities\DriverStatistic::setCount()`
9-
10-
## 9.2.2
11-
##### 11 january 2024
12-
- __Core__
13-
- Added optional prefix to `\Phpfastcache\Core\Pool\CacheItemPoolTrait::getKeys()`
14-
15-
## 9.2.1
16-
##### 07 january 2024
17-
- __Misc__
18-
- Added additional check in cache manager for extensions
19-
20-
## 9.2.0
21-
##### 07 january 2024
22-
- __API__
23-
- Upgraded Phpfastcache API to `4.3.0` ([see changes](CHANGELOG_API.md))
24-
- __Extensions__ (💡 New in 9.2)
25-
- Created an extension mechanism to allow some drivers to be loaded independently, see [README.md](README.md)
26-
- Added support of `Couchbasev4` as an extension with its own [sub-repository](https://github.com/PHPSocialNetwork/couchbasev4-extension).
27-
- **IMPORTANT**: *AS OF v9.2* the following drivers has been **MOVED** to their own sub-repositories as a standalone extension: `Arangodb`, `Couchdb`, `Dynamodb`, `Firestore`, `Mongodb`, `Solr`. However `Couchbasev3` will stay in the core for compatibility reasons but will be deprecated.
28-
- **IMPORTANT**: *AS OF v10* extensions will have their namespaces permanently moved from `Phpfastcache\Drivers\EXT_NAME\{Config, Driver, Event, Item}` to `Phpfastcache\Extensions\Drivers\EXT_NAME\{Config, Driver, Event, Item}`. For now an alias is ensuring compatibility.
29-
- __Events__
30-
- EventManager is now scoped to its own poll if retrieved through `ExtendedCacheItemPoolTrait::->getEventManager()`. Global EventManager `EventManager::getInstance()` remains unchanged, see [EVENTS.md](./docs/EVENTS.md).
31-
- `EventManagerInterface::on()` now also accepts a single `string $events`.
32-
- Alias `\Phpfastcache\PhpfastcacheEventManager` of `\Phpfastcache\EventManager` has been added to improve your code import readability.
33-
- Deprecated `\Phpfastcache\Event\EventManagerDispatcherInterface::hasEventManager` to be removed for v10.
34-
- __Drivers__
35-
- Implemented #906 // **Added `RedisCluster` driver support**
36-
- Driver `Memstatic` has changed its name to `Memory` for more consistency.
37-
- Driver `Wincache` is now deprecated and will be removed as of v10 due to the lack of updates to PHP 8 [as officially stated by PHP](https://www.php.net/manual/en/install.windows.recommended.php).
38-
- __Pool__
39-
- Added `ExtendedCacheItemPoolTrait::getAllItems` to allow you to retrieve all items in the cache. This method have some limitations, ([see more in the Wiki](https://github.com/PHPSocialNetwork/phpfastcache/wiki/%5BV5%CB%96%5D-Fetching-all-keys)).
40-
- __Core__
41-
- Configuration methods`ConfigurationOption::isPreventCacheSlams()`, `ConfigurationOption::setPreventCacheSlams()`, `ConfigurationOption::getCacheSlamsTimeout()`, `ConfigurationOption::setCacheSlamsTimeout()` are deprecated. ([See changes](CHANGELOG_API.md)).
42-
- Fixed #907 // Internal "driver decode()" method will now throw an if the string data looks corrupted.
43-
- Internal: Implemented multiple keys fetch (*if supported by the backend*) to improve the performances behind all `getItems()` calls. Currently only supported in some backends, but it may evolve in the future.
44-
- Internal: Implemented multiple keys delete (*if supported by the backend*) to improve the performances behind all `deleteItems()` calls. Currently only supported in some backends, but it may evolve in the future.
45-
- `\Phpfastcache\CacheContract::get()` now accepts a `\Stringable $cacheKey` argument.
46-
- __Tags__
47-
- Added `\Phpfastcache\Core\Item\TaggableCacheItemInterface::isTagged(): bool`
48-
- __Misc__
49-
- Fixed multiple code typo & updated README.md
50-
51-
## 9.1.3
52-
##### 12 february 2023
53-
- __Core__
54-
- Fixed #893 // getItemsByTag() - empty after one item has expired
55-
- __Misc__
56-
- Fixed multiple code typo & updated README.md
57-
58-
## 9.1.2
59-
##### 09 june 2022
60-
- __API__
61-
- Upgraded Phpfastcache API to `4.2.0` ([see changes](CHANGELOG_API.md))
62-
- __Core__
63-
- Rewrote some core code to improve code maintainability & readability following Scrutinizer and Phpstan recommendations
64-
- Fixed an issue with tags not properly reinitialized when a backend driver returns an expired cache item
65-
- __Drivers__
66-
- Fixed #866 // Deprecated Method Cassandra\ExecutionOptions starting of Cassandra 1.3
67-
- __Misc__
68-
- Increased PHPSTAN level to 6
69-
- Fixed multiple fails of Travis CI
70-
- Migrated Github issue templates from Markdown to YAML configurations
71-
72-
## 9.1.1
73-
##### 15 april 2022
1+
## 10.0.0
2+
##### xx xxxxxxx xxxx
743
- __Core__
75-
- Fixed #860 // Cache item throw an error on reading with DateTimeImmutable date objects
76-
- Fixed an issue with tags not properly reinitialized when a backend driver returns an expired cache item
77-
- __Drivers__
78-
- Fixed #862 // Multiple driver errors caused by invalid return type of `driverRead()` (reported by @ShockedPlot7560 and @aemla)
79-
80-
## 9.1.0
81-
##### 04 april 2022
82-
- __API__
83-
- Upgraded Phpfastcache API to `4.1.0` ([see changes](CHANGELOG_API.md))
84-
- __Core__
85-
- Added `\Phpfastcache\Helper\UninstanciableObjectTrait` trait which will contains base locked constructor for any classes that are nor meant to be instanciated.
86-
- Deprecated `\Phpfastcache\Config\Config::class`
87-
- Removed/reworked/improved dead/unreachable/redundant/obsolete code, thanks to `Phpstan`
88-
- __Drivers__
89-
- **Added `Solr` driver support**
90-
- __Events__
91-
- Added `\Phpfastcache\Event\EventInterface` for `\Phpfastcache\Event\Event` and subclasses below
92-
- Added `\Phpfastcache\Drivers\Arangodb\Event` for Arangodb events
93-
- Added `\Phpfastcache\Drivers\Dynamodb\Event` for Dynamodb events
94-
- Added `\Phpfastcache\Drivers\Solr\Event` for Solr events
95-
- Moved the following constant from `\Phpfastcache\Event\Event` to their respective drivers: `ARANGODB_CONNECTION`, `ARANGODB_COLLECTION_PARAMS`, `DYNAMODB_CREATE_TABLE`
96-
- __Cluster__
97-
- Fixed #855 // ClusterReplication drivers are saving erroneous expiration date in low-level backends
98-
- __Misc__
99-
- Full PSR-12 compliance is now enforced by PHPCS
100-
- Multiple typo fixes (@mbiebl)
101-
- Updated composer suggestions and CI builder dependencies
102-
103-
## 9.0.2
104-
##### 04 march 2022
105-
- __Core__
106-
- Updated CacheContract::__invoke() signature
107-
- Added new option to allow EventManager override + improved EventManager tests (EventManager::setInstance())
108-
- __Drivers__
109-
- Fixed #853 // Configuration validation issue with Memcached socket (path)
110-
- __Misc__
111-
- Fixed typo and some types hint
112-
113-
## 9.0.1
114-
##### 14 november 2021
115-
- __Core__
116-
- Added `\Phpfastcache\Event\Event` class for centralizing event name with reusable constants.
117-
- __Item__
118-
- `\Psr\Cache\CacheItemInterface::set` will also no longer accepts resource object anymore as method unique parameter
119-
- __Misc__
120-
- Fixed typos in [README.md](./README.md)
121-
122-
## 9.0.0
123-
##### 31 october 2021
124-
- __Migration guide__
125-
- Read the [migration guide](./docs/migration/MigratingFromV8ToV9.md) to upgrade from V8 to V9
126-
- __PSR-6__
127-
- Upgraded `psr/cache` dependency to `^2.0||^3.0` (for PHP-8 types)
128-
- `\Psr\Cache\CacheItemInterface::get()` slightly changed to fully comply with missing PSR-6 specification: If the cache item is **NOT** hit, this method will return `NULL`.
129-
- __PSR-16__
130-
- Upgraded `psr/simple-cache` dependency to `^2.0||^3.0` (for PHP-8 types)
131-
- __API__
132-
- Upgraded Phpfastcache API to `4.0.0` ([see changes](CHANGELOG_API.md))
133-
- Renamed `Api::getPhpFastCacheVersion()` to `Api::getPhpfastcacheVersion()`
134-
- Renamed `Api::getPhpFastCacheChangelog()` to `Api::getPhpfastcacheChangelog()`
135-
- Renamed `Api::getPhpFastCacheGitHeadHash()` to `Api::getPhpfastcacheGitHeadHash()`
136-
- __Cluster__
137-
- Renamed `\Phpfastcache\Cluster\AggregatorInterface::aggregateNewDriver()` to `\Phpfastcache\Cluster\AggregatorInterface::aggregateDriverByName()`
138-
- __Exceptions__
139-
- Added `PhpfastcacheEventManagerException` for EventManager-related exceptions
140-
- __Global__
141-
- Removed magics methods from CacheManager `CacheManager::DriverName()`, use `CacheManager::getInstance('DriverName')` instead
142-
- `\Phpfastcache\Proxy\PhpfastcacheAbstractProxy` now implements `\Phpfastcache\Proxy\PhpfastcacheAbstractProxyInterface`
143-
- Slightly increased performances on some critical points of the library
144-
- Removed "BadPracticeOMeter" notice in CacheManager
145-
- Removed many code duplicate (like in `\Phpfastcache\Driver\[DRIVER_NAME]\Item` classes)
146-
- Reworked traits inter-dependencies for better logic and less polymorphic calls in pool/item traits
147-
- Upgrading library to use benefits of PHP 8 new features (see below)
148-
- Typed every class properties of the library
149-
- Migrated many Closure to arrow functions
150-
- Updated parameters & return type hint to use benefit of covariance and contravariance
151-
- Removed embedded Autoload, Phpfastcache is now only Composer-compatible.
152-
- Removed embedded dependencies (`psr/cache`, `psr/simple-cache`)
4+
- Removed deprecated methods`ConfigurationOption::isPreventCacheSlams()`, `ConfigurationOption::setPreventCacheSlams()`, `ConfigurationOption::getCacheSlamsTimeout()`, `ConfigurationOption::setCacheSlamsTimeout()`. ([See changes](CHANGELOG_API.md)).
5+
Removed deprecated class `\Phpfastcache\Config\Config::class`.
1536
- __Helpers__
154-
- Deprecated `\Phpfastcache\Helper\CacheConditionalHelper`, use `\Phpfastcache\CacheContract` instead
155-
- The `\Phpfastcache\CacheContract` class is now also callable directly without calling `get()` method
156-
- __Config/Options__
157-
- Configuration object will now be locked once the cache pool instance is running.
158-
- Updated `ConfigurationOption` which is no longer an `ArrayObject` class, therefore array-syntax is no longer available.
159-
- Removed configuration entry `htaccess` for files-based drivers.
160-
- Removed `IOConfigurationOptionTrait::getHtaccess()`
161-
- Removed `IOConfigurationOptionTrait::setHtaccess()`
162-
- __Tests__
163-
- Added PHPMD, PHPCS and PHPSTAN coverages to increase quality of the project
164-
- Updated tests to work with new core/drivers changes
165-
- Removed Autoload test since its support has been removed and now only managed by Composer
166-
- Increased tests reliability and code coverage for better catching any eventual regression
167-
- __Item__
168-
- `\Psr\Cache\CacheItemInterface::set` will not accept `\Closure` object anymore as method unique parameter
7+
- Removed `\Phpfastcache\Helper\CacheConditionalHelper`. Use `\Phpfastcache\CacheContract` instead.
1698
- __Drivers__
170-
- Added `Arangodb` driver support
171-
- Added `Dynamodb` (AWS) driver support
172-
- Added `Firestore` (GCP) driver support
173-
- Removed `Cookie` driver because of its potential dangerosity
174-
- Removed `Couchbase` (SDK 2 support dropped) driver which is now replaced by `Couchbasev3` (SDK 3)
175-
- Removed `Devtrue` and `Devfalse` drivers
176-
- Added `Devrandom` with configurable factor chance and data length
177-
- Renamed classes `\Phpfastcache\Cluster\Drivers\[STATEGY]\[CLUSTER_NAME]Cluster` to `\Phpfastcache\Cluster\Drivers\[STATEGY]\Driver` for better driver naming across the project
9+
- Removed deprecated method `\Phpfastcache\Entities\DriverStatistic::getData()`.
10+
- Removed deprecated method `\Phpfastcache\Entities\DriverStatistic::setData()`.
17811
- __Events__
179-
- Added `\Phpfastcache\Event\EventReferenceParameter` class and more events such as driver-specific events, see [EVENTS.md](./docs/EVENTS.md) file for more information
180-
- Event callbacks will now receive the `eventName` as an extra _last_ callback parameter (except for `onEveryEvents` callbacks)
181-
- Added `EventManagerInterface::on(array $eventNames, $callback)` method, to subscribe to multiple events in once with the same callback
182-
- Added method named `unbindAllEventCallbacks(): bool` to `EventManagerInterface` to allow you to unbind/clear all event from an event instance
183-
- Updated argument type #2 (`$items`) of `onCacheSaveMultipleItems()` event from `ExtendedCacheItemInterface[]` to `EventReferenceParameter($items)`
184-
- Updated argument type #2 (`$items`) of `onCacheCommitItem()` event from `ExtendedCacheItemInterface[]` to `EventReferenceParameter($items)`
185-
- Updated argument type #2 (`$value`) of `onCacheItemSet()` event from `mixed` to `EventReferenceParameter(mixed $value)`
186-
- __Misc__
187-
- Increased minimum PHP compatibility in composer to `^8.0`
188-
- Updated copyright headers on every file to include the many project contributors
189-
- Globally renamed every occurrence of `PhpFastCache` to `Phpcastcache`
12+
- Phpfastcache EventManager is now [PSR-14](https://www.php-fig.org/psr/psr-14/) compliant. Therefore, its API has slightly changed and may not be backward-compatible.
13+
- Removed deprecated method `\Phpfastcache\Event\EventManagerDispatcherInterface::hasEventManager`.
14+
- __Drivers__
15+
- Removed driver `Memstatic`. Use `Memory` instead.
16+
- Removed driver `Wincache`.

‎composer.json‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"homepage": "https://www.phpfastcache.com",
77
"license": "MIT",
88
"readme": "README.md",
9-
"minimum-stability": "stable",
9+
"minimum-stability": "dev",
1010
"authors": [
1111
{
1212
"name": "Georges.L",
@@ -21,14 +21,16 @@
2121
],
2222
"provide": {
2323
"psr/cache-implementation": "2.0|3.0",
24-
"psr/simple-cache-implementation": "2.0|3.0"
24+
"psr/simple-cache-implementation": "2.0|3.0",
25+
"psr/event-dispatcher-implementation": "^1.0"
2526
},
2627
"require": {
27-
"php": ">=8.0",
28+
"php": ">=8.2",
2829
"psr/cache": "^2.0||^3.0",
2930
"psr/simple-cache": "^2.0||^3.0",
3031
"ext-mbstring": "*",
31-
"ext-json": "*"
32+
"ext-json": "*",
33+
"psr/event-dispatcher": "^1.0"
3234
},
3335
"require-dev": {
3436
"league/climate": "^3.8",
@@ -37,7 +39,7 @@
3739
"squizlabs/php_codesniffer": "@stable",
3840
"phpstan/phpstan": "@stable",
3941
"jetbrains/phpstorm-stubs": "dev-master",
40-
"phpfastcache/phpfastcache-devtools": "dev-master"
42+
"phpfastcache/phpfastcache-devtools": "^10.0.0-ALPHA"
4143
},
4244
"suggest": {
4345
"ext-apcu": "*",

‎lib/Phpfastcache/Cluster/ClusterAggregator.php‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
use Exception;
2020
use Phpfastcache\CacheManager;
2121
use Phpfastcache\Config\ConfigurationOption;
22-
use Phpfastcache\Event\Event;
22+
use Phpfastcache\Event\Event\CacheItemPoolEventClusterBuilt;
23+
use Phpfastcache\Event\Events;
2324
use Phpfastcache\EventManager;
2425
use Phpfastcache\Exceptions\PhpfastcacheDriverCheckException;
2526
use Phpfastcache\Exceptions\PhpfastcacheDriverException;
@@ -151,7 +152,7 @@ public function getCluster(int $strategy = AggregatorInterface::STRATEGY_FULL_RE
151152
...\array_values($this->driverPools)
152153
);
153154

154-
$this->cluster->getEventManager()->dispatch(Event::CACHE_CLUSTER_BUILT, $this, $this->cluster);
155+
$this->cluster->getEventManager()->dispatch(new CacheItemPoolEventClusterBuilt($this->cluster, $this));
155156
}
156157
} else {
157158
throw new PhpfastcacheInvalidArgumentException('Unknown cluster strategy');

‎lib/Phpfastcache/Cluster/ClusterPoolAbstract.php‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -235,16 +235,6 @@ public function getStats(): DriverStatistic
235235
)
236236
);
237237

238-
$stats->setData(
239-
\implode(
240-
', ',
241-
\array_map(
242-
static fn (ExtendedCacheItemPoolInterface $pool) => $pool->getStats()->getData(),
243-
$this->clusterPools
244-
)
245-
)
246-
);
247-
248238
return $stats;
249239
}
250240
}

‎lib/Phpfastcache/Cluster/Drivers/MasterSlaveReplication/Driver.php‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use Phpfastcache\Cluster\ClusterPoolAbstract;
2121
use Phpfastcache\Core\Item\ExtendedCacheItemInterface;
2222
use Phpfastcache\Core\Pool\ExtendedCacheItemPoolInterface;
23-
use Phpfastcache\Event\Event;
23+
use Phpfastcache\Event\Event\CacheReplicationSlaveFallbackItemPoolEvent;
2424
use Phpfastcache\Event\EventManagerInterface;
2525
use Phpfastcache\Exceptions\PhpfastcacheCoreException;
2626
use Phpfastcache\Exceptions\PhpfastcacheDriverCheckException;
@@ -80,9 +80,10 @@ protected function makeOperation(callable $operation)
8080
} catch (PhpfastcacheExceptionInterface $e) {
8181
try {
8282
$this->eventManager->dispatch(
83-
Event::CACHE_REPLICATION_SLAVE_FALLBACK,
84-
$this,
85-
\debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2)[1]['function']
83+
new CacheReplicationSlaveFallbackItemPoolEvent(
84+
$this,
85+
\debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2)[1]['function']
86+
)
8687
);
8788
return $operation($this->getSlavePool());
8889
} catch (PhpfastcacheExceptionInterface $e) {

‎lib/Phpfastcache/Cluster/Drivers/RandomReplication/Driver.php‎

Lines changed: 6 additions & 4 deletions

‎lib/Phpfastcache/Config/Config.php‎

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)