1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace kalanis\kw_cache_psr\Traits; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use kalanis\kw_cache_psr\InvalidArgumentException; |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Trait TCheckKey |
11
|
|
|
* @package kalanis\kw_cache_psr\Traits |
12
|
|
|
* Check key for problematic characters |
13
|
|
|
*/ |
14
|
|
|
trait TCheckKey |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @param string $key |
18
|
|
|
* @return string |
19
|
|
|
* @throws InvalidArgumentException |
20
|
|
|
*/ |
21
|
48 |
|
protected function checkKey(string $key): string |
22
|
|
|
{ |
23
|
|
|
// problematic chars |
24
|
|
|
// {}()/\@: |
25
|
48 |
|
if (false !== strpos($key, '{')) { |
26
|
7 |
|
throw new InvalidArgumentException(sprintf('The key *%s* contains "{"', $key)); |
27
|
|
|
} |
28
|
43 |
|
if (false !== strpos($key, '}')) { |
29
|
1 |
|
throw new InvalidArgumentException(sprintf('The key *%s* contains "}"', $key)); |
30
|
|
|
} |
31
|
42 |
|
if (false !== strpos($key, '(')) { |
32
|
1 |
|
throw new InvalidArgumentException(sprintf('The key *%s* contains "("', $key)); |
33
|
|
|
} |
34
|
41 |
|
if (false !== strpos($key, ')')) { |
35
|
1 |
|
throw new InvalidArgumentException(sprintf('The key *%s* contains ")"', $key)); |
36
|
|
|
} |
37
|
40 |
|
if (false !== strpos($key, '/')) { |
38
|
1 |
|
throw new InvalidArgumentException(sprintf('The key *%s* contains "/"', $key)); |
39
|
|
|
} |
40
|
39 |
|
if (false !== strpos($key, '\\')) { |
41
|
1 |
|
throw new InvalidArgumentException(sprintf('The key *%s* contains "\\"', $key)); |
42
|
|
|
} |
43
|
38 |
|
if (false !== strpos($key, '@')) { |
44
|
1 |
|
throw new InvalidArgumentException(sprintf('The key *%s* contains "@"', $key)); |
45
|
|
|
} |
46
|
37 |
|
if (false !== strpos($key, ':')) { |
47
|
1 |
|
throw new InvalidArgumentException(sprintf('The key *%s* contains ":"', $key)); |
48
|
|
|
} |
49
|
36 |
|
return $key; |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|