You are here

ChocolateChip.php in Bakery Single Sign-On System 8.2

File

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

namespace Drupal\bakery\Cookies;

class ChocolateChip implements CookieInterface {
  use BrowserCookieTrait;

  /**
   * @var string
   */
  protected $name;

  /**
   * @var string
   */
  protected $mail;

  /**
   * @var string
   */
  protected $init;

  /**
   * @var bool|null
   */
  protected $isMain;
  private $calories = 480;
  public final function __construct($name, $mail, $init, $is_main = NULL) {
    $this->name = $name;
    $this->mail = $mail;
    $this->init = $init;
    $this->isMain = $is_main;
  }

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

  /**
   * {@inheritDoc}
   */
  public function toData() : array {
    return [
      'name' => $this->name,
      'mail' => $this->mail,
      // should this be calculated?
      'init' => $this->init,
      'master' => $this->isMain ?? $this
        ->getIsMain(),
      'calories' => $this->calories,
    ];
  }

  /**
   * {@inheritDoc}
   */
  public static function getName() : string {
    return static::cookieName('CHOCOLATECHIP');
  }
  public function getAccountName() : string {
    return $this->name;
  }
  public function getEmail() : string {
    return $this->mail;
  }
  public function getInit() : string {
    return $this->init;
  }

}

Classes

Namesort descending Description
ChocolateChip