BrowscapPHP\Parser\Helper\Pattern::getHashForParts PHP Méthode

getHashForParts() public static méthode

returns a hash for one pattern
public static getHashForParts ( $pattern ) : string
$pattern
Résultat string
    public static function getHashForParts($pattern)
    {
        return md5($pattern);
    }

Usage Example

Exemple #1
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 => []]);
     }
 }
All Usage Examples Of BrowscapPHP\Parser\Helper\Pattern::getHashForParts