key_int = null; $this->key_string = null; if ($ignoreInKey) { $this->infos_ignored[$key] = $value; } else { $this->infos[$key] = $value; } } /** * @param $key string Key used with @add function * @param null $default * @return mixed|null */ public function get($key, $default = null) { if ($key && array_key_exists($key, $this->infos)) { return $this->infos[$key]; } elseif ($key && array_key_exists($key, $this->infos_ignored)) { return $this->infos_ignored[$key]; } return $default; } /** * @param $key string Key used with @add function */ public function remove($key) { if ($key && array_key_exists($key, $this->infos)) { unset($this->infos[$key]); $this->key_int = null; $this->key_string = null; } } /** * @return $this */ public function compute() { if ($this->key_int === null || $this->key_string == null) { // Make sure information are in the same order ksort($this->infos); // Create a unique string $str = json_encode($this->infos, JSON_INVALID_UTF8_SUBSTITUTE); // Compute CRC32 to be used by caching systems (as string) $this->key_string = hash("crc32b", $str); // Compute CRC32 to be stored in database (as integer) $this->key_int = (int) hexdec($this->key_string); } return $this; } public function toInt() { $this->compute(); return $this->key_int; } public function toString() { $this->compute(); return $this->key_string; } /** * @param $keyInt double * @return string */ public static function intToString($keyInt) { return sprintf("%08x", (double) $keyInt); } public function getInfos() { return $this->infos; } } }