You are here

abstract class FlagCookieStorage in Flag 7.3

Same name and namespace in other branches
  1. 6.2 flag.inc \FlagCookieStorage
  2. 7.2 flag.inc \FlagCookieStorage

Utility class to handle cookies.

Cookies are used to record flaggings for anonymous users on cached pages.

This class contains only two instance methods. Usage example:

$storage = FlagCookieStorage::factory($flag);
$storage
  ->flag(145);
$storage
  ->unflag(17);

You may delete all the cookies with <code>FlagCookieStorage::drop()</code>.

Hierarchy

Expanded class hierarchy of FlagCookieStorage

File

includes/flag.cookie_storage.inc, line 22
Contains the FlagCookieStorage class.

View source
abstract class FlagCookieStorage {

  /**
   * Returns the actual storage object compatible with the flag.
   */
  static function factory($flag) {
    if ($flag->global) {
      return new FlagGlobalCookieStorage($flag);
    }
    else {
      return new FlagNonGlobalCookieStorage($flag);
    }
  }
  function __construct($flag) {
    $this->flag = $flag;
  }

  /**
   * "Flags" an item.
   *
   * It just records this fact in a cookie.
   */
  abstract function flag($entity_id);

  /**
   * "Unflags" an item.
   *
   * It just records this fact in a cookie.
   */
  abstract function unflag($entity_id);

  /**
   * Deletes all the cookies.
   *
   * (Etymology: "drop" as in "drop database".)
   */
  static function drop() {
    FlagGlobalCookieStorage::drop();
    FlagNonGlobalCookieStorage::drop();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FlagCookieStorage::drop static function Deletes all the cookies. 2
FlagCookieStorage::factory static function Returns the actual storage object compatible with the flag.
FlagCookieStorage::flag abstract function "Flags" an item. 2
FlagCookieStorage::unflag abstract function "Unflags" an item. 2
FlagCookieStorage::__construct function 1