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;
protected $isMain;
public final function __construct($name, $data, $main = NULL) {
$this->name = $name;
$this->data = $data;
$this->isMain = $main;
}
public static function fromData(array $data) {
return new static($data['name'], $data['data'], $data['master'] ?? NULL);
}
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;
}
public static function getName() : string {
return static::cookieName('OATMEAL');
}
}