View source
<?php
abstract class Redis_Path_AbstractHashLookup extends Redis_AbstractBackend implements Redis_Path_HashLookupInterface {
protected abstract function saveInHash($key, $hkey, $hvalue);
protected abstract function deleteInHash($key, $hkey, $hvalue);
protected abstract function lookupInHash($keyPrefix, $hkey, $language = null);
private function normalize($value) {
if (null !== $value) {
return strtolower(trim($value));
}
}
public function saveAlias($source, $alias, $language = null) {
$alias = $this
->normalize($alias);
$source = $this
->normalize($source);
if (null === $language) {
$language = LANGUAGE_NONE;
}
if (!empty($source)) {
$this
->saveInHash($this
->getKey(array(
self::KEY_ALIAS,
$language,
)), $source, $alias);
}
if (!empty($alias)) {
$this
->saveInHash($this
->getKey(array(
self::KEY_SOURCE,
$language,
)), $alias, $source);
}
}
public function deleteAlias($source, $alias, $language = null) {
$alias = $this
->normalize($alias);
$source = $this
->normalize($source);
if (null === $language) {
$language = LANGUAGE_NONE;
}
$this
->deleteInHash($this
->getKey(array(
self::KEY_ALIAS,
$language,
)), $source, $alias);
$this
->deleteInHash($this
->getKey(array(
self::KEY_SOURCE,
$language,
)), $alias, $source);
}
public function lookupAlias($source, $language = null) {
$source = $this
->normalize($source);
return $this
->lookupInHash(self::KEY_ALIAS, $source, $language);
}
public function lookupSource($alias, $language = null) {
$alias = $this
->normalize($alias);
return $this
->lookupInHash(self::KEY_SOURCE, $alias, $language);
}
}