1 | <?php |
||
12 | abstract class Agent { |
||
13 | |||
14 | private static $mobiles = [], $robots = []; |
||
15 | |||
16 | /** |
||
17 | * Search an agent in the list |
||
18 | * |
||
19 | * @return bool : true if the agent is present in the list, otherwise false |
||
20 | */ |
||
21 | |||
22 | private static function search(array &$list) : bool { |
||
32 | |||
33 | /** |
||
34 | * Autoloader |
||
35 | */ |
||
36 | |||
37 | public static function __autoload() { |
||
38 | |||
39 | $file_mobiles = (DIR_DATA . 'Agent/Mobiles.php'); |
||
40 | |||
41 | $file_robots = (DIR_DATA . 'Agent/Robots.php'); |
||
42 | |||
43 | if (is_array($mobiles = Explorer::include($file_mobiles))) self::$mobiles = $mobiles; |
||
44 | |||
45 | if (is_array($robots = Explorer::include($file_robots))) self::$robots = $robots; |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * Check if a current user agent is a mobile device |
||
50 | * |
||
51 | * @return bool : true if the agent is present in the mobile devices list, otherwise false |
||
52 | */ |
||
53 | |||
54 | public static function isMobile() : bool { |
||
55 | |||
56 | return self::search(self::$mobiles); |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * Check if a current user agent is a robot |
||
61 | * |
||
62 | * @return bool : true if the agent is present in the robots list, otherwise false |
||
63 | */ |
||
64 | |||
65 | public static function isRobot() : bool { |
||
66 | |||
67 | return self::search(self::$robots); |
||
68 | } |
||
69 | } |
||
70 | } |
||
71 |