TestSessionBag.php in Drupal 10
File
core/modules/system/tests/modules/session_test/src/Session/TestSessionBag.php
View source
<?php
namespace Drupal\session_test\Session;
use Symfony\Component\HttpFoundation\Session\SessionBagInterface;
class TestSessionBag implements SessionBagInterface {
const BAG_NAME = 'session_test';
protected $storageKey;
protected $attributes = [];
public function __construct($storage_key = '_dp_session_test') {
$this->storageKey = $storage_key;
}
public function setFlag() {
$this->attributes['test_flag'] = TRUE;
}
public function hasFlag() {
return !empty($this->attributes['test_flag']);
}
public function clearFlag() {
unset($this->attributes['test_flag']);
}
public function getName() : string {
return self::BAG_NAME;
}
public function initialize(array &$attributes) {
$this->attributes =& $attributes;
}
public function getStorageKey() : string {
return $this->storageKey;
}
public function clear() : mixed {
$return = $this->attributes;
$this->attributes = [];
return $return;
}
}