1 | <?php |
||
17 | final class Pattern |
||
18 | { |
||
19 | private function __construct() |
||
22 | |||
23 | /** |
||
24 | * Gets a hash or an array of hashes from the first characters of a pattern/user agent, that can |
||
25 | * be used for a fast comparison, by comparing only the hashes, without having to match the |
||
26 | * complete pattern against the user agent. |
||
27 | * |
||
28 | * With the variants options, all variants from the maximum number of pattern characters to one |
||
29 | * character will be returned. This is required in some cases, the a placeholder is used very |
||
30 | * early in the pattern. |
||
31 | * |
||
32 | * Example: |
||
33 | * |
||
34 | * Pattern: "Mozilla/* (Nintendo 3DS; *) Version/*" |
||
35 | * User agent: "Mozilla/5.0 (Nintendo 3DS; U; ; en) Version/1.7567.US" |
||
36 | * |
||
37 | * In this case the has for the pattern is created for "Mozilla/" while the pattern |
||
38 | * for the hash for user agent is created for "Mozilla/5.0". The variants option |
||
39 | * results in an array with hashes for "Mozilla/5.0", "Mozilla/5.", "Mozilla/5", |
||
40 | * "Mozilla/" ... "M", so that the pattern hash is included. |
||
41 | * |
||
42 | * @param string $pattern |
||
43 | * @param bool $variants |
||
44 | * |
||
45 | * @return string[] |
||
46 | */ |
||
47 | 2 | public static function getHashForPattern(string $pattern, bool $variants = false) : array |
|
76 | |||
77 | /** |
||
78 | * returns a hash for one pattern |
||
79 | * |
||
80 | * @param $pattern |
||
81 | * |
||
82 | * @return string |
||
83 | */ |
||
84 | 1 | public static function getHashForParts(string $pattern) : string |
|
88 | |||
89 | /** |
||
90 | * Gets the minimum length of the patern (used in the getPatterns() method to |
||
91 | * check against the user agent length) |
||
92 | * |
||
93 | * @param string $pattern |
||
94 | * |
||
95 | * @return int |
||
96 | */ |
||
97 | 1 | public static function getPatternLength(string $pattern) : int |
|
101 | } |
||
102 |