You are here

AbstractBackend.php in Redis 7.3

Same filename and directory in other branches
  1. 7.2 lib/Redis/AbstractBackend.php

File

lib/Redis/AbstractBackend.php
View source
<?php

abstract class Redis_AbstractBackend implements Redis_BackendInterface {

  /**
   * Key components name separator
   */
  const KEY_SEPARATOR = ':';

  /**
   * @var string
   */
  private $prefix;

  /**
   * @var string
   */
  private $namespace;

  /**
   * @var mixed
   */
  private $client;

  /**
   * Default constructor
   *
   * @param mixed $client
   *   Redis client
   * @param string $namespace
   *   Component namespace
   * @param string $prefix
   *   Component prefix
   */
  public function __construct($client, $namespace = null, $prefix = null) {
    $this->client = $client;
    $this->prefix = $prefix;
    if (null !== $namespace) {
      $this->namespace = $namespace;
    }
  }
  public final function setClient($client) {
    $this->client = $client;
  }
  public final function getClient() {
    return $this->client;
  }
  public final function setPrefix($prefix) {
    $this->prefix = $prefix;
  }
  public final function getPrefix() {
    return $this->prefix;
  }
  public final function setNamespace($namespace) {
    $this->namespace = $namespace;
  }
  public final function getNamespace() {
    return $this->namespace;
  }

  /**
   * Get prefixed key
   *
   * @param string|string[] $parts
   *   Arbitrary number of strings to compose the key
   *
   * @return string
   */
  public function getKey($parts = array()) {
    $key = array();
    if (null !== $this->prefix) {
      $key[] = $this->prefix;
    }
    if (null !== $this->namespace) {
      $key[] = $this->namespace;
    }
    if ($parts) {
      if (is_array($parts)) {
        foreach ($parts as $part) {
          if ($part) {
            $key[] = $part;
          }
        }
      }
      else {
        $key[] = $parts;
      }
    }
    return implode(self::KEY_SEPARATOR, array_filter($key));
  }

}

Classes