You are here

OatmealCookie.php in Bakery Single Sign-On System 8.2

File

src/Cookies/OatmealCookie.php
View source
<?php

namespace Drupal\bakery\Cookies;

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');
  }

}

Classes

Namesort descending Description
OatmealCookie