Skip to content

Commit 517741c

Browse files
authored
Merge pull request #863 from PHPSocialNetwork/v9
Released 9.1.1
2 parents c871f98 + 4de9fce commit 517741c

File tree

21 files changed

+102
-37
lines changed

21 files changed

+102
-37
lines changed

.scrutinizer.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
# @author Contributors https://github.com/PHPSocialNetwork/phpfastcache/graphs/contributors
1010
#
1111

12-
before_commands:
13-
- "./bin/ci/scripts/install_dependencies.sh"
1412
build:
13+
dependencies:
14+
override:
15+
- "composer require -W --ignore-platform-reqs 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"
1516
nodes:
1617
analysis:
1718
project_setup:
@@ -21,7 +22,14 @@ build:
2122
environment:
2223
php:
2324
version: 8.0.0
24-
checks:
25+
ini:
26+
date.timezone: 'Europe/Paris'
27+
pecl_extensions:
28+
# - couchbase
29+
# - grpc
30+
- redis
31+
- memcache
32+
checks:
2533
php: true
2634
coding_style:
2735
php:

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 9.1.1
2+
##### _Date to be defined_
3+
- __Core__
4+
- Fixed #860 // Cache item throw an error on reading with DateTimeImmutable date objects
5+
- Fixed an issue with tags not properly reinitialized when a backend driver returns an expired cache item
6+
- __Drivers__
7+
- Fixed #862 // Multiple driver errors caused by invalid return type of `driverRead()` (reported by @ShockedPlot7560 and @aemla)
8+
19
## 9.1.0
210
##### 04 april 2022
311
- __API__

lib/Phpfastcache/Core/Item/CacheItemTrait.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function expiresAt(?\DateTimeInterface $expiration): static
102102
{
103103
if ($expiration instanceof DateTimeInterface) {
104104
$this->eventManager->dispatch(Event::CACHE_ITEM_EXPIRE_AT, $this, $expiration);
105-
$this->expirationDate = $expiration;
105+
$this->expirationDate = $this->demutateDatetime($expiration);
106106
} else {
107107
throw new PhpfastcacheInvalidArgumentException('$expiration must be an object implementing the DateTimeInterface got: ' . \gettype($expiration));
108108
}
@@ -139,4 +139,11 @@ public function expiresAfter(int|\DateInterval|null $time): static
139139

140140
return $this;
141141
}
142+
143+
protected function demutateDatetime(\DateTimeInterface $dateTime): \DateTimeInterface
144+
{
145+
return $dateTime instanceof \DateTimeImmutable
146+
? \DateTime::createFromImmutable($dateTime)
147+
: $dateTime;
148+
}
142149
}

lib/Phpfastcache/Core/Item/ExtendedCacheItemTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public function getCreationDate(): DateTimeInterface
136136
public function setCreationDate(DateTimeInterface $date): ExtendedCacheItemInterface
137137
{
138138
if ($this->driver->getConfig()->isItemDetailedDate()) {
139-
$this->creationDate = $date;
139+
$this->creationDate = $this->demutateDatetime($date);
140140
return $this;
141141
}
142142

@@ -163,7 +163,7 @@ public function getModificationDate(): DateTimeInterface
163163
public function setModificationDate(DateTimeInterface $date): ExtendedCacheItemInterface
164164
{
165165
if ($this->driver->getConfig()->isItemDetailedDate()) {
166-
$this->modificationDate = $date;
166+
$this->modificationDate = $this->demutateDatetime($date);
167167
return $this;
168168
}
169169

lib/Phpfastcache/Core/Item/TaggableCacheItemTrait.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,10 @@ public function hasTags(array $tagNames, int $strategy = TaggableCacheItemInterf
9090
*/
9191
public function setTags(array $tags): ExtendedCacheItemInterface
9292
{
93-
if (\count($tags)) {
94-
if (\array_filter($tags, 'is_string')) {
95-
$this->tags = $tags;
96-
} else {
97-
throw new PhpfastcacheInvalidArgumentException('$tagName must be an array of string');
98-
}
93+
if ($tags === [] || \array_filter($tags, 'is_string')) {
94+
$this->tags = $tags;
95+
} else {
96+
throw new PhpfastcacheInvalidArgumentException('$tagName must be an array of string');
9997
}
10098

10199
return $this;

lib/Phpfastcache/Core/Pool/DriverBaseTrait.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,11 @@ public function driverUnwrapData(array $wrapper): mixed
203203

204204
/**
205205
* @param array $wrapper
206-
* @return DateTime
206+
* @return DateTimeInterface
207207
*/
208-
public function driverUnwrapEdate(array $wrapper): \DateTime
208+
public function driverUnwrapEdate(array $wrapper): \DateTimeInterface
209209
{
210-
if ($wrapper[self::DRIVER_EDATE_WRAPPER_INDEX] instanceof \DateTime) {
210+
if ($wrapper[self::DRIVER_EDATE_WRAPPER_INDEX] instanceof \DateTimeInterface) {
211211
return $wrapper[self::DRIVER_EDATE_WRAPPER_INDEX];
212212
}
213213

@@ -216,11 +216,11 @@ public function driverUnwrapEdate(array $wrapper): \DateTime
216216

217217
/**
218218
* @param array $wrapper
219-
* @return DateTime|null
219+
* @return DateTimeInterface|null
220220
*/
221-
public function driverUnwrapCdate(array $wrapper): ?\DateTime
221+
public function driverUnwrapCdate(array $wrapper): ?\DateTimeInterface
222222
{
223-
if ($wrapper[self::DRIVER_CDATE_WRAPPER_INDEX] instanceof \DateTime) {
223+
if ($wrapper[self::DRIVER_CDATE_WRAPPER_INDEX] instanceof \DateTimeInterface) {
224224
return $wrapper[self::DRIVER_CDATE_WRAPPER_INDEX];
225225
}
226226

@@ -229,11 +229,11 @@ public function driverUnwrapCdate(array $wrapper): ?\DateTime
229229

230230
/**
231231
* @param array $wrapper
232-
* @return DateTime|null
232+
* @return DateTimeInterface|null
233233
*/
234-
public function driverUnwrapMdate(array $wrapper): ?\DateTime
234+
public function driverUnwrapMdate(array $wrapper): ?\DateTimeInterface
235235
{
236-
if ($wrapper[self::DRIVER_MDATE_WRAPPER_INDEX] instanceof \DateTime) {
236+
if ($wrapper[self::DRIVER_MDATE_WRAPPER_INDEX] instanceof \DateTimeInterface) {
237237
return $wrapper[self::DRIVER_MDATE_WRAPPER_INDEX];
238238
}
239239

@@ -269,6 +269,6 @@ protected function encode($data): string
269269
*/
270270
protected function decode(?string $value): mixed
271271
{
272-
return \unserialize((string) $value, ['allowed_classes' => true]);
272+
return $value ? \unserialize($value, ['allowed_classes' => true]) : null;
273273
}
274274
}

lib/Phpfastcache/Drivers/Apcu/Driver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ protected function driverRead(ExtendedCacheItemInterface $item): ?array
9292
{
9393
$data = apcu_fetch($item->getKey(), $success);
9494

95-
if ($success === false) {
95+
if ($success === false || !\is_array($data)) {
9696
return null;
9797
}
9898

lib/Phpfastcache/Drivers/Arangodb/Driver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ protected function driverRead(ExtendedCacheItemInterface $item): ?array
131131
return null;
132132
}
133133
throw new PhpfastcacheDriverException(
134-
'Got unexpeced error from Arangodb: ' . $e->getMessage()
134+
'Got unexpected error from Arangodb: ' . $e->getMessage()
135135
);
136136
}
137137

lib/Phpfastcache/Drivers/Cassandra/Driver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ protected function driverRead(ExtendedCacheItemInterface $item): ?array
140140
$results = $this->instance->execute(new Cassandra\SimpleStatement($query), $options);
141141

142142
if ($results instanceof Cassandra\Rows && $results->count() === 1) {
143-
return $this->decode($results->first()['cache_data']);
143+
return $this->decode($results->first()['cache_data']) ?: null;
144144
}
145145

146146
return null;

lib/Phpfastcache/Drivers/Couchdb/Driver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ protected function encodeDocument(array $data): array
257257
* @return mixed
258258
* @throws \Exception
259259
*/
260-
protected function decode($value): mixed
260+
protected function decode($value): array
261261
{
262262
$value[ExtendedCacheItemPoolInterface::DRIVER_DATA_WRAPPER_INDEX] = \unserialize(
263263
$value[ExtendedCacheItemPoolInterface::DRIVER_DATA_WRAPPER_INDEX],

0 commit comments

Comments
 (0)