Total Complexity | 5 |
Total Lines | 34 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
8 | trait KeyValidatorTrait |
||
9 | { |
||
10 | /** |
||
11 | * Verifies the given cache key is a legal value. |
||
12 | * |
||
13 | * @param mixed $key The cache key to validate. |
||
14 | * |
||
15 | * @return void |
||
16 | * |
||
17 | * @throws InvalidArgumentException Thrown if the $key string is not a legal value. |
||
18 | */ |
||
19 | protected function validateKey($key) |
||
20 | { |
||
21 | if (!is_string($key) || $key === '') { |
||
22 | throw new InvalidArgumentException('$key must be a valid non empty string'); |
||
23 | } |
||
24 | |||
25 | if (preg_match('#[{}()/\\\@:]#', $key) > 0) { |
||
26 | throw new InvalidArgumentException("Key '{$key}' contains unsupported characters"); |
||
27 | } |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * Verifies all of the given cache keys are a legal values. |
||
32 | * |
||
33 | * @param array $keys The collection cache key to validate. |
||
34 | * |
||
35 | * @return void |
||
36 | * |
||
37 | * @throws InvalidArgumentException Thrown if the $key string is not a legal value. |
||
38 | */ |
||
39 | protected function validateKeys(array $keys) |
||
42 | } |
||
43 | } |
||
44 |