/** * Returns an associative array of capabilityName => capabilityValue for the given $deviceID * * @param string $deviceID * * @return array associative array of capabilityName, capabilityValue */ public function getAllCapabilitiesForDevice($deviceID) { $devices = array_reverse($this->getDeviceHierarchy($deviceID)); $capabilities = array(); foreach ($devices as $device) { /** @var $device \Wurfl\Device\ModelDeviceInterface */ if (is_array($device->capabilities)) { $capabilities = array_merge($capabilities, $device->capabilities); } } $capabilities = array_diff_key($capabilities, array_flip(VirtualCapabilityProvider::getControlCapabilities())); return $capabilities; }
/** * Builds DeviceRepositoryInterface in PersistenceProvider from $wurflFile and $wurflPatches using $capabilityFilter * * @param string $wurflFile Filename of wurfl.xml or other complete WURFL file * @param array $wurflPatches Array of WURFL patch files * @param array $capabilityFilter Array of capabilities to be included in the DeviceRepositoryInterface * * @throws \Exception * @throws \Wurfl\Device\Exception * @throws \Wurfl\Exception\ConsistencyException * @return CustomDeviceRepository */ public function build($wurflFile, array $wurflPatches = array(), array $capabilityFilter = array()) { if (!$this->isRepositoryBuilt()) { if (!empty($capabilityFilter)) { $capabilityFilter = array_unique(array_merge($capabilityFilter, VirtualCapabilityProvider::getControlCapabilities())); } // If acquireLock() is false, the WURFL is being reloaded in another thread if ($this->acquireLock()) { try { $infoIterator = new VersionIterator($wurflFile); } catch (\InvalidArgumentException $e) { $this->releaseLock(); $this->logger->error($e); throw $e; } try { $deviceIterator = new DeviceIterator($wurflFile, $capabilityFilter); } catch (\InvalidArgumentException $e) { $this->releaseLock(); $this->logger->error($e); throw $e; } $patchIterators = $this->toPatchIterators($wurflPatches, $capabilityFilter); try { $this->buildRepository($infoIterator, $deviceIterator, $patchIterators); } catch (Exception $e) { $this->releaseLock(); $this->logger->error($e); throw $e; } try { $this->verifyRepository(); } catch (ConsistencyException $e) { $this->releaseLock(); $this->logger->error($e); throw $e; } $this->setRepositoryBuilt(); $this->releaseLock(); } } return new CustomDeviceRepository($this->persistenceProvider, $this->deviceClassificationNames()); }
/** * Returns capabilities and their values for the current device * * @return array Device capabilities array * * @see \Wurfl\Device\ModelDeviceInterface::getCapabilities() */ public function getAllCapabilities() { $capabilities = array(); foreach (array_reverse($this->modelDevices) as $modelDevice) { /* @var Device\ModelDeviceInterface $modelDevice */ $capabilities = array_merge($capabilities, $modelDevice->getCapabilities()); } $capabilities = array_diff_key($capabilities, array_flip(VirtualCapabilityProvider::getControlCapabilities())); return $capabilities; }