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); }
/** * @param array $modelDevices Array of WURFL_Xml_ModelDevice objects * @param WURFL_Request_GenericRequest $request * @throws InvalidArgumentException if $modelDevices is not an array of at least one WURFL_Xml_ModelDevice */ public function __construct(array $modelDevices, $request = null) { if (!is_array($modelDevices) || count($modelDevices) < 1) { throw new InvalidArgumentException("modelDevices must be an array of at least one ModelDevice."); } $this->modelDevices = $modelDevices; if ($request === null) { // This might happen if a device is looked up by its ID directly, without providing a user agent $requestFactory = new WURFL_Request_GenericRequestFactory(); $request = $requestFactory->createRequestForUserAgent($this->userAgent); } $this->request = $request; }
/** * Returns a device for the given user-agent * * @param string $userAgent * @return WURFL_CustomDevice device * @throws Exception if $userAgent is not set */ public function getDeviceForUserAgent($userAgent) { if (!isset($userAgent)) { $userAgent = ''; } $request = $this->_requestFactory->createRequestForUserAgent($userAgent); return $this->getDeviceForRequest($request); }
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; }
/** * Wraps the model device with WURFL_Xml_ModelDevice. This function takes the * Device ID and returns the WURFL_CustomDevice with all capabilities. * * @param string $deviceID * @param WURFL_Request_GenericRequest|null $request * @return WURFL_CustomDevice */ private function getWrappedDevice($deviceID, $request = null) { $modelDevices = $this->_cacheProvider->load('DEVS_' . $deviceID); if (empty($modelDevices)) { $modelDevices = $this->_deviceRepository->getDeviceHierarchy($deviceID); } $this->_cacheProvider->save('DEVS_' . $deviceID, $modelDevices); if ($request === null) { // If a request was not provided, we generate one from the WURFL entry itself // to help resolve the virtual capabilities $requestFactory = new WURFL_Request_GenericRequestFactory(); $request = $requestFactory->createRequestForUserAgent($modelDevices[0]->userAgent); $genericNormalizer = WURFL_UserAgentHandlerChainFactory::createGenericNormalizers(); $request->userAgentNormalized = $genericNormalizer->normalize($request->userAgent); } // The CustomDevice is not cached since virtual capabilities must be recalculated // for every different request. return new WURFL_CustomDevice($modelDevices, $request); }
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(); }
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(); }