1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
|
4
|
|
|
namespace BrowscapPHP\Parser\Helper; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* includes general functions for the work with patterns |
8
|
|
|
*/ |
9
|
|
|
final class SubKey |
10
|
|
|
{ |
11
|
|
|
private function __construct() |
12
|
|
|
{ |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Gets the subkey for the pattern cache file, generated from the given string |
17
|
|
|
* |
18
|
|
|
* @param string $string |
19
|
|
|
* |
20
|
|
|
* @return string |
21
|
|
|
*/ |
22
|
1 |
|
public static function getPatternCacheSubkey(string $string) : string |
23
|
|
|
{ |
24
|
1 |
|
return $string[0] . $string[1]; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Gets all subkeys for the pattern cache files |
29
|
|
|
* |
30
|
|
|
* @return string[] |
31
|
|
|
*/ |
32
|
1 |
|
public static function getAllPatternCacheSubkeys() : array |
33
|
|
|
{ |
34
|
1 |
|
$subkeys = []; |
35
|
1 |
|
$chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']; |
36
|
|
|
|
37
|
1 |
|
foreach ($chars as $charOne) { |
38
|
1 |
|
foreach ($chars as $charTwo) { |
39
|
1 |
|
$subkeys[$charOne . $charTwo] = ''; |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
1 |
|
return $subkeys; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Gets the sub key for the ini parts cache file, generated from the given string |
48
|
|
|
* |
49
|
|
|
* @param string $string |
50
|
|
|
* |
51
|
|
|
* @return string |
52
|
|
|
*/ |
53
|
|
|
public static function getIniPartCacheSubKey(string $string) : string |
54
|
|
|
{ |
55
|
|
|
return $string[0] . $string[1] . $string[2]; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Gets all sub keys for the inipart cache files |
60
|
|
|
* |
61
|
|
|
* @return string[] |
62
|
|
|
*/ |
63
|
|
|
public static function getAllIniPartCacheSubKeys() : array |
64
|
|
|
{ |
65
|
|
|
$subKeys = []; |
66
|
|
|
$chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']; |
67
|
|
|
|
68
|
|
|
foreach ($chars as $charOne) { |
69
|
|
|
foreach ($chars as $charTwo) { |
70
|
|
|
foreach ($chars as $charThree) { |
71
|
|
|
$subKeys[] = $charOne . $charTwo . $charThree; |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return $subKeys; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|