Skip to content

Commit 464201c

Browse files
committed
- Replaced \LogicException occurrences with phpFastCacheLogicException
1 parent 8b729cb commit 464201c

18 files changed

+138
-59
lines changed

MigratingFromV5ToV6.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ try{
9292
```
9393

9494
#### :alarm_clock: Now:
95-
This has been changed you now MUST catch `\phpFastCache\Exceptions\phpFastCacheInvalidArgumentException` interface
95+
This has been changed you now MUST catch `\phpFastCache\Exceptions\phpFastCacheInvalidArgumentException` class
9696

9797
```php
9898
namespace My\Custom\Project;
@@ -108,6 +108,40 @@ try{
108108
```
109109
:warning: Please note that `\phpFastCache\Exceptions\phpFastCacheInvalidArgumentException` implements `\Psr\Cache\InvalidArgumentException` as per PSR-6.
110110

111+
### Catching \LogicException
112+
113+
#### :clock1: Then:
114+
Code used to catch a `\LogicException`.
115+
116+
```php
117+
namespace My\Custom\Project;
118+
119+
$instance = CacheManager::getInstance('Files');
120+
121+
try{
122+
$item = $instance->getItem(array());
123+
}catch(\LogicException $e){
124+
//Catched exception code
125+
}
126+
127+
```
128+
129+
#### :alarm_clock: Now:
130+
This has been changed you now MUST catch `\phpFastCache\Exceptions\phpFastCacheLogicException` interface
131+
132+
```php
133+
namespace My\Custom\Project;
134+
135+
$instance = CacheManager::getInstance('Files');
136+
137+
try{
138+
$item = $instance->getItem(array());
139+
}catch(\phpFastCache\Exceptions\phpFastCacheLogicException $e){
140+
//Catched exception code
141+
}
142+
143+
```
144+
111145
### Allowed characters in key identifier
112146
:warning: As of the V6, the following characters can not longer being a part of the key identifier: `{}()/\@:`
113147

src/phpFastCache/CacheManager.php

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,27 @@
2222
* Class CacheManager
2323
* @package phpFastCache
2424
*
25-
* @method static ExtendedCacheItemPoolInterface Apc() Apc($config = []) Return a driver "apc" instance
26-
* @method static ExtendedCacheItemPoolInterface Apcu() Apcu($config = []) Return a driver "apcu" instance
25+
* @method static ExtendedCacheItemPoolInterface Apc() Apc($config = []) Return a driver "Apc" instance
26+
* @method static ExtendedCacheItemPoolInterface Apcu() Apcu($config = []) Return a driver "Apcu" instance
2727
* @method static ExtendedCacheItemPoolInterface Cassandra() Cassandra($config = []) Return a driver "Cassandra" instance
28-
* @method static ExtendedCacheItemPoolInterface Cookie() Cookie($config = []) Return a driver "cookie" instance
29-
* @method static ExtendedCacheItemPoolInterface Couchbase() Couchbase($config = []) Return a driver "couchbase" instance
28+
* @method static ExtendedCacheItemPoolInterface Cookie() Cookie($config = []) Return a driver "Cookie" instance
29+
* @method static ExtendedCacheItemPoolInterface Couchbase() Couchbase($config = []) Return a driver "Couchbase" instance
3030
* @method static ExtendedCacheItemPoolInterface Couchdb() Couchdb($config = []) Return a driver "Couchdb" instance
31+
* @method static ExtendedCacheItemPoolInterface Devnull() Devnull($config = []) Return a driver "Devnull" instance
3132
* @method static ExtendedCacheItemPoolInterface Files() Files($config = []) Return a driver "files" instance
32-
* @method static ExtendedCacheItemPoolInterface Leveldb() Leveldb($config = []) Return a driver "leveldb" instance
33-
* @method static ExtendedCacheItemPoolInterface Memcache() Memcache($config = []) Return a driver "memcache" instance
34-
* @method static ExtendedCacheItemPoolInterface Memcached() Memcached($config = []) Return a driver "memcached" instance
35-
* @method static ExtendedCacheItemPoolInterface Mongodb() Mongodb($config = []) Return a driver "mongodb" instance
36-
* @method static ExtendedCacheItemPoolInterface Predis() Predis($config = []) Return a driver "predis" instance
37-
* @method static ExtendedCacheItemPoolInterface Redis() Redis($config = []) Return a driver "redis" instance
38-
* @method static ExtendedCacheItemPoolInterface Sqlite() Sqlite($config = []) Return a driver "sqlite" instance
39-
* @method static ExtendedCacheItemPoolInterface Ssdb() Ssdb($config = []) Return a driver "ssdb" instance
40-
* @method static ExtendedCacheItemPoolInterface Wincache() Wincache($config = []) Return a driver "wincache" instance
41-
* @method static ExtendedCacheItemPoolInterface Xcache() Xcache($config = []) Return a driver "xcache" instance
42-
* @method static ExtendedCacheItemPoolInterface Zenddisk() Zenddisk($config = []) Return a driver "zend disk cache" instance
43-
* @method static ExtendedCacheItemPoolInterface Zendshm() Zendshm($config = []) Return a driver "zend memory cache" instance
33+
* @method static ExtendedCacheItemPoolInterface Leveldb() Leveldb($config = []) Return a driver "Leveldb" instance
34+
* @method static ExtendedCacheItemPoolInterface Memcache() Memcache($config = []) Return a driver "Memcache" instance
35+
* @method static ExtendedCacheItemPoolInterface Memcached() Memcached($config = []) Return a driver "Memcached" instance
36+
* @method static ExtendedCacheItemPoolInterface Memstatic() Memstatic($config = []) Return a driver "Memstatic" instance
37+
* @method static ExtendedCacheItemPoolInterface Mongodb() Mongodb($config = []) Return a driver "Mongodb" instance
38+
* @method static ExtendedCacheItemPoolInterface Predis() Predis($config = []) Return a driver "Predis" instance
39+
* @method static ExtendedCacheItemPoolInterface Redis() Redis($config = []) Return a driver "Pedis" instance
40+
* @method static ExtendedCacheItemPoolInterface Sqlite() Sqlite($config = []) Return a driver "Sqlite" instance
41+
* @method static ExtendedCacheItemPoolInterface Ssdb() Ssdb($config = []) Return a driver "Ssdb" instance
42+
* @method static ExtendedCacheItemPoolInterface Wincache() Wincache($config = []) Return a driver "Wincache" instance
43+
* @method static ExtendedCacheItemPoolInterface Xcache() Xcache($config = []) Return a driver "Xcache" instance
44+
* @method static ExtendedCacheItemPoolInterface Zenddisk() Zenddisk($config = []) Return a driver "Zend disk cache" instance
45+
* @method static ExtendedCacheItemPoolInterface Zendshm() Zendshm($config = []) Return a driver "Zend memory cache" instance
4446
*
4547
*/
4648
class CacheManager
@@ -71,7 +73,7 @@ class CacheManager
7173
'autoTmpFallback' => false,
7274

7375
/**
74-
* Provide a secure file manipulation mechanism
76+
* Provide a secure file manipulation mechanism,
7577
* on intensive usage the performance can be affected.
7678
*/
7779
'secureFileManipulation' => false,

src/phpFastCache/Core/Item/ExtendedCacheItemInterface.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use phpFastCache\Exceptions\phpFastCacheInvalidArgumentException;
1919
use Psr\Cache\CacheItemInterface;
2020
use phpFastCache\Core\Pool\ExtendedCacheItemPoolInterface;
21+
use phpFastCache\Exceptions\phpFastCacheLogicException;
2122

2223
/**
2324
* Interface ExtendedCacheItemInterface
@@ -60,27 +61,27 @@ public function setExpirationDate(\DateTimeInterface $expiration);
6061

6162
/**
6263
* @return \DateTimeInterface
63-
* @throws \LogicException
64+
* @throws phpFastCacheLogicException
6465
*/
6566
public function getCreationDate();
6667

6768
/**
6869
* @return \DateTimeInterface
69-
* @throws \LogicException
70+
* @throws phpFastCacheLogicException
7071
*/
7172
public function getModificationDate();
7273

7374
/**
7475
* @param $date \DateTimeInterface
7576
* @return $this
76-
* @throws \LogicException
77+
* @throws phpFastCacheLogicException
7778
*/
7879
public function setCreationDate(\DateTimeInterface $date);
7980

8081
/**
8182
* @param $date \DateTimeInterface
8283
* @return $this
83-
* @throws \LogicException
84+
* @throws phpFastCacheLogicException
8485
*/
8586
public function setModificationDate(\DateTimeInterface $date);
8687

src/phpFastCache/Core/Item/ItemBaseTrait.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@
1111
* @author Georges.L (Geolim4) <[email protected]>
1212
*
1313
*/
14-
1514
namespace phpFastCache\Core\Item;
1615

1716
use phpFastCache\Exceptions\phpFastCacheInvalidArgumentException;
1817

18+
/**
19+
* Trait ItemBaseTrait
20+
* @package phpFastCache\Core\Item
21+
*/
1922
trait ItemBaseTrait
2023
{
2124
use ItemExtendedTrait;

src/phpFastCache/Core/Item/ItemExtendedTrait.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
use phpFastCache\EventManager;
1818
use phpFastCache\Core\Pool\ExtendedCacheItemPoolInterface;
1919
use phpFastCache\Exceptions\phpFastCacheInvalidArgumentException;
20+
use phpFastCache\Exceptions\phpFastCacheLogicException;
2021

2122
/**
2223
* Class ItemExtendedTrait
2324
* @package phpFastCache\Core\Item
25+
* @property \Datetime $expirationDate Expiration date of the item
2426
*/
2527
trait ItemExtendedTrait
2628
{
@@ -90,57 +92,57 @@ public function setExpirationDate(\DateTimeInterface $expiration)
9092

9193
/**
9294
* @return \DateTimeInterface
93-
* @throws \LogicException
95+
* @throws phpFastCacheLogicException
9496
*/
9597
public function getCreationDate()
9698
{
9799
if($this->driver->getConfig()['itemDetailedDate']){
98100
return $this->creationDate;
99101
}else{
100-
throw new \LogicException('Cannot access to the creation date when the "itemDetailedDate" configuration is disabled.');
102+
throw new phpFastCacheLogicException('Cannot access to the creation date when the "itemDetailedDate" configuration is disabled.');
101103
}
102104
}
103105

104106
/**
105107
* @param \DateTimeInterface $date
106108
* @return $this
107-
* @throws \LogicException
109+
* @throws phpFastCacheLogicException
108110
*/
109111
public function setCreationDate(\DateTimeInterface $date)
110112
{
111113
if($this->driver->getConfig()['itemDetailedDate']){
112114
$this->creationDate = $date;
113115
return $this;
114116
}else{
115-
throw new \LogicException('Cannot access to the creation date when the "itemDetailedDate" configuration is disabled.');
117+
throw new phpFastCacheLogicException('Cannot access to the creation date when the "itemDetailedDate" configuration is disabled.');
116118
}
117119
}
118120

119121
/**
120122
* @return \DateTimeInterface
121-
* @throws \LogicException
123+
* @throws phpFastCacheLogicException
122124
*/
123125
public function getModificationDate()
124126
{
125127
if($this->driver->getConfig()['itemDetailedDate']){
126128
return $this->modificationDate;
127129
}else{
128-
throw new \LogicException('Cannot access to the modification date when the "itemDetailedDate" configuration is disabled.');
130+
throw new phpFastCacheLogicException('Cannot access to the modification date when the "itemDetailedDate" configuration is disabled.');
129131
}
130132
}
131133

132134
/**
133135
* @param \DateTimeInterface $date
134136
* @return $this
135-
* @throws \LogicException
137+
* @throws phpFastCacheLogicException
136138
*/
137139
public function setModificationDate(\DateTimeInterface $date)
138140
{
139141
if($this->driver->getConfig()['itemDetailedDate']){
140142
$this->modificationDate = $date;
141143
return $this;
142144
}else{
143-
throw new \LogicException('Cannot access to the modification date when the "itemDetailedDate" configuration is disabled.');
145+
throw new phpFastCacheLogicException('Cannot access to the modification date when the "itemDetailedDate" configuration is disabled.');
144146
}
145147
}
146148

@@ -207,7 +209,7 @@ public function decrement($step = 1)
207209
public function append($data)
208210
{
209211
if (is_array($this->data)) {
210-
array_push($this->data, $data);
212+
$this->data[] = $data;
211213
} else if (is_string($data)) {
212214
$this->data .= (string) $data;
213215
} else {
@@ -292,6 +294,7 @@ public function getTags()
292294
}
293295

294296
/**
297+
* @param string $separator
295298
* @return string
296299
*/
297300
public function getTagsAsString($separator = ', ')

src/phpFastCache/Core/Pool/CacheItemPoolTrait.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use phpFastCache\EventManager;
2121
use phpFastCache\Exceptions\phpFastCacheCoreException;
2222
use phpFastCache\Exceptions\phpFastCacheInvalidArgumentException;
23+
use phpFastCache\Exceptions\phpFastCacheLogicException;
2324
use Psr\Cache\CacheItemInterface;
2425
use phpFastCache\Util\ClassNamespaceResolverTrait;
2526

@@ -56,7 +57,7 @@ trait CacheItemPoolTrait
5657
* @param string $key
5758
* @return \phpFastCache\Core\Item\ExtendedCacheItemInterface
5859
* @throws phpFastCacheInvalidArgumentException
59-
* @throws \LogicException
60+
* @throws phpFastCacheLogicException
6061
* @throws phpFastCacheCoreException
6162
*/
6263
public function getItem($key)

src/phpFastCache/Core/Pool/DriverBaseTrait.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use phpFastCache\Core\Item\ExtendedCacheItemInterface;
1717
use phpFastCache\Exceptions\phpFastCacheInvalidArgumentException;
18+
use phpFastCache\Exceptions\phpFastCacheLogicException;
1819

1920

2021
/**
@@ -217,7 +218,7 @@ public function getDriverName()
217218
/**
218219
* @param \phpFastCache\Core\Item\ExtendedCacheItemInterface $item
219220
* @return bool
220-
* @throws \LogicException
221+
* @throws phpFastCacheLogicException
221222
*/
222223
public function driverWriteTags(ExtendedCacheItemInterface $item)
223224
{
@@ -227,7 +228,7 @@ public function driverWriteTags(ExtendedCacheItemInterface $item)
227228
* to an infinite recursive calls
228229
*/
229230
if(strpos($item->getKey(), self::DRIVER_TAGS_KEY_PREFIX ) === 0){
230-
throw new \LogicException('Trying to set tag(s) to an Tag item index: ' . $item->getKey());
231+
throw new phpFastCacheLogicException('Trying to set tag(s) to an Tag item index: ' . $item->getKey());
231232
}
232233

233234
/**

src/phpFastCache/Core/Pool/ExtendedCacheItemPoolInterface.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use phpFastCache\EventManager;
2121
use Psr\Cache\CacheItemInterface;
2222
use Psr\Cache\CacheItemPoolInterface;
23+
use phpFastCache\Exceptions\phpFastCacheLogicException;
2324

2425
/**
2526
* Interface ExtendedCacheItemPoolInterface
@@ -472,7 +473,7 @@ public function detachAllItems();
472473
/**
473474
* @param \Psr\Cache\CacheItemInterface $item
474475
* @return void
475-
* @throws \LogicException
476+
* @throws phpFastCacheLogicException
476477
*/
477478
public function attachItem(CacheItemInterface $item);
478479

@@ -483,7 +484,7 @@ public function attachItem(CacheItemInterface $item);
483484
*
484485
* @param \Psr\Cache\CacheItemInterface $item
485486
* @return bool|null
486-
* @throws \LogicException
487+
* @throws phpFastCacheLogicException
487488
*/
488489
public function isAttached(CacheItemInterface $item);
489490

src/phpFastCache/Core/Pool/ExtendedCacheItemPoolTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use phpFastCache\Core\Item\ExtendedCacheItemInterface;
1919
use phpFastCache\EventManager;
2020
use phpFastCache\Exceptions\phpFastCacheInvalidArgumentException;
21+
use phpFastCache\Exceptions\phpFastCacheLogicException;
2122
use Psr\Cache\CacheItemInterface;
2223

2324

@@ -399,7 +400,7 @@ public function detachAllItems()
399400
public function attachItem(CacheItemInterface $item)
400401
{
401402
if (isset($this->itemInstances[ $item->getKey() ]) && spl_object_hash($item) !== spl_object_hash($this->itemInstances[ $item->getKey() ])) {
402-
throw new \LogicException('The item already exists and cannot be overwritten because the Spl object hash mismatches ! You probably tried to re-attach a detached item which has been already retrieved from cache.');
403+
throw new phpFastCacheLogicException('The item already exists and cannot be overwritten because the Spl object hash mismatches ! You probably tried to re-attach a detached item which has been already retrieved from cache.');
403404
} else {
404405
$this->itemInstances[ $item->getKey() ] = $item;
405406
}
@@ -433,7 +434,6 @@ protected function deregisterItem($item)
433434
*
434435
* @param \Psr\Cache\CacheItemInterface $item
435436
* @return bool|null
436-
* @throws \LogicException
437437
*/
438438
public function isAttached(CacheItemInterface $item)
439439
{

src/phpFastCache/Core/Pool/IO/IOHelperTrait.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ protected function encodeFilename($keyword)
175175
}
176176

177177
/**
178-
* @param $this ->config
179178
* @return int
180179
*/
181180
protected function getDefaultChmod()

0 commit comments

Comments
 (0)