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 | * Class constructor. |
||
64 | */ |
||
65 | public function __construct(array $headers = null, $userAgent = null) |
||
74 | |||
75 | /** |
||
76 | * Set HTTP headers. |
||
77 | * |
||
78 | * @param array $httpHeaders |
||
79 | */ |
||
80 | public function setHttpHeaders($httpHeaders = null) |
||
96 | |||
97 | /** |
||
98 | * Return user agent headers. |
||
99 | * |
||
100 | * @return array |
||
101 | */ |
||
102 | public function getUaHttpHeaders() |
||
106 | |||
107 | /** |
||
108 | * Set the user agent. |
||
109 | * |
||
110 | * @param string $userAgent |
||
111 | */ |
||
112 | public function setUserAgent($userAgent = null) |
||
127 | |||
128 | /** |
||
129 | * Build the user agent regex. |
||
130 | * |
||
131 | * @return string |
||
132 | */ |
||
133 | public function getRegex() |
||
137 | |||
138 | /** |
||
139 | * Build the replacement regex. |
||
140 | * |
||
141 | * @return string |
||
142 | */ |
||
143 | public function getExclusions() |
||
147 | |||
148 | /** |
||
149 | * Check user agent string against the regex. |
||
150 | * |
||
151 | * @param string $userAgent |
||
152 | * |
||
153 | * @return bool |
||
154 | */ |
||
155 | public function isCrawler($userAgent = null) |
||
173 | |||
174 | /** |
||
175 | * Return the matches. |
||
176 | * |
||
177 | * @return string |
||
178 | */ |
||
179 | public function getMatches() |
||
183 | } |
||
184 |
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: