示例#1
0
 /**
  * Return a device for the given http request(user-agent..)
  *
  * @param array $httpRequest HTTP Request array (normally $_SERVER)
  * @param bool $override_sideloaded_browser_ua
  * @return WURFL_CustomDevice device
  * @throws Exception if $httpRequest is not set
  */
 public function getDeviceForHttpRequest($httpRequest, $override_sideloaded_browser_ua = true)
 {
     if (!isset($httpRequest)) {
         throw new Exception("The {$httpRequest} parameter must be set.");
     }
     $request = $this->_requestFactory->createRequest($httpRequest, $override_sideloaded_browser_ua);
     return $this->getDeviceForRequest($request);
 }
示例#2
0
 /**
  * Return a device for the given http request(user-agent..)
  *
  * @param array $httpRequest HTTP Request array (normally $_SERVER)
  * @return WURFL_CustomDevice device
  * @throws Exception if $httpRequest is not set
  */
 public function getDeviceForHttpRequest($httpRequest)
 {
     if (!isset($httpRequest)) {
         throw new Exception("The {$httpRequest} parameter must be set.");
     }
     $request = $this->_requestFactory->createRequest($httpRequest);
     return $this->getDeviceForRequest($request);
 }
示例#3
0
 public function testShouldNormalizeHeaders()
 {
     $headers = array("REQUEST_START_TIME" => 1429192614, "REQUEST_TIME" => 1429192614, "REQUEST_TIME_FLOAT" => 1429192614.5303, "HTTP_ACCEPT_LANGUAGE" => "en-us", "HTTP_ACCEPT" => "*/*", "HTTP_X_FORWARDED_PROTO" => "http", "HTTP_CONNECTION" => "keep-alive", "HTTP_REFERER" => "http://example.com", "HTTP_X_FORWARDED_PORT" => "80", "HTTP_ACCEPT_ENCODING" => "gzip, deflate", "HTTP_X_FORWARDED_FOR" => "127.0.1.1", "HTTP_CONTENT_TYPE" => "", "HTTP_CONTENT_LENGTH" => "", "HTTP_USER_AGENT" => "Mozilla/5.0 (iPad; CPU OS 7_1_1 like Mac OS X)", "HTTP_HOST" => "example.com", "GATEWAY_INTERFACE" => "CGI/1.1", "SERVER_ADDR" => "10.0.0.1", "SERVER_NAME" => "", "SERVER_PORT" => "80", "SERVER_SOFTWARE" => "nginx/1.4.6", "SERVER_PROTOCOL" => "HTTP/1.1", "SERVER_ADMIN" => "", "SERVER_SIGNATURE" => "", "REDIRECT_STATUS" => "200", "CONTENT_LENGTH" => "", "REQUEST_METHOD" => "GET", "DOCUMENT_URI" => "/example.php", "SCRIPT_NAME" => "/example.php", "REMOTE_PORT" => 11111, "REQUEST_URI" => "/example.php", "REMOTE_ADDR" => "10.0.0.1", "CONTENT_TYPE" => "", "DOCUMENT_ROOT" => "/var/www/example", "QUERY_STRING" => "", "SCRIPT_FILENAME" => "/var/www/example/web/example.php", "SCRIPT_URL" => "/example.php", "SCRIPT_URI" => "http://example.com/example.php", "PHP_SELF" => "/example.php", "PATH_TRANSLATED" => "/var/www/example/web/example.php", "HTTPS" => "", "argv" => [], "argc" => 1, "THREAD_TYPE" => "Web Request");
     $ua = "Mozilla/5.0 (iPad; CPU OS 7_1_1 like Mac OS X)";
     $request_factory = new WURFL_Request_GenericRequestFactory();
     $request = $request_factory->createRequest($headers);
     $this->assertEquals($ua, $request->userAgent);
 }
示例#4
0
 public function run(WURFL_WURFLManager $wurflManager)
 {
     $this->failure_count = 0;
     // Verify API Version
     if ($this->min_version && version_compare(WURFL_Constants::API_VERSION, $this->min_version, '<')) {
         throw new CentralTest_InvalidIntrospectorVersionException("Test requires WURFL PHP API >= {$this->min_version} (current " . WURFL_Constants::API_VERSION . ")");
     }
     // Verify correct mode
     if ($this->mode != self::MODE_ALL) {
         $required_mode = $this->mode == self::MODE_HIGH_PERFORMANCE ? WURFL_Configuration_Config::MATCH_MODE_PERFORMANCE : WURFL_Configuration_Config::MATCH_MODE_ACCURACY;
         WURFL_Configuration_ConfigHolder::getWURFLConfig()->matchMode($required_mode);
     }
     $request_factory = new WURFL_Request_GenericRequestFactory();
     $request = $request_factory->createRequest($this->http_headers, $this->ua_override);
     $device = $wurflManager->getDeviceForRequest($request);
     foreach ($this->assertions as $assertion) {
         /* @var $assertion CentralTestAssertion */
         $assertion->wurflManager = $wurflManager;
         if (!$assertion->assert($device)) {
             $this->failure_count++;
         }
     }
     return $this->failure_count === 0;
 }
示例#5
0
 protected function actionRequest()
 {
     $request_factory = new WURFL_Request_GenericRequestFactory();
     $request = $request_factory->createRequest($this->http_headers);
     $device = $this->wurfl->getDeviceForRequest($request);
     $this->response['id'] = $device->id;
     $this->response['user_agent'] = $request->userAgent;
     if (!empty($this->capabilities)) {
         $this->response['capabilities'] = array();
         foreach ($this->capabilities as $capability) {
             if (array_key_exists($capability, WURFL_VirtualCapabilityProvider::$virtual_capabilities)) {
                 $value = $device->getVirtualCapability($capability);
             } else {
                 $value = $device->getCapability($capability);
             }
             $this->response['capabilities'][$capability] = $value;
         }
     }
     if ($this->matcher_history) {
         $this->response['matcher_history'] = $request->matchInfo->matcher_history;
     }
     $this->response['success'] = true;
     $this->sendResponse();
 }
示例#6
0
 protected function actionRequest()
 {
     $request_factory = new WURFL_Request_GenericRequestFactory();
     $request = $request_factory->createRequest($this->http_headers);
     $device = $this->wurfl->getDeviceForRequest($request);
     $this->response['id'] = $device->id;
     $this->response['user_agent'] = $request->userAgent;
     if (!empty($this->capabilities)) {
         $this->response['capabilities'] = array();
         foreach ($this->capabilities as $capability) {
             $this->response['capabilities'][$capability] = $device->getCapability($capability);
         }
     }
     if ($this->matcher_history) {
         $this->response['matcher_history'] = $device->getCapability('matcher_history');
     }
     $this->response['success'] = true;
     $this->sendResponse();
 }