File tree
Expand file treeCollapse file tree4 files changed
+55
-7
lines changed Expand file treeCollapse file tree4 files changed
+55
-7
lines changed Original file line number | Diff line number | Diff line change |
---|
|
| 1 | +## 8.1.3 |
| 2 | +#### _"Don't throw the masks, yet."_ |
| 3 | +##### _date to be defined_ |
| 4 | +- __Core__ |
| 5 | +- Fixed #860 // Cache item throw an error on save with DateTimeImmutable date objects |
| 6 | + |
1 | 7 | ## 8.1.2
|
2 | 8 | #### _"Free the masks"_
|
3 | 9 | ##### 04 march 2022
|
|
Original file line number | Diff line number | Diff line change |
---|
@@ -162,7 +162,7 @@ public function expiresAt($expiration): ExtendedCacheItemInterface
|
162 | 162 | * @param DateTimeInterface $expiration
|
163 | 163 | */
|
164 | 164 | $this->eventManager->dis('CacheItemExpireAt', $this, $expiration);
|
165 |
| -$this->expirationDate = $expiration; |
| 165 | +$this->expirationDate = $this->demutateDatetime($expiration); |
166 | 166 | } else {
|
167 | 167 | throw new PhpfastcacheInvalidArgumentException('$expiration must be an object implementing the DateTimeInterface got: ' . \gettype($expiration));
|
168 | 168 | }
|
@@ -211,4 +211,11 @@ public function expiresAfter($time)
|
211 | 211 |
|
212 | 212 | return $this;
|
213 | 213 | }
|
| 214 | + |
| 215 | +protected function demutateDatetime(\DateTimeInterface $dateTime): \DateTimeInterface |
| 216 | +{ |
| 217 | +return $dateTime instanceof \DateTimeImmutable |
| 218 | +? \DateTime::createFromImmutable($dateTime) |
| 219 | +: $dateTime; |
| 220 | +} |
214 | 221 | }
|
Original file line number | Diff line number | Diff line change |
---|
|
17 | 17 | namespace Phpfastcache\Core\Pool;
|
18 | 18 |
|
19 | 19 | use DateTime;
|
| 20 | +use DateTimeInterface; |
20 | 21 | use Exception;
|
21 | 22 | use Phpfastcache\Config\ConfigurationOption;
|
22 | 23 | use Phpfastcache\Core\Item\ExtendedCacheItemInterface;
|
@@ -179,27 +180,27 @@ public function driverUnwrapData(array $wrapper)
|
179 | 180 |
|
180 | 181 | /**
|
181 | 182 | * @param array $wrapper
|
182 |
| -* @return DateTime |
| 183 | +* @return ?DateTimeInterface |
183 | 184 | */
|
184 |
| -public function driverUnwrapEdate(array $wrapper) |
| 185 | +public function driverUnwrapEdate(array $wrapper): ?DateTimeInterface |
185 | 186 | {
|
186 | 187 | return $wrapper[self::DRIVER_EDATE_WRAPPER_INDEX];
|
187 | 188 | }
|
188 | 189 |
|
189 | 190 | /**
|
190 | 191 | * @param array $wrapper
|
191 |
| -* @return DateTime |
| 192 | +* @return ?DateTimeInterface |
192 | 193 | */
|
193 |
| -public function driverUnwrapCdate(array $wrapper) |
| 194 | +public function driverUnwrapCdate(array $wrapper): ?DateTimeInterface |
194 | 195 | {
|
195 | 196 | return $wrapper[self::DRIVER_CDATE_WRAPPER_INDEX];
|
196 | 197 | }
|
197 | 198 |
|
198 | 199 | /**
|
199 | 200 | * @param array $wrapper
|
200 |
| -* @return DateTime |
| 201 | +* @return ?DateTimeInterface |
201 | 202 | */
|
202 |
| -public function driverUnwrapMdate(array $wrapper) |
| 203 | +public function driverUnwrapMdate(array $wrapper) :?DateTimeInterface |
203 | 204 | {
|
204 | 205 | return $wrapper[self::DRIVER_MDATE_WRAPPER_INDEX];
|
205 | 206 | }
|
|
Original file line number | Diff line number | Diff line change |
---|
|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | +* @author Khoa Bui (khoaofgod) <[email protected]> https://www.phpfastcache.com |
| 5 | +* @author Georges.L (Geolim4) <[email protected]> |
| 6 | +*/ |
| 7 | + |
| 8 | +use Phpfastcache\CacheManager; |
| 9 | +use Phpfastcache\Drivers\Files\Config as FilesConfig; |
| 10 | +use Phpfastcache\Tests\Helper\TestHelper; |
| 11 | + |
| 12 | +chdir(__DIR__); |
| 13 | +require_once __DIR__ . '/../../vendor/autoload.php'; |
| 14 | +$testHelper = new TestHelper(' issue #860 - Cache item throw an error on save with DateTimeImmutable date objects'); |
| 15 | + |
| 16 | +$config = new FilesConfig(); |
| 17 | +$config->setItemDetailedDate(true); |
| 18 | +$cacheInstance = CacheManager::getInstance('Files', $config); |
| 19 | +$cacheInstance->clear(); |
| 20 | + |
| 21 | +try { |
| 22 | +$key = 'pfc_' . bin2hex(random_bytes(12)); |
| 23 | +$item = $cacheInstance->getItem($key); |
| 24 | +$item->set(random_int(1000, 999999)) |
| 25 | +->setExpirationDate(new DateTimeImmutable('+1 month')) |
| 26 | +->setCreationDate(new DateTimeImmutable()) |
| 27 | +->setModificationDate(new DateTimeImmutable('+1 week')); |
| 28 | +$cacheInstance->save($item); |
| 29 | +$cacheInstance->detachAllItems(); |
| 30 | +$item = $cacheInstance->getItem($key); |
| 31 | +$testHelper->assertPass(' issue #860 have not regressed.'); |
| 32 | +} catch (\TypeError $e) { |
| 33 | +$testHelper->assertFail(' issue #860 have regressed, exception caught: ' . $e->getMessage()); |
| 34 | +} |
You can’t perform that action at this time.
0 commit comments