class TestSessionBag in Drupal 9
Same name and namespace in other branches
- 8 core/modules/system/tests/modules/session_test/src/Session/TestSessionBag.php \Drupal\session_test\Session\TestSessionBag
Test session container.
Hierarchy
- class \Drupal\session_test\Session\TestSessionBag implements \Symfony\Component\HttpFoundation\Session\SessionBagInterface
Expanded class hierarchy of TestSessionBag
1 file declares its use of TestSessionBag
- SessionTestController.php in core/
modules/ system/ tests/ modules/ session_test/ src/ Controller/ SessionTestController.php
1 string reference to 'TestSessionBag'
- session_test.services.yml in core/
modules/ system/ tests/ modules/ session_test/ session_test.services.yml - core/modules/system/tests/modules/session_test/session_test.services.yml
1 service uses TestSessionBag
- session_test.session_bag in core/
modules/ system/ tests/ modules/ session_test/ session_test.services.yml - Drupal\session_test\Session\TestSessionBag
File
- core/
modules/ system/ tests/ modules/ session_test/ src/ Session/ TestSessionBag.php, line 10
Namespace
Drupal\session_test\SessionView source
class TestSessionBag implements SessionBagInterface {
/**
* The bag name.
*/
const BAG_NAME = 'session_test';
/**
* Key used when persisting the session.
*
* @var string
*/
protected $storageKey;
/**
* Storage for data to save.
*
* @var array
*/
protected $attributes = [];
/**
* Constructs a new TestSessionBag object.
*
* @param string $storage_key
* The key used to store test attributes.
*/
public function __construct($storage_key = '_dp_session_test') {
$this->storageKey = $storage_key;
}
/**
* Sets the test flag.
*/
public function setFlag() {
$this->attributes['test_flag'] = TRUE;
}
/**
* Returns TRUE if the test flag is set.
*
* @return bool
* TRUE when flag is set, FALSE otherwise.
*/
public function hasFlag() {
return !empty($this->attributes['test_flag']);
}
/**
* Clears the test flag.
*/
public function clearFlag() {
unset($this->attributes['test_flag']);
}
/**
* {@inheritdoc}
*/
public function getName() {
return self::BAG_NAME;
}
/**
* {@inheritdoc}
*/
public function initialize(array &$attributes) {
$this->attributes =& $attributes;
}
/**
* {@inheritdoc}
*/
public function getStorageKey() {
return $this->storageKey;
}
/**
* {@inheritdoc}
*/
public function clear() {
$return = $this->attributes;
$this->attributes = [];
return $return;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
TestSessionBag:: |
protected | property | Storage for data to save. | |
TestSessionBag:: |
protected | property | Key used when persisting the session. | |
TestSessionBag:: |
constant | The bag name. | ||
TestSessionBag:: |
public | function | ||
TestSessionBag:: |
public | function | Clears the test flag. | |
TestSessionBag:: |
public | function | ||
TestSessionBag:: |
public | function | ||
TestSessionBag:: |
public | function | Returns TRUE if the test flag is set. | |
TestSessionBag:: |
public | function | ||
TestSessionBag:: |
public | function | Sets the test flag. | |
TestSessionBag:: |
public | function | Constructs a new TestSessionBag object. |