hub20xx / session
一个简单的会话类
0.2.0
2016-01-05 14:08 UTC
Requires (Dev)
- phpunit/phpunit: ^5.1
This package is not auto-updated.
Last update: 2024-09-14 18:20:38 UTC
README
一个简单的会话类。
安装
通过Composer
$ composer require hub20xxx/session
使用方法
您可以使用此类存储/检索可以在PHP会话中存储的任何内容。
// Forget about session_start(): // - current session left alone if present // - new session started if no session present $session = new \hub20xxx\Session\Session; // Checking the existence of a session variable $session->exists('variable'); // returns a boolean // Setting session variables $session->set('myString', 'stringy string'); $session->set('myArray', ['key' => 'value', 'otherKey' => 'otherValue']); $session->set('myClass', new StdClass); // Getting values of session variables $mySessionString = $session->get('myString'); $mySessionArray = $session->get('myArray'); $mySessionClass = $session->get('myClass'); // Deleting session variables $session->delete('myString'); $session->delete('myArray'); $session->delete('myClass'); // Flashing session variables // 1. Setting the session variable (you can use the set method as well) $session->flash('myFlashString', 'stringy string'); $session->flash('myFlashArray', ['key' => 'value', 'otherKey' => 'otherValue']); $session->flash('myFlashClass', new StdClass); // 2. Getting values of session variables and deleting them $myFlashString = $session->flash('myFlashString'); $myFlashArray = $session->flash('myFlashArray'); $myFlashClass = $session->flash('myFlashClass');
测试
$ phpunit
许可证
致谢
本包灵感来源于(其中之一)
非常感谢他们 :)
贡献
如果您想贡献力量,请使用Github(问题、拉取请求等)。