1 | <?php |
||
9 | final class Pattern |
||
10 | { |
||
11 | private function __construct() |
||
14 | |||
15 | /** |
||
16 | * Gets a hash or an array of hashes from the first characters of a pattern/user agent, that can |
||
17 | * be used for a fast comparison, by comparing only the hashes, without having to match the |
||
18 | * complete pattern against the user agent. |
||
19 | * |
||
20 | * With the variants options, all variants from the maximum number of pattern characters to one |
||
21 | * character will be returned. This is required in some cases, the a placeholder is used very |
||
22 | * early in the pattern. |
||
23 | * |
||
24 | * Example: |
||
25 | * |
||
26 | * Pattern: "Mozilla/* (Nintendo 3DS; *) Version/*" |
||
27 | * User agent: "Mozilla/5.0 (Nintendo 3DS; U; ; en) Version/1.7567.US" |
||
28 | * |
||
29 | * In this case the has for the pattern is created for "Mozilla/" while the pattern |
||
30 | * for the hash for user agent is created for "Mozilla/5.0". The variants option |
||
31 | * results in an array with hashes for "Mozilla/5.0", "Mozilla/5.", "Mozilla/5", |
||
32 | * "Mozilla/" ... "M", so that the pattern hash is included. |
||
33 | * |
||
34 | * @param string $pattern |
||
35 | * @param bool $variants |
||
36 | * @return string|array |
||
37 | */ |
||
38 | 3 | public static function getHashForPattern(string $pattern, bool $variants = false) |
|
67 | |||
68 | /** |
||
69 | * returns a hash for one pattern |
||
70 | * |
||
71 | * @param $pattern |
||
72 | * |
||
73 | * @return string |
||
74 | */ |
||
75 | 1 | public static function getHashForParts(string $pattern) : string |
|
79 | |||
80 | /** |
||
81 | * Gets the minimum length of the patern (used in the getPatterns() method to |
||
82 | * check against the user agent length) |
||
83 | * |
||
84 | * @param string $pattern |
||
85 | * @return int |
||
86 | */ |
||
87 | 1 | public static function getPatternLength(string $pattern) : int |
|
91 | } |
||
92 |