/**
  * Builds DeviceRepository 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 DeviceRepository
  * @return WURFL_CustomDeviceRepository
  */
 public function build($wurflFile, $wurflPatches = array(), $capabilityFilter = array())
 {
     // TODO: Create a better locking solution
     if (!$this->isRepositoryBuilt()) {
         // Determine Lockfile location
         if (strpos(PHP_OS, 'SunOS') === false) {
             $this->lockFile = dirname(__FILE__) . "/DeviceRepositoryBuilder.php";
         } else {
             // Solaris can't handle exclusive file locks on files unless they are opened for RW
             $this->lockStyle = 'w+';
             $this->lockFile = WURFL_FileUtils::getTempDir() . '/wurfl.lock';
         }
         // Update Data
         set_time_limit(300);
         $fp = fopen($this->lockFile, $this->lockStyle);
         if (flock($fp, LOCK_EX | LOCK_NB)) {
             $infoIterator = new WURFL_Xml_VersionIterator($wurflFile);
             $deviceIterator = new WURFL_Xml_DeviceIterator($wurflFile, $capabilityFilter);
             $patchIterators = $this->toPatchIterators($wurflPatches, $capabilityFilter);
             $this->buildRepository($infoIterator, $deviceIterator, $patchIterators);
             $this->setRepositoryBuilt();
             flock($fp, LOCK_UN);
         }
     }
     $deviceClassificationNames = $this->deviceClassificationNames();
     return new WURFL_CustomDeviceRepository($this->persistenceProvider, $deviceClassificationNames);
 }
Пример #2
0
 /**
  * @param WURFL_Storage_Base $persistenceProvider
  * @param WURFL_UserAgentHandlerChain $userAgentHandlerChain
  * @param WURFL_Xml_DevicePatcher $devicePatcher
  */
 public function __construct($persistenceProvider, $userAgentHandlerChain, $devicePatcher)
 {
     $this->persistenceProvider = $persistenceProvider;
     $this->userAgentHandlerChain = $userAgentHandlerChain;
     $this->devicePatcher = $devicePatcher;
     $this->lockFile = WURFL_FileUtils::getTempDir() . '/wurfl_builder.lock';
 }
Пример #3
0
 /**
  * Loads given XML $inputFile
  * @param string $inputFile
  */
 public function __construct($inputFile)
 {
     $inputFile = WURFL_FileUtils::cleanFilename($inputFile);
     if (!file_exists($inputFile)) {
         throw new InvalidArgumentException("cannot locate [{$inputFile}] file!");
     }
     $this->inputFile = WURFL_Xml_Utils::getXMLFile($inputFile);
 }
Пример #4
0
 public function testShouldTryToCreateTheStorage()
 {
     $cachepath = $this->realpath(self::STORAGE_DIR . "/cache");
     $params = array("dir" => $cachepath);
     new WURFL_Storage_File($params);
     $this->assertStorageDirectoryIsCreated($cachepath);
     WURFL_FileUtils::rmdir($cachepath);
 }
Пример #5
0
 /**
  * Returns a XML Resource filename for the uncompressed contents of the provided zipped $filename
  * @param string $filename of zipped XML data
  * @throws WURFL_WURFLException ZipArchive extension is not loaded or the ZIP file is corrupt
  * @return string Full filename and path of extracted XML file
  */
 private static function getZippedFile($filename)
 {
     if (!self::zipModuleLoaded()) {
         throw new WURFL_WURFLException("The ZipArchive extension is not loaded. Load the extension or use the flat wurfl.xml file");
     }
     $tmpDir = WURFL_FileUtils::getTempDir();
     $zip = new ZipArchive();
     if ($zip->open($filename) !== true) {
         throw new WURFL_WURFLException("The Zip file <{$filename}> could not be opened");
     }
     $zippedFile = $zip->statIndex(0);
     $wurflFile = $zippedFile['name'];
     //$wurflFile = md5(uniqid(rand(), true));
     //$zip->extractTo($tmpDir, $wurflFile);
     $zip->extractTo($tmpDir);
     $zip->close();
     return WURFL_FileUtils::cleanFilename($tmpDir . DIRECTORY_SEPARATOR . $wurflFile);
 }
Пример #6
0
 public function tearDown()
 {
     WURFL_FileUtils::rmdir($this->persistenceDir);
 }
Пример #7
0
 private function keyPath($key)
 {
     return WURFL_FileUtils::join(array($this->root, $this->spread(md5($key))));
 }
 /**
  * Clears the persistence provider by removing the directory 
  *
  */
 public function clear()
 {
     WURFL_FileUtils::rmdir($this->_persistenceDir);
 }
Пример #9
0
 public function tearDown()
 {
     WURFL_FileUtils::rmdir($this->cacheDir());
 }