phico/session
最新稳定版本:v0.1.0
Composer 安装命令:
composer require phico/session
包简介
Specialised session support for Phico
README 文档
README
Specialised session support for Phico
Installation
Install using composer
composer require phico/session
Config
Session config should be passed as an array
$config = [ // set the cookie parameters 'cookie' => [ 'name' => 'ssn', 'options' => [ 'expires' => 0, 'path' => '/', 'domain' => '', 'secure' => false, 'httponly' => true, 'samesite' => 'Lax', 'prefix' => '', 'encode' => false, ], ], // set the Time To Live in seconds, sessions will expire after this time 'ttl' => 3600 ];
Usage
Instantiating the Session
Use the session middleware to pass the session through the Request.
public function use(): array { return [ \Phico\Session\SessionMiddleware::class ] }
Storing Data
To store data in the session, use the set method.
$session->set('key', 'value'); // or shorthand $session->key = $value;
Retrieving Data
To retrieve data from the session, use the get method. You can provide a default value that will be returned if the key does not exist.
$value = $session->get('key'); // optionally specify a default value if key is not in the session $value = $session->get('key', 'default'); // or shorthand without specifying a default $value = $session->key;
Checking for Data
To check if a key exists in the session, use the has method.
$exists = $session->has('key');
Flash Messages
Flash messages are used to store data that should be available for only the next request.
Setting Flash Messages
$session->flash('flash_key', 'flash_value');
Retrieving Flash Messages
Flash messages are retrieved using the same get method.
$flashValue = $session->get('flash_key');
Deleting the Session
To delete a session, use the delete method. This removes the session data from the storage.
$session->delete();
Accessing the Session ID
THe session id is readonly
$id = $session->id;
Regenerating the Session ID
To create a new session id use the regenerate method, this will remove the old session from storage.
$session->regenerate();
Issues
If you discover any bugs or issues in behaviour or performance please create an issue, and if you are able a pull request with a fix.
Please make sure to update any tests as appropriate.
For major changes, please open an issue first to discuss what you would like to change.
License
统计信息
- 总下载量: 16
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2024-06-23