/** * Detect what device the current session was requested from. * * @param $simulate Name of device to simulate (self::DEVICE_*) * @return MobileDeviceDetection */ public static function detect(MobileDevice $device = null) { $result = new MobileDetectorResults(); $data = $_SERVER; // Simulate a particular device? if ($device) { $data = $device->simulate($data); } // Something to do with detecting WAP support: if (isset($data['HTTP_X_WAP_PROFILE']) || preg_match('%wap\\.|\\.wap%i', $data['HTTP_ACCEPT'])) { $result->pass(); } // Make sure no negative matches apply, not a mobile: foreach (self::$negatives as $match) { if (!preg_match($match, $data['HTTP_USER_AGENT'])) { continue; } $result->fail(); return $result; } // Check for generic mobile device, not a mobile: foreach (self::$positives as $match) { if (!preg_match($match, $data['HTTP_USER_AGENT'])) { continue; } $result->pass(); break; } // Check for matches, is a mobile: foreach (self::$devices as $device) { $device->detect($data, $result); } // No decision yet, not a mobile: if (!$result->done()) { $result->fail(); } return $result; }