Ejemplo n.º 1
0
 /**
  *
  */
 public function testConstruct()
 {
     $userAgent = 'Mozilla/5.0 (Randomized by FreeSafeIP.com/upgrade-to-remove; compatible; MSIE 8.0; Windows NT 5.0) Chrome/21.0.1229.79';
     $header = array('HTTP_USER_AGENT' => $userAgent);
     $request = new GenericRequest($header, $userAgent, null, false);
     $device = new Device($request);
     self::assertSame($request, $device->getHttpRequest());
     self::assertSame($userAgent, $device->getDeviceUa());
     self::assertSame($userAgent, $device->getBrowserUa());
     self::assertSame($device->getBrowserUaNormalized(), $device->getDeviceUaNormalized());
     self::assertInstanceOf('\\Wurfl\\VirtualCapability\\Tool\\NameVersionPair', $device->getBrowser());
     self::assertInstanceOf('\\Wurfl\\VirtualCapability\\Tool\\NameVersionPair', $device->getOs());
 }
Ejemplo n.º 2
0
 /**
  * normalize the OS Information
  *
  * @param \Wurfl\VirtualCapability\Tool\Device $device
  */
 private static function normalizeOS(Device $device)
 {
     if (strpos($device->getDeviceUa(), 'Windows') !== false) {
         if (preg_match('/Windows NT ([0-9]+?\\.[0-9])/', $device->getOs()->name, $matches)) {
             $device->getOs()->name = 'Windows';
             $device->getOs()->version = array_key_exists($matches[1], self::$windowsMap) ? self::$windowsMap[$matches[1]] : $matches[1];
             return;
         }
         if (preg_match('/Windows [0-9\\.]+/', $device->getOs()->name)) {
             return;
         }
     }
     if (strpos($device->getOs()->name, 'Windows Phone') !== false) {
         if (array_key_exists($device->getOs()->version, self::$wds_map)) {
             $device->getOs()->version = self::$wds_map[$device->getOs()->version];
             return;
         }
     }
     if ($device->getOs()->setRegex($device->getDeviceUa(), '/PPC.+OS X ([0-9\\._]+)/', 'Mac OS X')) {
         $device->getOs()->version = str_replace('_', '.', $device->getOs()->version);
         return;
     }
     if ($device->getOs()->setRegex($device->getDeviceUa(), '/PPC.+OS X/', 'Mac OS X')) {
         return;
     }
     if ($device->getOs()->setRegex($device->getDeviceUa(), '/Intel Mac OS X ([0-9\\._]+)/', 'Mac OS X', 1)) {
         $device->getOs()->version = str_replace('_', '.', $device->getOs()->version);
         return;
     }
     if ($device->getOs()->setContains($device->getDeviceUa(), 'Mac_PowerPC', 'Mac OS X')) {
         return;
     }
     if ($device->getOs()->setContains($device->getDeviceUa(), 'CrOS', 'Chrome OS')) {
         return;
     }
     if ($device->getOs()->name) {
         return;
     }
     if (strpos($device->getDeviceUa(), 'FreeBSD') !== false) {
         $device->getOs()->name = 'FreeBSD';
         return;
     }
     if (strpos($device->getDeviceUa(), 'NetBSD') !== false) {
         $device->getOs()->name = 'NetBSD';
         return;
     }
     // Last ditch efforts
     if (strpos($device->getDeviceUa(), 'Linux') !== false || strpos($device->getDeviceUa(), 'X11') !== false) {
         $device->getOs()->name = 'Linux';
         return;
     }
 }