Skip to content

Commit 2badbe8

Browse files
committed
require php ^8.0
1 parent 571d70c commit 2badbe8

6 files changed

Lines changed: 164 additions & 153 deletions

File tree

composer.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
{
2-
"name": "ihipop/psr-null-cache",
2+
"name": "valgorithms/psr-null-cache",
33
"type": "library",
4-
"homepage": "https://github.com/ihipop/PSR-NullCache",
4+
"homepage": "https://github.com/valgorithms/PSR-NullCache",
55
"description": "NullCache implementation (Fake Storage) of PSR-16 with Basic data validation",
66
"license": "LGPL-3.0+",
77
"authors": [
88
{
99
"name": "ihipop",
1010
"email": "ihipop@gmail.com"
11+
},
12+
{
13+
"name": "Valithor Obisdion",
14+
"email": "valithor@valgorithms.com"
1115
}
1216
],
1317
"require": {
18+
"php": "^8.0",
1419
"psr/simple-cache": "^1.0",
1520
"psr/cache": "^1.0"
1621
},
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
namespace ihipop\PsrNullCache\Exception;
44

55
use Psr\Cache\InvalidArgumentException as Psr6CacheInvalidArgumentExceptionInterface;
66
use Psr\SimpleCache\InvalidArgumentException as SimpleCacheInvalidArgumentExceptionInterface;
77

88
class InvalidArgumentException extends \InvalidArgumentException implements Psr6CacheInvalidArgumentExceptionInterface, SimpleCacheInvalidArgumentExceptionInterface
9-
{
10-
11-
}
9+
{}
Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,55 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
namespace ihipop\PsrNullCache\SimpleCache;
44

5+
use Psr\SimpleCache\CacheInterface;
6+
57
trait CacheInterfaceProxy
68
{
9+
protected CacheInterface $realCacheClient;
710

8-
/** @var \Psr\SimpleCache\CacheInterface */
9-
protected $realCacheClient;
10-
11-
public function __call($name, $arguments)
11+
public function __call(string $name, array $arguments): mixed
1212
{
1313
return call_user_func_array([$this->realCacheClient, $name], $arguments);
1414
}
1515

1616
/** @inheritdoc */
17-
public function set($key, $value, $ttl = null)
17+
public function get($key, $default = null)
1818
{
19-
2019
return call_user_func_array([$this->realCacheClient, __FUNCTION__], func_get_args());
2120
}
2221

2322
/** @inheritdoc */
24-
public function get($key, $default = null)
23+
public function set($key, $value, $ttl = null)
2524
{
2625
return call_user_func_array([$this->realCacheClient, __FUNCTION__], func_get_args());
2726
}
2827

2928
/** @inheritdoc */
30-
public function getMultiple($keys, $default = null)
29+
public function delete($key)
3130
{
3231
return call_user_func_array([$this->realCacheClient, __FUNCTION__], func_get_args());
3332
}
3433

3534
/** @inheritdoc */
36-
public function setMultiple($values, $ttl = null)
35+
public function clear()
3736
{
3837
return call_user_func_array([$this->realCacheClient, __FUNCTION__], func_get_args());
3938
}
4039

4140
/** @inheritdoc */
42-
public function delete($key)
41+
public function getMultiple($keys, $default = null)
4342
{
4443
return call_user_func_array([$this->realCacheClient, __FUNCTION__], func_get_args());
4544
}
4645

4746
/** @inheritdoc */
48-
public function clear()
47+
public function setMultiple($values, $ttl = null)
4948
{
5049
return call_user_func_array([$this->realCacheClient, __FUNCTION__], func_get_args());
5150
}
5251

5352
/** @inheritdoc */
54-
5553
public function deleteMultiple($keys)
5654
{
5755
return call_user_func_array([$this->realCacheClient, __FUNCTION__], func_get_args());
@@ -62,4 +60,4 @@ public function has($key)
6260
{
6361
return call_user_func_array([$this->realCacheClient, __FUNCTION__], func_get_args());
6462
}
65-
}
63+
}

src/SimpleCache/NullCache.php

Lines changed: 3 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,17 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
namespace ihipop\PsrNullCache\SimpleCache;
44

55
use Psr\SimpleCache\CacheInterface;
6-
use ihipop\PsrNullCache\Exception\InvalidArgumentException;
76

87
class NullCache implements CacheInterface
98
{
10-
11-
protected $defaultBool = false;
9+
protected bool $defaultBool;
1210

1311
public function __construct(bool $defaultBool = false)
1412
{
1513
$this->defaultBool = $defaultBool;
1614
}
1715

18-
public static function typeString($object){
19-
return \is_object($object) ? \get_class($object) : \gettype($object);
20-
}
21-
22-
public static function validateKey($key)
23-
{
24-
if (!\is_string($key)) {
25-
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given', self::typeString($key)));
26-
}
27-
if ('' === $key) {
28-
throw new InvalidArgumentException('Cache key length must be greater than zero');
29-
}
30-
if (false !== strpbrk($key, '{}()/\@:')) {
31-
throw new InvalidArgumentException(sprintf('Cache key "%s" contains reserved characters {}()/\@:', $key));
32-
}
33-
34-
return $key;
35-
}
36-
37-
public static function traversToArray($travers)
38-
{
39-
if ($travers instanceof \Traversable) {
40-
$travers = iterator_to_array($travers, false);
41-
}
42-
if (!\is_array($travers)) {
43-
throw new InvalidArgumentException(sprintf('Cache keys must be array or Traversable, "%s" given',
44-
self::typeString($travers)));
45-
}
46-
47-
return $travers;
48-
}
49-
50-
/** @inheritdoc */
51-
public function get($key, $default = null)
52-
{
53-
54-
self::validateKey($key);
55-
56-
return $default;
57-
}
58-
59-
/** @inheritdoc */
60-
public function set($key, $value, $ttl = null)
61-
{
62-
self::validateKey($key);
63-
64-
return $this->defaultBool;
65-
}
66-
67-
/** @inheritdoc */
68-
public function delete($key)
69-
{
70-
self::validateKey($key);
71-
72-
return $this->defaultBool;
73-
}
74-
75-
/** @inheritdoc */
76-
public function clear()
77-
{
78-
return $this->defaultBool;
79-
}
80-
81-
/** @inheritdoc */
82-
public function getMultiple($keys, $default = null)
83-
{
84-
$keys = self::traversToArray($keys);
85-
foreach ($keys as $value) {
86-
self::validateKey($value);
87-
}
88-
foreach ($keys as $key) {
89-
yield $key => $default;
90-
}
91-
}
92-
93-
/** @inheritdoc */
94-
public function setMultiple($values, $ttl = null)
95-
{
96-
$KeyValues = self::traversToArray($values);
97-
98-
foreach ($KeyValues as $key=>$__){
99-
self::validateKey($key);
100-
}
101-
102-
return $this->defaultBool;
103-
}
104-
105-
/** @inheritdoc */
106-
public function deleteMultiple($keys)
107-
{
108-
$keys = self::traversToArray($keys);
109-
foreach ($keys as $value) {
110-
self::validateKey($value);
111-
}
112-
113-
return $this->defaultBool;
114-
}
115-
116-
/** @inheritdoc */
117-
public function has($key)
118-
{
119-
self::validateKey($key);
120-
121-
return $this->defaultBool;
122-
}
16+
use NullCacheTrait;
12317
}

src/SimpleCache/NullCacheTrait.php

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace ihipop\PsrNullCache\SimpleCache;
4+
5+
use ihipop\PsrNullCache\Exception\InvalidArgumentException;
6+
7+
trait NullCacheTrait
8+
{
9+
public static function typeString(mixed $object): string
10+
{
11+
return \is_object($object) ? \get_class($object) : \gettype($object);
12+
}
13+
14+
public static function validateKey(mixed $key): string
15+
{
16+
if (!\is_string($key)) {
17+
throw new InvalidArgumentException(sprintf('Cache key must be string, "%s" given', self::typeString($key)));
18+
}
19+
if ('' === $key) {
20+
throw new InvalidArgumentException('Cache key length must be greater than zero');
21+
}
22+
if (false !== strpbrk($key, '{}()/\@:')) {
23+
throw new InvalidArgumentException(sprintf('Cache key "%s" contains reserved characters {}()/\@:', $key));
24+
}
25+
26+
return $key;
27+
}
28+
29+
public static function traversToArray(mixed $travers): array
30+
{
31+
if ($travers instanceof \Traversable) {
32+
$travers = iterator_to_array($travers, false);
33+
}
34+
if (!\is_array($travers)) {
35+
throw new InvalidArgumentException(sprintf('Cache keys must be array or Traversable, "%s" given',
36+
self::typeString($travers)));
37+
}
38+
39+
return $travers;
40+
}
41+
42+
/** @inheritdoc */
43+
public function get($key, $default = null)
44+
{
45+
self::validateKey($key);
46+
47+
return $default;
48+
}
49+
50+
/** @inheritdoc */
51+
public function set($key, $value, $ttl = null)
52+
{
53+
self::validateKey($key);
54+
55+
return $this->defaultBool;
56+
}
57+
58+
/** @inheritdoc */
59+
public function delete($key)
60+
{
61+
self::validateKey($key);
62+
63+
return $this->defaultBool;
64+
}
65+
66+
/** @inheritdoc */
67+
public function clear()
68+
{
69+
return $this->defaultBool;
70+
}
71+
72+
/** @inheritdoc */
73+
public function getMultiple($keys, $default = null)
74+
{
75+
$keys = self::traversToArray($keys);
76+
foreach ($keys as $value) {
77+
self::validateKey($value);
78+
}
79+
foreach ($keys as $key) {
80+
yield $key => $default;
81+
}
82+
}
83+
84+
/** @inheritdoc */
85+
public function setMultiple($values, $ttl = null)
86+
{
87+
$KeyValues = self::traversToArray($values);
88+
89+
foreach ($KeyValues as $key => $__) {
90+
self::validateKey($key);
91+
}
92+
93+
return $this->defaultBool;
94+
}
95+
96+
/** @inheritdoc */
97+
public function deleteMultiple($keys)
98+
{
99+
$keys = self::traversToArray($keys);
100+
foreach ($keys as $value) {
101+
self::validateKey($value);
102+
}
103+
104+
return $this->defaultBool;
105+
}
106+
107+
/** @inheritdoc */
108+
public function has($key)
109+
{
110+
self::validateKey($key);
111+
112+
return $this->defaultBool;
113+
}
114+
}

0 commit comments

Comments
 (0)