├── .cs.php
├── .github
├── dependabot.yml
└── workflows
│ └── build.yml
├── CHANGELOG.md
├── LICENSE
├── README.md
├── _config.yml
├── composer.json
├── phpcs.xml
├── phpstan.neon
├── phpunit.xml
└── src
├── Exception
└── SessionException.php
├── Flash.php
├── FlashInterface.php
├── MemorySession.php
├── Middleware
└── SessionStartMiddleware.php
├── PhpSession.php
├── SessionInterface.php
└── SessionManagerInterface.php
/.cs.php:
--------------------------------------------------------------------------------
1 | setUsingCache(false)
7 | ->setRiskyAllowed(true)
8 | ->setRules(
9 | [
10 | '@PSR1' => true,
11 | '@PSR2' => true,
12 | '@Symfony' => true,
13 | 'psr_autoloading' => true,
14 | // custom rules
15 | 'align_multiline_comment' => ['comment_type' => 'phpdocs_only'], // psr-5
16 | 'phpdoc_to_comment' => false,
17 | 'no_superfluous_phpdoc_tags' => false,
18 | 'array_indentation' => true,
19 | 'array_syntax' => ['syntax' => 'short'],
20 | 'cast_spaces' => ['space' => 'none'],
21 | 'concat_space' => ['spacing' => 'one'],
22 | 'compact_nullable_type_declaration' => true,
23 | 'declare_equal_normalize' => ['space' => 'single'],
24 | 'general_phpdoc_annotation_remove' => [
25 | 'annotations' => [
26 | 'author',
27 | 'package',
28 | ],
29 | ],
30 | 'increment_style' => ['style' => 'post'],
31 | 'list_syntax' => ['syntax' => 'short'],
32 | 'echo_tag_syntax' => ['format' => 'long'],
33 | 'phpdoc_add_missing_param_annotation' => ['only_untyped' => false],
34 | 'phpdoc_align' => false,
35 | 'phpdoc_no_empty_return' => false,
36 | 'phpdoc_order' => true, // psr-5
37 | 'phpdoc_no_useless_inheritdoc' => false,
38 | 'protected_to_private' => false,
39 | 'yoda_style' => false,
40 | 'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'],
41 | 'ordered_imports' => [
42 | 'sort_algorithm' => 'alpha',
43 | 'imports_order' => ['class', 'function', 'const'],
44 | ],
45 | 'single_line_throw' => false,
46 | 'declare_strict_types' => false,
47 | 'blank_line_between_import_groups' => true,
48 | 'fully_qualified_strict_types' => true,
49 | 'no_null_property_initialization' => false,
50 | 'nullable_type_declaration_for_default_null_value' => false,
51 | 'operator_linebreak' => [
52 | 'only_booleans' => true,
53 | 'position' => 'beginning',
54 | ],
55 | 'global_namespace_import' => [
56 | 'import_classes' => true,
57 | 'import_constants' => null,
58 | 'import_functions' => null
59 | ],
60 | 'class_definition' => [
61 | 'space_before_parenthesis' => true,
62 | ],
63 | 'declare_equal_normalize' => false,
64 | 'phpdoc_summary' => false,
65 | 'phpdoc_add_missing_param_annotation' => false,
66 | 'no_useless_concat_operator' => false,
67 | 'fully_qualified_strict_types' => false,
68 | ]
69 | )
70 | ->setFinder(
71 | PhpCsFixer\Finder::create()
72 | ->in(__DIR__ . '/src')
73 | ->in(__DIR__ . '/tests')
74 | ->name('*.php')
75 | ->ignoreDotFiles(true)
76 | ->ignoreVCS(true)
77 | );
78 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 | - package-ecosystem: composer
4 | directory: "/"
5 | schedule:
6 | interval: daily
7 | time: "04:00"
8 | open-pull-requests-limit: 10
9 |
--------------------------------------------------------------------------------
/.github/workflows/build.yml:
--------------------------------------------------------------------------------
1 | name: build
2 |
3 | on:
4 | push:
5 | branches:
6 | - '6.x'
7 | pull_request:
8 | branches:
9 | - '*'
10 |
11 | jobs:
12 | run:
13 | runs-on: ${{ matrix.operating-system }}
14 | strategy:
15 | matrix:
16 | operating-system: [ ubuntu-latest ]
17 | php-versions: [ '8.2', '8.3', '8.4' ]
18 | name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }}
19 |
20 | steps:
21 | - name: Checkout
22 | uses: actions/checkout@v1
23 |
24 | - name: Setup PHP
25 | uses: shivammathur/setup-php@v2
26 | with:
27 | php-version: ${{ matrix.php-versions }}
28 | coverage: none
29 |
30 | - name: Check PHP Version
31 | run: php -v
32 |
33 | - name: Check Composer Version
34 | run: composer -V
35 |
36 | - name: Check PHP Extensions
37 | run: php -m
38 |
39 | - name: Validate composer.json and composer.lock
40 | run: composer validate
41 |
42 | - name: Install dependencies
43 | run: composer install --prefer-dist --no-progress --no-suggest
44 |
45 | - name: Run test suite
46 | run: composer test:all
47 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 |
3 | All notable changes to this project will be documented in this file.
4 |
5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7 |
8 | ## [6.3.0] - 2024-12-15
9 |
10 | * Add support for PHP 8.4
11 |
12 | ## [6.2.0] - 2024-09-20
13 |
14 | ### Added
15 |
16 | * Add support for PHP 8.3
17 | * Add support for psr/http-message 2.x
18 |
19 | ### Changes
20 |
21 | * Upgrade tests to PHPUnit 11
22 |
23 | ### Removed
24 |
25 | * Drop support for PHP 8.0 and 8.1
26 |
27 | ## [6.1.0] - 2023-02-22
28 |
29 | ### Added
30 |
31 | * Add `has` method to `SessionInterface` #30 #29
32 | * Add PHP 8.2 to build pipeline
33 |
34 | ### Changed
35 |
36 | * Update docs
37 |
38 | ## [6.0.0] - 2022-12-04
39 |
40 | ### Changes
41 |
42 | * Require PHP 8.0+
43 | * Make session settings "immutable".
44 | * Move all session settings to the `PhpSession` constructor.
45 | * Provide interfaces for each concern (management and session data).
46 | * Change `SessionInterface` to handle session data operations only, e.g. `get`, `set`.
47 | * Rename session method `replace` to `setValues`.
48 | * Rename session method `remove` to `delete`.
49 | * Calling the session `save` method is now optional.
50 | * Rename class `Odan\Session\Middleware\SessionMiddleware` to `Odan\Session\Middleware\SessionStartMiddleware`.
51 |
52 | ### Added
53 |
54 | * Add `SessionManagerInterface` to handle session operations, such as `start`, `save`, `destroy`, `getName`, etc.
55 | * Add `default` parameter to session `get` method.
56 |
57 | ### Removed
58 |
59 | * Remove session method `setOptions` and `getOptions`. Pass all settings into `PhpSession` constructor instead.
60 | * Remove session method `setCookieParams` and `getCookieParams`. The cookie parameters must be
61 | defined in the settings and will set in the session `start` method.
62 | * Remove session `setName` method. Use the `name` setting instead.
63 | * Remove session `setId` method. Use the optional `id` setting instead.
64 | * Remove session `count` method.
65 | * Remove `SessionAwareInterface` in favor of dependency injection.
66 |
67 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2023 odan
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Session handler
2 |
3 | [](https://github.com/odan/session/releases)
4 | [](LICENSE)
5 | [](https://packagist.org/packages/odan/session/stats)
6 |
7 | A middleware (PSR-15) oriented session and flash message handler for PHP.
8 |
9 | * Documentation for v6:
10 |
--------------------------------------------------------------------------------
/_config.yml:
--------------------------------------------------------------------------------
1 | theme: jekyll-theme-cayman
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "odan/session",
3 | "type": "library",
4 | "description": "A Slim session handler",
5 | "keywords": [
6 | "slim",
7 | "session"
8 | ],
9 | "homepage": "https://github.com/odan/session",
10 | "license": "MIT",
11 | "require": {
12 | "php": "~8.2.0 || ~8.3.0 || ~8.4.0",
13 | "psr/http-message": "^1 || ^2",
14 | "psr/http-server-handler": "^1",
15 | "psr/http-server-middleware": "^1"
16 | },
17 | "require-dev": {
18 | "friendsofphp/php-cs-fixer": "^3",
19 | "middlewares/utils": "^3",
20 | "nyholm/psr7": "^1.5",
21 | "phpstan/phpstan": "^2",
22 | "phpunit/phpunit": "^11",
23 | "squizlabs/php_codesniffer": "^3"
24 | },
25 | "scripts": {
26 | "cs:check": [
27 | "@putenv PHP_CS_FIXER_IGNORE_ENV=1",
28 | "php-cs-fixer fix --dry-run --format=txt --verbose --config=.cs.php --ansi"
29 | ],
30 | "cs:fix": [
31 | "@putenv PHP_CS_FIXER_IGNORE_ENV=1",
32 | "php-cs-fixer fix --config=.cs.php --ansi --verbose"
33 | ],
34 | "sniffer:check": "phpcs --standard=phpcs.xml",
35 | "sniffer:fix": "phpcbf --standard=phpcs.xml",
36 | "stan": "phpstan analyse -c phpstan.neon --no-progress --ansi",
37 | "test": "phpunit --configuration phpunit.xml --do-not-cache-result --colors=always --display-warnings --display-deprecations --no-coverage",
38 | "test:all": [
39 | "@cs:check",
40 | "@sniffer:check",
41 | "@stan",
42 | "@test"
43 | ],
44 | "test:coverage": [
45 | "@putenv XDEBUG_MODE=coverage",
46 | "phpunit --configuration phpunit.xml --do-not-cache-result --colors=always --display-warnings --display-deprecations --coverage-clover build/coverage/clover.xml --coverage-html build/coverage --coverage-text"
47 | ]
48 | },
49 | "autoload": {
50 | "psr-4": {
51 | "Odan\\Session\\": "src/"
52 | }
53 | },
54 | "autoload-dev": {
55 | "psr-4": {
56 | "Odan\\Session\\Test\\": "tests/"
57 | }
58 | },
59 | "config": {
60 | "sort-packages": true
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/phpcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | ./src
11 | ./tests
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/phpstan.neon:
--------------------------------------------------------------------------------
1 | parameters:
2 | level: 8
3 | paths:
4 | - src
5 | - tests
6 |
--------------------------------------------------------------------------------
/phpunit.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
13 | tests
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 | src
23 |
24 |
25 | build
26 | vendor
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/src/Exception/SessionException.php:
--------------------------------------------------------------------------------
1 | |ArrayAccess
14 | */
15 | private array|ArrayAccess $storage;
16 |
17 | private string $storageKey;
18 |
19 | /**
20 | * @param array|ArrayAccess $storage
21 | */
22 | public function __construct(array|ArrayAccess &$storage, string $storageKey = '_flash')
23 | {
24 | $this->storage = &$storage;
25 | $this->storageKey = $storageKey;
26 | }
27 |
28 | public function add(string $key, string $message): void
29 | {
30 | // Create array for this key
31 | if (!isset($this->storage[$this->storageKey][$key])) {
32 | $this->storage[$this->storageKey][$key] = [];
33 | }
34 |
35 | // Push onto the array
36 | $this->storage[$this->storageKey][$key][] = $message;
37 | }
38 |
39 | public function get(string $key): array
40 | {
41 | if (!$this->has($key)) {
42 | return [];
43 | }
44 |
45 | $return = $this->storage[$this->storageKey][$key];
46 | unset($this->storage[$this->storageKey][$key]);
47 |
48 | return (array)$return;
49 | }
50 |
51 | public function has(string $key): bool
52 | {
53 | return isset($this->storage[$this->storageKey][$key]);
54 | }
55 |
56 | public function clear(): void
57 | {
58 | unset($this->storage[$this->storageKey]);
59 | }
60 |
61 | public function set(string $key, array $messages): void
62 | {
63 | $this->storage[$this->storageKey][$key] = $messages;
64 | }
65 |
66 | public function all(): array
67 | {
68 | $result = $this->storage[$this->storageKey] ?? [];
69 | $this->clear();
70 |
71 | return (array)$result;
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/FlashInterface.php:
--------------------------------------------------------------------------------
1 | The messages
26 | */
27 | public function get(string $key): array;
28 |
29 | /**
30 | * Has flash message.
31 | *
32 | * @param string $key The key
33 | *
34 | * @return bool Whether the key is set or not
35 | */
36 | public function has(string $key): bool;
37 |
38 | /**
39 | * Clear all messages.
40 | *
41 | * @return void
42 | */
43 | public function clear(): void;
44 |
45 | /**
46 | * Set all messages.
47 | *
48 | * @param string $key The key to clear
49 | * @param array $messages The messages
50 | *
51 | * @return void
52 | */
53 | public function set(string $key, array $messages): void;
54 |
55 | /**
56 | * Gets all flash messages.
57 | *
58 | * @return array All messages. Can be an empty array.
59 | */
60 | public function all(): array;
61 | }
62 |
--------------------------------------------------------------------------------
/src/MemorySession.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | private array $options = [
14 | 'name' => 'app',
15 | 'lifetime' => 7200,
16 | ];
17 |
18 | /**
19 | * @var array
20 | */
21 | private array $storage;
22 |
23 | private Flash $flash;
24 |
25 | private string $id = '';
26 |
27 | private bool $started = false;
28 |
29 | /**
30 | * @param array $options
31 | */
32 | public function __construct(array $options = [])
33 | {
34 | $keys = array_keys($this->options);
35 | foreach ($keys as $key) {
36 | if (array_key_exists($key, $options)) {
37 | $this->options[$key] = $options[$key];
38 | }
39 | }
40 |
41 | $session = [];
42 | $this->storage = &$session;
43 | $this->flash = new Flash($session);
44 | }
45 |
46 | public function getFlash(): FlashInterface
47 | {
48 | return $this->flash;
49 | }
50 |
51 | public function start(): void
52 | {
53 | if (!$this->id) {
54 | $this->regenerateId();
55 | }
56 |
57 | $this->started = true;
58 | }
59 |
60 | public function isStarted(): bool
61 | {
62 | return $this->started;
63 | }
64 |
65 | public function regenerateId(): void
66 | {
67 | $this->id = str_replace('.', '', uniqid('sess_', true));
68 | }
69 |
70 | public function destroy(): void
71 | {
72 | $keys = array_keys($this->storage);
73 | foreach ($keys as $key) {
74 | unset($this->storage[$key]);
75 | }
76 | $this->regenerateId();
77 | }
78 |
79 | public function getId(): string
80 | {
81 | return $this->id;
82 | }
83 |
84 | public function getName(): string
85 | {
86 | return $this->options['name'];
87 | }
88 |
89 | public function get(string $key, mixed $default = null): mixed
90 | {
91 | return $this->storage[$key] ?? $default;
92 | }
93 |
94 | public function all(): array
95 | {
96 | return (array)$this->storage;
97 | }
98 |
99 | public function set(string $key, mixed $value): void
100 | {
101 | $this->storage[$key] = $value;
102 | }
103 |
104 | public function setValues(array $values): void
105 | {
106 | foreach ($values as $key => $value) {
107 | $this->storage[$key] = $value;
108 | }
109 | }
110 |
111 | public function has(string $key): bool
112 | {
113 | return array_key_exists($key, $this->storage);
114 | }
115 |
116 | public function delete(string $key): void
117 | {
118 | unset($this->storage[$key]);
119 | }
120 |
121 | public function clear(): void
122 | {
123 | $keys = array_keys($this->storage);
124 | foreach ($keys as $key) {
125 | unset($this->storage[$key]);
126 | }
127 | }
128 |
129 | public function save(): void
130 | {
131 | }
132 | }
133 |
--------------------------------------------------------------------------------
/src/Middleware/SessionStartMiddleware.php:
--------------------------------------------------------------------------------
1 | session = $session;
18 | }
19 |
20 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
21 | {
22 | if (!$this->session->isStarted()) {
23 | $this->session->start();
24 | }
25 |
26 | $response = $handler->handle($request);
27 | $this->session->save();
28 |
29 | return $response;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/PhpSession.php:
--------------------------------------------------------------------------------
1 |
14 | */
15 | private array $storage;
16 |
17 | private FlashInterface $flash;
18 |
19 | /**
20 | * @var array
21 | */
22 | private array $options = [
23 | 'id' => null,
24 | 'name' => 'app',
25 | 'lifetime' => 7200,
26 | 'path' => null,
27 | 'domain' => null,
28 | 'secure' => false,
29 | 'httponly' => true,
30 | // public, private_no_expire, private, nocache
31 | // Setting the cache limiter to '' will turn off automatic sending of cache headers entirely.
32 | 'cache_limiter' => 'nocache',
33 | ];
34 |
35 | /**
36 | * @param array $options
37 | */
38 | public function __construct(array $options = [])
39 | {
40 | // Prevent uninitialized state
41 | $empty = [];
42 | $this->storage = &$empty;
43 | $this->flash = new Flash($empty);
44 |
45 | $keys = array_keys($this->options);
46 | foreach ($keys as $key) {
47 | if (array_key_exists($key, $options)) {
48 | $this->options[$key] = $options[$key];
49 | unset($options[$key]);
50 | }
51 | }
52 |
53 | foreach ($options as $key => $value) {
54 | ini_set('session.' . $key, $value);
55 | }
56 | }
57 |
58 | public function start(): void
59 | {
60 | if ($this->isStarted()) {
61 | throw new SessionException('Failed to start the session: Already started.');
62 | }
63 |
64 | if (headers_sent($file, $line) && filter_var(ini_get('session.use_cookies'), FILTER_VALIDATE_BOOLEAN)) {
65 | throw new SessionException(
66 | sprintf(
67 | 'Failed to start the session because headers have already been sent by "%s" at line %d.',
68 | $file,
69 | $line
70 | )
71 | );
72 | }
73 |
74 | $current = session_get_cookie_params();
75 |
76 | $lifetime = (int)($this->options['lifetime'] ?: $current['lifetime']);
77 | $path = $this->options['path'] ?: $current['path'];
78 | $domain = $this->options['domain'] ?: $current['domain'];
79 | $secure = (bool)$this->options['secure'];
80 | $httponly = (bool)$this->options['httponly'];
81 |
82 | session_set_cookie_params($lifetime, $path, $domain, $secure, $httponly);
83 | session_name($this->options['name']);
84 | session_cache_limiter($this->options['cache_limiter']);
85 |
86 | $sessionId = $this->options['id'] ?: null;
87 | if ($sessionId) {
88 | session_id($sessionId);
89 | }
90 |
91 | // Try and start the session
92 | if (!session_start()) {
93 | throw new SessionException('Failed to start the session.');
94 | }
95 |
96 | // Load the session
97 | $this->storage = &$_SESSION;
98 | $this->flash = new Flash($_SESSION);
99 | }
100 |
101 | public function isStarted(): bool
102 | {
103 | return session_status() === PHP_SESSION_ACTIVE;
104 | }
105 |
106 | public function regenerateId(): void
107 | {
108 | if (!$this->isStarted()) {
109 | throw new SessionException('Cannot regenerate the session ID for non-active sessions.');
110 | }
111 |
112 | if (headers_sent()) {
113 | throw new SessionException('Headers have already been sent.');
114 | }
115 |
116 | if (!session_regenerate_id(true)) {
117 | throw new SessionException('The session ID could not be regenerated.');
118 | }
119 | }
120 |
121 | public function destroy(): void
122 | {
123 | if (!$this->isStarted()) {
124 | return;
125 | }
126 |
127 | $this->clear();
128 |
129 | if (ini_get('session.use_cookies')) {
130 | $params = session_get_cookie_params();
131 | setcookie(
132 | $this->getName(),
133 | '',
134 | time() - 42000,
135 | $params['path'],
136 | $params['domain'],
137 | $params['secure'],
138 | $params['httponly']
139 | );
140 | }
141 |
142 | if (session_unset() === false) {
143 | throw new SessionException('The session could not be unset.');
144 | }
145 |
146 | if (session_destroy() === false) {
147 | throw new SessionException('The session could not be destroyed.');
148 | }
149 | }
150 |
151 | public function getId(): string
152 | {
153 | return (string)session_id();
154 | }
155 |
156 | public function getName(): string
157 | {
158 | return (string)session_name();
159 | }
160 |
161 | public function get(string $key, mixed $default = null): mixed
162 | {
163 | return $this->storage[$key] ?? $default;
164 | }
165 |
166 | public function all(): array
167 | {
168 | return (array)$this->storage;
169 | }
170 |
171 | public function set(string $key, mixed $value): void
172 | {
173 | $this->storage[$key] = $value;
174 | }
175 |
176 | public function setValues(array $values): void
177 | {
178 | foreach ($values as $key => $value) {
179 | $this->storage[$key] = $value;
180 | }
181 | }
182 |
183 | public function has(string $key): bool
184 | {
185 | return array_key_exists($key, $this->storage);
186 | }
187 |
188 | public function delete(string $key): void
189 | {
190 | unset($this->storage[$key]);
191 | }
192 |
193 | public function clear(): void
194 | {
195 | $keys = array_keys($this->storage);
196 | foreach ($keys as $key) {
197 | unset($this->storage[$key]);
198 | }
199 | }
200 |
201 | public function save(): void
202 | {
203 | session_write_close();
204 | }
205 |
206 | public function getFlash(): FlashInterface
207 | {
208 | return $this->flash;
209 | }
210 | }
211 |
--------------------------------------------------------------------------------
/src/SessionInterface.php:
--------------------------------------------------------------------------------
1 | The session values
24 | */
25 | public function all(): array;
26 |
27 | /**
28 | * Sets an attribute by key.
29 | *
30 | * @param string $key The key of the element to set
31 | * @param mixed $value The data to set
32 | *
33 | * @return void
34 | */
35 | public function set(string $key, mixed $value): void;
36 |
37 | /**
38 | * Sets multiple attributes at once: takes a keyed array and sets each key => value pair.
39 | *
40 | * @param array $values The new values
41 | */
42 | public function setValues(array $values): void;
43 |
44 | /**
45 | * Check if an attribute key exists.
46 | *
47 | * @param string $key The key
48 | *
49 | * @return bool True if the key is set or not
50 | */
51 | public function has(string $key): bool;
52 |
53 | /**
54 | * Deletes an attribute by key.
55 | *
56 | * @param string $key The key to remove
57 | */
58 | public function delete(string $key): void;
59 |
60 | /**
61 | * Clear all attributes.
62 | */
63 | public function clear(): void;
64 |
65 | /**
66 | * Get flash handler.
67 | *
68 | * @return FlashInterface The flash handler
69 | */
70 | public function getFlash(): FlashInterface;
71 | }
72 |
--------------------------------------------------------------------------------
/src/SessionManagerInterface.php:
--------------------------------------------------------------------------------
1 |