Skip to content

Commit d4a52b3

Browse files
committed
Renamed "Memstatic" to "Memory", updated composer metadata, improved EventManagerInterface::on() signature
1 parent 035b84a commit d4a52b3

33 files changed

+436
-181
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@
44
- Upgraded Phpfastcache API to `4.3.0` ([see changes](CHANGELOG_API.md))
55
- __Events__
66
- 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).
7+
- `EventManagerInterface::on()` now accepts a single `string $events` or an `array $events`.
8+
- Alias `\Phpfastcache\PhpfastcacheEventManager` of `\Phpfastcache\EventManager` has been added to improve your code import readability.
79
- __Drivers__
810
- Implemented #906 // **Added `RedisCluster` driver support**
11+
- Driver `Memstatic` has changed its name to `Memory` for more consistency.
912
- __Pool__
1013
- 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)).
1114
- __Core__
1215
- Configuration methods`ConfigurationOption::isPreventCacheSlams()`, `ConfigurationOption::setPreventCacheSlams()`, `ConfigurationOption::getCacheSlamsTimeout()`, `ConfigurationOption::setCacheSlamsTimeout()` are deprecated. ([See changes](CHANGELOG_API.md)).
1316
- Fixed #907 // Internal "driver decode()" method will now throw an if the string data looks corrupted.
1417
- 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.
1518
- 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.
19+
- `\Phpfastcache\CacheContract::get()` now accepts a `\Stringable $cacheKey` argument.
1620
- __Misc__
1721
- Fixed multiple code typo & updated README.md
1822

CHANGELOG_API.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- Created `IOConfigurationOption::setPreventCacheSlams()`. This method will **only be available** for `Files, Sqlite, Leveldb` drivers.
99
- Created `IOConfigurationOption::getCacheSlamsTimeout()`. This method will **only be available** for `Files, Sqlite, Leveldb` drivers.
1010
- Created `IOConfigurationOption::setCacheSlamsTimeout()`. This method will **only be available** for `Files, Sqlite, Leveldb` drivers.
11+
- Method `EventManagerInterface::on(array|string $events, callable $callback)` now accepts a single `string $events` or an `array $events`.
1112

1213

1314
## 4.2.0

SECURITY.md

+14-11
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,24 @@ If you discover any vulnerability please be aware of the following table of supp
33
Then feel free to contact me at the email address provided in the bottom of that page.
44

55
## Supported Versions
6-
| Version | End of support | End of life |
7-
| ------- | -------------------- | ------------------ |
8-
| 9.x | December 2023 | December 2024 |
9-
| 8.x | July 2023 | July 2024 |
10-
| 7.1 | July 2021 | July 2022 |
11-
| 7.0 | July 2019 | July 2020 |
12-
| 6.0 | July 2020 | July 2021 |
13-
| 5.0 | July 2018 | July 2019 |
14-
| 4.0 | July 2017 | January 2018 |
15-
| < 4.0 | N/A | N/A |
6+
| Version | End of support | End of life |
7+
|---------|------------------|------------------|
8+
| 10.0 | *In development* | *In development* |
9+
| 9.2 | December 2025 | December 2026 |
10+
| 9.1 | December 2024 | December 2025 |
11+
| 9.0 | December 2023 | December 2024 |
12+
| 8.x | July 2023 | July 2024 |
13+
| 7.1 | July 2021 | July 2022 |
14+
| 7.0 | July 2019 | July 2020 |
15+
| 6.0 | July 2020 | July 2021 |
16+
| 5.0 | July 2018 | July 2019 |
17+
| 4.0 | July 2017 | January 2018 |
18+
| < 4.0 | N/A | N/A |
1619

1720
More details on the [Wiki](https://github.com/PHPSocialNetwork/phpfastcache/wiki/%5BV4%CB%96%5D-Global-support-timeline)
1821

1922
## Reporting a Vulnerability
2023
If you discover any security vulnerability contact me at contact#at#geolim4.com with a subject formatted like that:\
21-
`[PHPFASTCACHE][VULNERABILITY] Your subject goes here`
24+
`[PHPFASTCACHE][VULNERABILITY] Your mail subject goes here`
2225

2326
Thanks in advance for taking the time to report me that in private.

bin/ci/scripts/install_dependencies.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ composer install
66
#####
77
# Travis CI have php mongodb extension locked to 1.10, so we must set the mongodb/mongodb minimum version to 1.9 :(
88
#####
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.39 solarium/solarium:~6.1
9+
composer require -W doctrine/couchdb:dev-master phpfastcache/phpssdb:~1.2 predis/predis:~1.1 mongodb/mongodb:~1.9 triagens/arangodb:~3.8 aws/aws-sdk-php:~3.2 google/cloud-firestore:~1.39 solarium/solarium:~6.1

composer.json

+22-4
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
"keywords": ["abstract", "cache","caching","php cache","mysql cache","apc","apcu","arangodb","dynamodb","firestore","memcache","memcached","wincache","files cache","pdo cache","cache class","redis","redis cluster","predis","cookie", "mongodb", "cassandra", "couchdb", "couchbase", "LevelDb", "Solr", "Ssdb", "Wincache", "xcache","zend","zend disk cache","zend memory cache","zend data cache","zend server"],
66
"homepage": "https://www.phpfastcache.com",
77
"license": "MIT",
8+
"readme": "README.md",
89
"minimum-stability": "stable",
910
"authors": [
1011
{
1112
"name": "Georges.L",
1213
"email": "[email protected]",
1314
"homepage": "https://github.com/Geolim4",
14-
"role": "Actual Project Manager/Developer"
15+
"role": "Project Manager"
1516
},
1617
{
1718
"name": "Contributors",
@@ -23,7 +24,16 @@
2324
"psr/cache": "^2.0||^3.0",
2425
"psr/simple-cache": "^2.0||^3.0",
2526
"ext-mbstring": "*",
26-
"ext-json": "*"
27+
"ext-json": "*",
28+
"doctrine/couchdb": "dev-master",
29+
"phpfastcache/phpssdb": "~1.2",
30+
"predis/predis": "~1.1",
31+
"mongodb/mongodb": "~1.9",
32+
"triagens/arangodb": "~3.8",
33+
"aws/aws-sdk-php": "~3.2",
34+
"google/cloud-firestore": "~1.39",
35+
"solarium/solarium": "~6.1",
36+
"symfony/var-dumper": "^6.0"
2737
},
2838
"require-dev": {
2939
"league/climate": "^3.8",
@@ -35,9 +45,11 @@
3545
},
3646
"suggest": {
3747
"ext-apcu": "*",
48+
"ext-curl": "*",
3849
"ext-intl": "*",
3950
"ext-memcached": "*",
4051
"ext-cassandra": "*",
52+
"ext-grpc": "*",
4153
"ext-memcache": "*",
4254
"ext-mongodb": "*",
4355
"ext-redis": "*",
@@ -62,14 +74,20 @@
6274
},
6375
"autoload": {
6476
"psr-4": {
65-
"Phpfastcache\\": "lib/Phpfastcache/",
77+
"Phpfastcache\\": "lib/Phpfastcache/"
78+
}
79+
},
80+
"autoload-dev": {
81+
"psr-4": {
6682
"Phpfastcache\\Tests\\": "tests/lib/"
6783
}
6884
},
6985
"support": {
7086
"issues": "https://github.com/PHPSocialNetwork/phpfastcache/issues",
7187
"wiki": "https://github.com/PHPSocialNetwork/phpfastcache/wiki",
72-
"source": "https://github.com/PHPSocialNetwork/phpfastcache"
88+
"docs": "https://github.com/PHPSocialNetwork/phpfastcache/wiki",
89+
"source": "https://github.com/PHPSocialNetwork/phpfastcache",
90+
"security": "https://github.com/PHPSocialNetwork/phpfastcache/blob/master/SECURITY.md"
7391
},
7492
"funding": [
7593
{

docs/EVENTS.md

+10
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,16 @@ The order of execution of the events is always the following:
331331
- Allow you to alter the parameters built used to create the collection
332332
- **Risky Circular Methods**: None
333333

334+
#### Couchdb (v9.2)
335+
- onCouchdbCreateOptions(*Callable* **$callback**)
336+
- **Callback arguments**
337+
- *ExtendedCacheItemPoolInterface* **$itemPool**
338+
- *EventReferenceParameter($options)* **$options** _via EventReferenceParameter object_ **(type modification forbidden)**
339+
- **Scope**
340+
- Arangodb Driver
341+
- **Description**
342+
- Allow you to alter the options built used to create the Couchdb client instance.
343+
- **Risky Circular Methods**: None
334344
#### Dynamodb
335345
- onDynamodbCreateTable(*Callable* **$callback**)
336346
- **Callback arguments**

lib/Phpfastcache/CacheContract.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ public function __construct(CacheItemPoolInterface $cacheInstance)
3232
/**
3333
* @throws InvalidArgumentException
3434
*/
35-
public function get(string $cacheKey, callable $callback, DateInterval|int $expiresAfter = null): mixed
35+
public function get(string|\Stringable $cacheKey, callable $callback, DateInterval|int $expiresAfter = null): mixed
3636
{
37-
$cacheItem = $this->cacheInstance->getItem($cacheKey);
37+
$cacheItem = $this->cacheInstance->getItem((string) $cacheKey);
3838

3939
if (!$cacheItem->isHit()) {
4040
/*

lib/Phpfastcache/Core/Pool/ExtendedCacheItemPoolTrait.php

+14
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,18 @@ public function getHelp(): string
118118
{
119119
return '';
120120
}
121+
122+
/**
123+
* @throws PhpfastcacheInvalidArgumentException
124+
*/
125+
public function throwUnsupportedDriverReadAllPattern(string $linkReference = ''): void
126+
{
127+
throw new PhpfastcacheInvalidArgumentException(
128+
sprintf(
129+
'%s does not support a pattern argument.%s',
130+
$this->getDriverName(),
131+
$linkReference ? " See $linkReference" : ''
132+
)
133+
);
134+
}
121135
}

lib/Phpfastcache/Drivers/Arangodb/Config.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
*/
2626
class Config extends ConfigurationOption
2727
{
28-
protected string $database;
29-
protected string $collection;
28+
protected string $database = 'phpfastcache';
29+
protected string $collection = 'phpfastcache';
3030

3131
/**
3232
* @var string|array<string>

lib/Phpfastcache/Drivers/Arangodb/Driver.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -292,13 +292,16 @@ public function getStats(): DriverStatistic
292292
try {
293293
$adminHandler = new AdminHandler($this->instance);
294294
$rawData['adminInfo'] = $adminHandler->getServerVersion(true);
295+
295296
$infoText = \sprintf(
296-
'%s server v%s "%s" edition (%s/%s).',
297+
'%s server v%s "%s" edition (%s/%s). Database/Collection: "%s"/"%s"',
297298
\ucfirst($rawData['adminInfo']['server']),
298299
$rawData['adminInfo']['version'] ?? 'unknown version',
299300
$rawData['adminInfo']['license'] ?? 'unknown licence',
300301
$rawData['adminInfo']['details']['architecture'] ?? 'unknown architecture',
301302
$rawData['adminInfo']['details']['platform'] ?? 'unknown platform',
303+
$this->instance->getDatabase(),
304+
$rawData['collectionInfo']->getName(),
302305
);
303306
} catch (ArangoException $e) {
304307
$infoText = 'No readable human data, encountered an error while trying to get details: ' . $e->getMessage();

lib/Phpfastcache/Drivers/Couchdb/Driver.php

+67-8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Phpfastcache\Core\Pool\TaggableCacheItemPoolTrait;
2525
use Phpfastcache\Core\Item\ExtendedCacheItemInterface;
2626
use Phpfastcache\Entities\DriverStatistic;
27+
use Phpfastcache\Event\EventReferenceParameter;
2728
use Phpfastcache\Exceptions\PhpfastcacheDriverException;
2829
use Phpfastcache\Exceptions\PhpfastcacheInvalidArgumentException;
2930
use Phpfastcache\Exceptions\PhpfastcacheLogicException;
@@ -95,13 +96,16 @@ protected function driverConnect(): bool
9596
$url .= ":{$clientConfig->getPort()}";
9697
$url .= '/' . \urlencode($this->getDatabaseName());
9798

98-
$this->instance = CouchDBClient::create(
99-
[
100-
'dbname' => $this->getDatabaseName(),
101-
'url' => $url,
102-
'timeout' => $clientConfig->getTimeout(),
103-
]
104-
);
99+
$options = [
100+
'dbname' => $this->getDatabaseName(),
101+
'url' => $url,
102+
'timeout' => $clientConfig->getTimeout(),
103+
'headers' => []
104+
];
105+
106+
$this->eventManager->dispatch(Event::COUCHDB_CREATE_OPTIONS, $this, new EventReferenceParameter($options));
107+
108+
$this->instance = CouchDBClient::create($options);
105109

106110
$this->createDatabase();
107111

@@ -164,11 +168,66 @@ protected function driverRead(ExtendedCacheItemInterface $item): ?array
164168
throw new PhpfastcacheDriverException('Got unexpected HTTP status: ' . $response->status);
165169
}
166170

171+
/**
172+
* @param ExtendedCacheItemInterface ...$items
173+
* @return array<array<string, mixed>>
174+
* @throws PhpfastcacheDriverException
175+
*/
176+
protected function driverReadMultiple(ExtendedCacheItemInterface ...$items): array
177+
{
178+
$response = $this->instance->findDocuments(
179+
array_map(
180+
fn(string $key) => $this->getCouchDbKey($key),
181+
$this->getKeys($items, true)
182+
)
183+
);
184+
185+
if ($response->status === 404 || empty($response->body['rows'])) {
186+
return [];
187+
}
188+
189+
if ($response->status === 200) {
190+
$driverArrays = [];
191+
foreach ($response->body['rows'] as $row) {
192+
if (isset($row['doc'])) {
193+
$doc = $this->decodeDocument($row['doc']);
194+
$driverArrays[$doc[self::DRIVER_KEY_WRAPPER_INDEX]] = $doc;
195+
}
196+
}
197+
return $driverArrays;
198+
}
199+
200+
throw new PhpfastcacheDriverException('Got unexpected HTTP status: ' . $response->status);
201+
}
202+
203+
/**
204+
* @return array<int, string>
205+
* @throws PhpfastcacheDriverException
206+
* @throws PhpfastcacheInvalidArgumentException
207+
*/
208+
protected function driverReadAllKeys(string $pattern = ''): iterable
209+
{
210+
if ($pattern !== '') {
211+
$this->throwUnsupportedDriverReadAllPattern();
212+
}
213+
214+
$response = $this->instance->allDocs(ExtendedCacheItemPoolInterface::MAX_ALL_KEYS_COUNT);
215+
216+
if ($response->status === 404 || empty($response->body['rows'])) {
217+
return [];
218+
}
219+
220+
if ($response->status === 200) {
221+
return array_map(static fn(array $row) => $row['doc'][self::DRIVER_KEY_WRAPPER_INDEX], $response->body['rows']);
222+
}
223+
224+
throw new PhpfastcacheDriverException('Got unexpected HTTP status: ' . $response->status);
225+
}
226+
167227
/**
168228
* @param ExtendedCacheItemInterface $item
169229
* @return bool
170230
* @throws PhpfastcacheDriverException
171-
* @throws PhpfastcacheInvalidArgumentException
172231
* @throws PhpfastcacheLogicException
173232
*/
174233
protected function driverWrite(ExtendedCacheItemInterface $item): bool
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Phpfastcache\Drivers\Couchdb;
4+
5+
class Event extends \Phpfastcache\Event\Event
6+
{
7+
public const COUCHDB_CREATE_OPTIONS = 'CouchdbCreateOptions';
8+
}

lib/Phpfastcache/Drivers/Firestore/Driver.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ protected function driverRead(ExtendedCacheItemInterface $item): ?array
138138
protected function driverReadAllKeys(string $pattern = ''): iterable
139139
{
140140
if ($pattern !== '') {
141-
throw new PhpfastcacheInvalidArgumentException('Firestore does not support a pattern argument');
141+
$this->throwUnsupportedDriverReadAllPattern();
142142
}
143143
$data = [];
144144
$documents = $this->instance->collection($this->getConfig()->getCollectionName())

lib/Phpfastcache/Drivers/Memcached/Driver.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ protected function driverReadMultiple(ExtendedCacheItemInterface ...$items): arr
179179
protected function driverReadAllKeys(string $pattern = ''): iterable
180180
{
181181
if ($pattern !== '') {
182-
throw new PhpfastcacheInvalidArgumentException('Memcached does not support a pattern argument, see https://www.php.net/manual/en/memcached.getallkeys.php');
182+
$this->throwUnsupportedDriverReadAllPattern('https://www.php.net/manual/en/memcached.getallkeys.php');
183183
}
184184
$keys = $this->instance->getAllKeys();
185185

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
/**
4+
*
5+
* This file is part of Phpfastcache.
6+
*
7+
* @license MIT License (MIT)
8+
*
9+
* For full copyright and license information, please see the docs/CREDITS.txt and LICENCE files.
10+
*
11+
* @author Georges.L (Geolim4) <[email protected]>
12+
* @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
13+
*/
14+
15+
declare(strict_types=1);
16+
17+
namespace Phpfastcache\Drivers\Memory;
18+
19+
use Phpfastcache\Config\ConfigurationOption;
20+
21+
class Config extends ConfigurationOption
22+
{
23+
}

0 commit comments

Comments
 (0)