You are here

class OatmealCookie in Bakery Single Sign-On System 8.2

Hierarchy

Expanded class hierarchy of OatmealCookie

2 files declare their use of OatmealCookie
MainDeprecatedController.php in src/Controller/MainDeprecatedController.php
OatmealCookieTest.php in tests/src/Unit/Cookies/OatmealCookieTest.php

File

src/Cookies/OatmealCookie.php, line 5

Namespace

Drupal\bakery\Cookies
View source
class OatmealCookie implements CookieInterface {
  use BrowserCookieTrait;
  protected $calories = 320;
  protected $name;
  protected $data;

  /**
   * @var int|null
   */
  protected $isMain;
  public final function __construct($name, $data, $main = NULL) {
    $this->name = $name;
    $this->data = $data;
    $this->isMain = $main;
  }

  /**
   * {@inheritDoc}
   */
  public static function fromData(array $data) {
    return new static($data['name'], $data['data'], $data['master'] ?? NULL);
  }

  /**
   * {@inheritDoc}
   */
  public function toData() : array {
    $main = $this->isMain ?? $this
      ->getIsMain();
    $tmp = [
      'name' => $this->name,
      'data' => $this->data,
      'master' => (int) $main,
      'calories' => $this->calories,
    ];
    if (!$main) {
      global $base_url;
      $tmp['slave'] = $base_url . '/';
    }
    return $tmp;
  }

  /**
   * {@inheritDoc}
   */
  public static function getName() : string {
    return static::cookieName('OATMEAL');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BrowserCookieTrait::cookieName protected static function Wrap cookie name for browser.
BrowserCookieTrait::getBakeryKitchen private static function Get a kitchen.
BrowserCookieTrait::getBakeryService private static function Get a bakery service.
BrowserCookieTrait::getIsMain protected function Helper to determine if the current site is the "main" site.
OatmealCookie::$calories protected property
OatmealCookie::$data protected property
OatmealCookie::$isMain protected property
OatmealCookie::$name protected property
OatmealCookie::fromData public static function Create from data stored in a cookie. Overrides CookieInterface::fromData
OatmealCookie::getName public static function Get the cookie name/type. Overrides CookieInterface::getName
OatmealCookie::toData public function Convert the data into an array to be stored into a cookie. Overrides CookieInterface::toData
OatmealCookie::__construct final public function