Skip to content

Commit c09d7d0

Browse files
committed
Added test for option "itemDetailedDate"
1 parent 5328f5f commit c09d7d0

File tree

27 files changed

+220
-223
lines changed

27 files changed

+220
-223
lines changed

src/phpFastCache/Core/Item/ItemExtendedTrait.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use phpFastCache\Core\Pool\ExtendedCacheItemPoolInterface;
1919
use phpFastCache\EventManager;
2020
use phpFastCache\Exceptions\{
21-
phpFastCacheInvalidArgumentException, phpFastCacheLogicException
21+
phpFastCacheInvalidArgumentException, phpFastCacheInvalidArgumentTypeException, phpFastCacheLogicException
2222
};
2323

2424
/**
@@ -56,6 +56,28 @@ trait ItemExtendedTrait
5656
*/
5757
protected $encodedKey;
5858

59+
/**
60+
* Item constructor.
61+
* @param ExtendedCacheItemPoolInterface $driver
62+
* @param $key
63+
* @throws phpFastCacheInvalidArgumentException
64+
*/
65+
public function __construct(ExtendedCacheItemPoolInterface $driver, $key)
66+
{
67+
if (is_string($key)) {
68+
$this->key = $key;
69+
$this->driver = $driver;
70+
$this->driver->setItem($this);
71+
$this->expirationDate = new \DateTime();
72+
if($this->driver->getConfigOption('itemDetailedDate')){
73+
$this->creationDate = new \DateTime();
74+
$this->modificationDate = new \DateTime();
75+
}
76+
} else {
77+
throw new phpFastCacheInvalidArgumentTypeException('string', $key);
78+
}
79+
}
80+
5981
/**
6082
* @return string
6183
*/

src/phpFastCache/Core/Pool/CacheItemPoolTrait.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ public function getItem($key)
128128
$item->set($driverData);
129129
$item->expiresAt($this->driverUnwrapEdate($driverArray));
130130

131-
if ($this->config[ 'itemDetailedDate' ]) {
132-
131+
if ($this->getConfigOption( 'itemDetailedDate')) {
133132
/**
134133
* If the itemDetailedDate has been
135134
* set after caching, we MUST inject
@@ -159,7 +158,7 @@ public function getItem($key)
159158
->expiresAfter(abs((int)$this->getConfig()[ 'defaultTtl' ]))
160159
->setHit(false)
161160
->setTags([]);
162-
if ($this->config[ 'itemDetailedDate' ]) {
161+
if ($this->getConfigOption( 'itemDetailedDate')) {
163162

164163
/**
165164
* If the itemDetailedDate has been

src/phpFastCache/Drivers/Apc/Item.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,19 @@
2828
*/
2929
class Item implements ExtendedCacheItemInterface
3030
{
31-
use ItemBaseTrait;
31+
use ItemBaseTrait{
32+
ItemBaseTrait::__construct as __BaseConstruct;
33+
}
3234

3335
/**
3436
* Item constructor.
3537
* @param \phpFastCache\Drivers\Apc\Driver $driver
3638
* @param $key
37-
* @throws phpFastCacheInvalidArgumentTypeException
39+
* @throws phpFastCacheInvalidArgumentException
3840
*/
3941
public function __construct(ApcDriver $driver, $key)
4042
{
41-
if (is_string($key)) {
42-
$this->key = $key;
43-
$this->driver = $driver;
44-
$this->driver->setItem($this);
45-
$this->expirationDate = new \DateTime();
46-
} else {
47-
throw new phpFastCacheInvalidArgumentTypeException('string', $key);
48-
}
43+
$this->__BaseConstruct($driver, $key);
4944
}
5045

5146
/**

src/phpFastCache/Drivers/Apcu/Item.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
*/
2929
class Item implements ExtendedCacheItemInterface
3030
{
31-
use ItemBaseTrait;
31+
use ItemBaseTrait{
32+
ItemBaseTrait::__construct as __BaseConstruct;
33+
}
3234

3335
/**
3436
* Item constructor.
@@ -38,14 +40,7 @@ class Item implements ExtendedCacheItemInterface
3840
*/
3941
public function __construct(ApcuDriver $driver, $key)
4042
{
41-
if (is_string($key)) {
42-
$this->key = $key;
43-
$this->driver = $driver;
44-
$this->driver->setItem($this);
45-
$this->expirationDate = new \DateTime();
46-
} else {
47-
throw new phpFastCacheInvalidArgumentTypeException('string', $key);
48-
}
43+
$this->__BaseConstruct($driver, $key);
4944
}
5045

5146
/**

src/phpFastCache/Drivers/Cassandra/Item.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
*/
3030
class Item implements ExtendedCacheItemInterface
3131
{
32-
use ItemBaseTrait;
32+
use ItemBaseTrait{
33+
ItemBaseTrait::__construct as __BaseConstruct;
34+
}
3335

3436
/**
3537
* Item constructor.
@@ -39,14 +41,7 @@ class Item implements ExtendedCacheItemInterface
3941
*/
4042
public function __construct(CassandraDriver $driver, $key)
4143
{
42-
if (is_string($key)) {
43-
$this->key = $key;
44-
$this->driver = $driver;
45-
$this->driver->setItem($this);
46-
$this->expirationDate = new \DateTime();
47-
} else {
48-
throw new phpFastCacheInvalidArgumentTypeException('string', $key);
49-
}
44+
$this->__BaseConstruct($driver, $key);
5045
}
5146

5247
/**

src/phpFastCache/Drivers/Cookie/Item.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
*/
2929
class Item implements ExtendedCacheItemInterface
3030
{
31-
use ItemBaseTrait;
31+
use ItemBaseTrait{
32+
ItemBaseTrait::__construct as __BaseConstruct;
33+
}
3234

3335
/**
3436
* Item constructor.
@@ -38,15 +40,7 @@ class Item implements ExtendedCacheItemInterface
3840
*/
3941
public function __construct(CookieDriver $driver, $key)
4042
{
41-
if (is_string($key)) {
42-
$this->expirationDate = new \DateTime();
43-
$this->key = $key;
44-
$this->driver = $driver;
45-
$this->driver->setItem($this);
46-
} else {
47-
throw new phpFastCacheInvalidArgumentException(sprintf('$key must be a string, got type "%s" instead.',
48-
gettype($key)));
49-
}
43+
$this->__BaseConstruct($driver, $key);
5044
}
5145

5246

src/phpFastCache/Drivers/Couchbase/Item.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
*/
2929
class Item implements ExtendedCacheItemInterface
3030
{
31-
use ItemBaseTrait;
31+
use ItemBaseTrait{
32+
ItemBaseTrait::__construct as __BaseConstruct;
33+
}
3234

3335
/**
3436
* Item constructor.
@@ -38,14 +40,7 @@ class Item implements ExtendedCacheItemInterface
3840
*/
3941
public function __construct(CouchbaseDriver $driver, $key)
4042
{
41-
if (is_string($key)) {
42-
$this->key = $key;
43-
$this->driver = $driver;
44-
$this->driver->setItem($this);
45-
$this->expirationDate = new \DateTime();
46-
} else {
47-
throw new phpFastCacheInvalidArgumentTypeException('string', $key);
48-
}
43+
$this->__BaseConstruct($driver, $key);
4944
}
5045

5146
/**

src/phpFastCache/Drivers/Couchdb/Item.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
*/
3030
class Item implements ExtendedCacheItemInterface
3131
{
32-
use ItemBaseTrait;
32+
use ItemBaseTrait{
33+
ItemBaseTrait::__construct as __BaseConstruct;
34+
}
3335

3436
/**
3537
* Item constructor.
@@ -39,14 +41,7 @@ class Item implements ExtendedCacheItemInterface
3941
*/
4042
public function __construct(CouchdbDriver $driver, $key)
4143
{
42-
if (is_string($key)) {
43-
$this->key = $key;
44-
$this->driver = $driver;
45-
$this->driver->setItem($this);
46-
$this->expirationDate = new \DateTime();
47-
} else {
48-
throw new phpFastCacheInvalidArgumentTypeException('string', $key);
49-
}
44+
$this->__BaseConstruct($driver, $key);
5045
}
5146

5247
/**

src/phpFastCache/Drivers/Devfalse/Item.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
*/
3030
class Item implements ExtendedCacheItemInterface
3131
{
32-
use ItemBaseTrait;
32+
use ItemBaseTrait{
33+
ItemBaseTrait::__construct as __BaseConstruct;
34+
}
3335

3436
/**
3537
* Item constructor.
@@ -39,14 +41,7 @@ class Item implements ExtendedCacheItemInterface
3941
*/
4042
public function __construct(DevfalseDriver $driver, $key)
4143
{
42-
if (is_string($key)) {
43-
$this->key = $key;
44-
$this->driver = $driver;
45-
$this->driver->setItem($this);
46-
$this->expirationDate = new \DateTime();
47-
} else {
48-
throw new phpFastCacheInvalidArgumentTypeException('string', $key);
49-
}
44+
$this->__BaseConstruct($driver, $key);
5045
}
5146

5247
/**

src/phpFastCache/Drivers/Devnull/Item.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
*/
2929
class Item implements ExtendedCacheItemInterface
3030
{
31-
use ItemBaseTrait;
31+
use ItemBaseTrait{
32+
ItemBaseTrait::__construct as __BaseConstruct;
33+
}
3234

3335
/**
3436
* Item constructor.
@@ -38,14 +40,7 @@ class Item implements ExtendedCacheItemInterface
3840
*/
3941
public function __construct(DevnullDriver $driver, $key)
4042
{
41-
if (is_string($key)) {
42-
$this->key = $key;
43-
$this->driver = $driver;
44-
$this->driver->setItem($this);
45-
$this->expirationDate = new \DateTime();
46-
} else {
47-
throw new phpFastCacheInvalidArgumentTypeException('string', $key);
48-
}
43+
$this->__BaseConstruct($driver, $key);
4944
}
5045

5146
/**

0 commit comments

Comments
 (0)