1 | <?php |
||
18 | class CrawlerDetect |
||
19 | { |
||
20 | /** |
||
21 | * The user agent. |
||
22 | * |
||
23 | * @var null |
||
24 | */ |
||
25 | protected $userAgent = null; |
||
26 | |||
27 | /** |
||
28 | * Headers that contain a user agent. |
||
29 | * |
||
30 | * @var array |
||
31 | */ |
||
32 | protected $httpHeaders = array(); |
||
33 | |||
34 | /** |
||
35 | * Store regex matches. |
||
36 | * |
||
37 | * @var array |
||
38 | */ |
||
39 | protected $matches = array(); |
||
40 | |||
41 | /** |
||
42 | * Crawlers object. |
||
43 | * |
||
44 | * @var \Jaybizzle\CrawlerDetect\Fixtures\Crawlers |
||
45 | */ |
||
46 | protected $crawlers; |
||
47 | |||
48 | /** |
||
49 | * Exclusions object. |
||
50 | * |
||
51 | * @var \Jaybizzle\CrawlerDetect\Fixtures\Exclusions |
||
52 | */ |
||
53 | protected $exclusions; |
||
54 | |||
55 | /** |
||
56 | * Headers object. |
||
57 | * |
||
58 | * @var \Jaybizzle\CrawlerDetect\Fixtures\Headers |
||
59 | */ |
||
60 | protected $uaHttpHeaders; |
||
61 | |||
62 | /** |
||
63 | * The compiled regex string. |
||
64 | * |
||
65 | * @var string |
||
66 | */ |
||
67 | protected $compiledRegex; |
||
68 | |||
69 | /** |
||
70 | * The compiled exclusions regex string. |
||
71 | * |
||
72 | * @var string |
||
73 | */ |
||
74 | protected $compiledExclusions; |
||
75 | |||
76 | /** |
||
77 | * Class constructor. |
||
78 | */ |
||
79 | public function __construct(array $headers = null, $userAgent = null) |
||
91 | |||
92 | /** |
||
93 | * Compile the regex patterns into one regex string. |
||
94 | * |
||
95 | * @param array |
||
96 | * |
||
97 | * @return string |
||
98 | */ |
||
99 | public function compileRegex($patterns) |
||
103 | |||
104 | /** |
||
105 | * Set HTTP headers. |
||
106 | * |
||
107 | * @param array $httpHeaders |
||
108 | */ |
||
109 | public function setHttpHeaders($httpHeaders = null) |
||
127 | |||
128 | /** |
||
129 | * Return user agent headers. |
||
130 | * |
||
131 | * @return array |
||
132 | */ |
||
133 | public function getUaHttpHeaders() |
||
137 | |||
138 | /** |
||
139 | * Set the user agent. |
||
140 | * |
||
141 | * @param string $userAgent |
||
142 | */ |
||
143 | public function setUserAgent($userAgent = null) |
||
158 | |||
159 | /** |
||
160 | * Check user agent string against the regex. |
||
161 | * |
||
162 | * @param string $userAgent |
||
163 | * |
||
164 | * @return bool |
||
165 | */ |
||
166 | public function isCrawler($userAgent = null) |
||
184 | |||
185 | /** |
||
186 | * Return the matches. |
||
187 | * |
||
188 | * @return string|null |
||
189 | */ |
||
190 | public function getMatches() |
||
194 | } |
||
195 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: