getIniPartCacheSubKey() public static method

Gets the sub key for the ini parts cache file, generated from the given string
public static getIniPartCacheSubKey ( string $string ) : string
$string string
return string
示例#1
0
 /**
  * Gets the relevant part (array of settings) of the ini file for a given pattern.
  *
  * @param  string $pattern
  * @return array
  */
 private function getIniPart($pattern)
 {
     $pattern = strtolower($pattern);
     $patternhash = Pattern::getHashForParts($pattern);
     $subkey = SubKey::getIniPartCacheSubKey($patternhash);
     if (!$this->cache->hasItem('browscap.iniparts.' . $subkey, true)) {
         $this->logger->debug('cache key "browscap.iniparts.' . $subkey . '" not found');
         return [];
     }
     $success = null;
     $file = $this->cache->getItem('browscap.iniparts.' . $subkey, true, $success);
     if (!$success) {
         $this->logger->debug('cache key "browscap.iniparts.' . $subkey . '" not found');
         return [];
     }
     if (!is_array($file) || !count($file)) {
         $this->logger->debug('cache key "browscap.iniparts.' . $subkey . '" was empty');
         return [];
     }
     $propertyFormatter = new PropertyFormatter(new PropertyHolder());
     $return = [];
     foreach ($file as $buffer) {
         list($tmpBuffer, $patterns) = explode("\t", $buffer, 2);
         if ($tmpBuffer === $patternhash) {
             $return = json_decode($patterns, true);
             foreach (array_keys($return) as $property) {
                 $return[$property] = $propertyFormatter->formatPropertyValue($return[$property], $property);
             }
             break;
         }
     }
     return $return;
 }
示例#2
0
 /**
  * Creates new ini part cache files
  *
  * @param string $content
  *
  * @return \Generator
  */
 public function createIniParts($content)
 {
     // get all patterns from the ini file in the correct order,
     // so that we can calculate with index number of the resulting array,
     // which part to use when the ini file is splitted into its sections.
     preg_match_all('/(?<=\\[)(?:[^\\r\\n]+)(?=\\])/m', $content, $patternpositions);
     $patternpositions = $patternpositions[0];
     // split the ini file into sections and save the data in one line with a hash of the beloging
     // pattern (filtered in the previous step)
     $iniParts = preg_split('/\\[[^\\r\\n]+\\]/', $content);
     $contents = [];
     $propertyFormatter = new PropertyFormatter(new PropertyHolder());
     foreach ($patternpositions as $position => $pattern) {
         $pattern = strtolower($pattern);
         $patternhash = Pattern::getHashForParts($pattern);
         $subkey = SubKey::getIniPartCacheSubKey($patternhash);
         if (!isset($contents[$subkey])) {
             $contents[$subkey] = [];
         }
         $browserProperties = parse_ini_string($iniParts[$position + 1], INI_SCANNER_RAW);
         foreach (array_keys($browserProperties) as $property) {
             $browserProperties[$property] = $propertyFormatter->formatPropertyValue($browserProperties[$property], $property);
         }
         // the position has to be moved by one, because the header of the ini file
         // is also returned as a part
         $contents[$subkey][] = $patternhash . "\t" . json_encode($browserProperties, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP);
     }
     unset($patternpositions);
     unset($iniParts);
     $subkeys = array_flip(SubKey::getAllIniPartCacheSubKeys());
     foreach ($contents as $subkey => $content) {
         $subkey = (string) $subkey;
         (yield [$subkey => $content]);
         unset($subkeys[$subkey]);
     }
     foreach (array_keys($subkeys) as $subkey) {
         $subkey = (string) $subkey;
         (yield [$subkey => []]);
     }
 }