/** * 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); }
/** * @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; }
/** * 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); }