You are here

abstract class Redis_Path_AbstractHashLookup in Redis 7.3

Same name and namespace in other branches
  1. 7.2 lib/Redis/Path/AbstractHashLookup.php \Redis_Path_AbstractHashLookup

Common implementation for Redis-based implementations

Hierarchy

Expanded class hierarchy of Redis_Path_AbstractHashLookup

File

lib/Redis/Path/AbstractHashLookup.php, line 6

View source
abstract class Redis_Path_AbstractHashLookup extends Redis_AbstractBackend implements Redis_Path_HashLookupInterface {

  /**
   * @todo document me
   *
   * @param string $key
   * @param string $hkey
   * @param string $hvalue
   */
  protected abstract function saveInHash($key, $hkey, $hvalue);

  /**
   * @todo document me
   *
   * @param string $key
   * @param string $hkey
   * @param string $hvalue
   */
  protected abstract function deleteInHash($key, $hkey, $hvalue);

  /**
   * @todo document me
   *
   * @param string $keyPrefix
   * @param string $hkey
   * @param string $language
   */
  protected abstract function lookupInHash($keyPrefix, $hkey, $language = null);

  /**
   * Normalize value to avoid duplicate or false negatives
   *
   * @param string $value
   *
   * @return string
   */
  private function normalize($value) {
    if (null !== $value) {
      return strtolower(trim($value));
    }
  }

  /**
   * {@inheritdoc}
   */
  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);
    }
  }

  /**
   * {@inheritdoc}
   */
  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);
  }

  /**
   * {@inheritdoc}
   */
  public function lookupAlias($source, $language = null) {
    $source = $this
      ->normalize($source);
    return $this
      ->lookupInHash(self::KEY_ALIAS, $source, $language);
  }

  /**
   * {@inheritdoc}
   */
  public function lookupSource($alias, $language = null) {
    $alias = $this
      ->normalize($alias);
    return $this
      ->lookupInHash(self::KEY_SOURCE, $alias, $language);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Redis_AbstractBackend::$client private property
Redis_AbstractBackend::$namespace private property
Redis_AbstractBackend::$prefix private property
Redis_AbstractBackend::getClient final public function Get client Overrides Redis_BackendInterface::getClient
Redis_AbstractBackend::getKey public function Get prefixed key Overrides Redis_BackendInterface::getKey 1
Redis_AbstractBackend::getNamespace final public function Get namespace Overrides Redis_BackendInterface::getNamespace
Redis_AbstractBackend::getPrefix final public function Get prefix Overrides Redis_BackendInterface::getPrefix
Redis_AbstractBackend::KEY_SEPARATOR constant Key components name separator
Redis_AbstractBackend::setClient final public function Set client Overrides Redis_BackendInterface::setClient
Redis_AbstractBackend::setNamespace final public function Set namespace Overrides Redis_BackendInterface::setNamespace
Redis_AbstractBackend::setPrefix final public function Set prefix Overrides Redis_BackendInterface::setPrefix
Redis_AbstractBackend::__construct public function Default constructor 1
Redis_Path_AbstractHashLookup::deleteAlias public function Alias is being deleted for the given source Overrides Redis_Path_HashLookupInterface::deleteAlias
Redis_Path_AbstractHashLookup::deleteInHash abstract protected function @todo document me 2
Redis_Path_AbstractHashLookup::lookupAlias public function Lookup any alias for the given source Overrides Redis_Path_HashLookupInterface::lookupAlias
Redis_Path_AbstractHashLookup::lookupInHash abstract protected function @todo document me 2
Redis_Path_AbstractHashLookup::lookupSource public function Lookup any source for the given alias Overrides Redis_Path_HashLookupInterface::lookupSource
Redis_Path_AbstractHashLookup::normalize private function Normalize value to avoid duplicate or false negatives
Redis_Path_AbstractHashLookup::saveAlias public function Alias is being inserted with the given source Overrides Redis_Path_HashLookupInterface::saveAlias
Redis_Path_AbstractHashLookup::saveInHash abstract protected function @todo document me 2
Redis_Path_HashLookupInterface::deleteLanguage public function A language is being deleted 3
Redis_Path_HashLookupInterface::KEY_ALIAS constant Alias HASH key prefix
Redis_Path_HashLookupInterface::KEY_SOURCE constant Source HASH key prefix
Redis_Path_HashLookupInterface::VALUE_NULL constant Null value (not existing yet cached value)
Redis_Path_HashLookupInterface::VALUE_SEPARATOR constant Values separator for hash values