You are here

abstract class State in Advanced CSS/JS Aggregation 8.2

Provides AdvAgg State interfaces with a few extra commands.

Hierarchy

Expanded class hierarchy of State

File

src/State/State.php, line 10

Namespace

Drupal\advagg\State
View source
abstract class State extends CoreState {

  /**
   * If the array isn't keyed by filepath the column the filepath is stored in.
   */
  protected $pathColumn = NULL;

  /**
   * Gets all stored information from this Key Value Store.
   *
   * @return array
   *   An array of all key value pairs.
   */
  public function getAll() {
    $values = $this->keyValueStore
      ->getAll();
    return $values;
  }

  /**
   * Delete all stored information from this Key Value Store.
   */
  public function deleteAll() {
    $this->keyValueStore
      ->deleteAll();
  }

  /**
   * Get a semi-random (randomness not guaranteed) key.
   */
  public function getRandomKey() {
    $key = array_rand($this
      ->getAll());
    return $key;
  }

  /**
   * Get a semi-random (randomness not guaranteed) value.
   */
  public function getRandom() {
    return $this
      ->get($this
      ->getRandomKey());
  }

  /**
   * Scan the filesystem for missing files and removee from database.
   */
  public function clearMissingFiles() {
    $removed = [];
    $values = $this
      ->getAll();
    if (empty($values)) {
      return $removed;
    }
    if ($this->pathColumn) {
      $values = array_column($values, NULL, $this->pathColumn);
    }
    foreach ($values as $path => $details) {
      if (!file_exists($path)) {
        $removed[$path] = $values[$path];
        $this
          ->delete($path);
      }
    }
    return $removed;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
State::$cache protected property Static state cache.
State::$keyValueStore protected property The key value store to use.
State::$pathColumn protected property If the array isn't keyed by filepath the column the filepath is stored in.
State::clearMissingFiles public function Scan the filesystem for missing files and removee from database.
State::delete public function Deletes an item. Overrides StateInterface::delete
State::deleteAll public function Delete all stored information from this Key Value Store.
State::deleteMultiple public function Deletes multiple items. Overrides StateInterface::deleteMultiple
State::get public function Returns the stored value for a given key. Overrides StateInterface::get
State::getAll public function Gets all stored information from this Key Value Store.
State::getMultiple public function Returns the stored key/value pairs for a given set of keys. Overrides StateInterface::getMultiple
State::getRandom public function Get a semi-random (randomness not guaranteed) value.
State::getRandomKey public function Get a semi-random (randomness not guaranteed) key.
State::resetCache public function Resets the static cache. Overrides StateInterface::resetCache
State::set public function Saves a value for a given key. Overrides StateInterface::set
State::setMultiple public function Saves key/value pairs. Overrides StateInterface::setMultiple
State::__construct public function Constructs a State object.