Giter Site home page Giter Site logo

session's Introduction

SktT1Byungi/Session

PHP Session manager (with non blocking handler)

Latest Stable Version Total Downloads License

Require

PHP 5.6 <= *

Simple Example

use SktT1Byungi\Session\Session;

 Session::manager()->start();
 Session::set('aaa', '111');
 
 var_dump(Session::get('aaa') === $_SESSION['aaa']);
 // true

Usage

manager()

 Session::manager()->id("id")->name("name")->start();
 // session_id("id");
 // session_id("name");
 // session_start();
 
 Session::manager()->close()->destroy();
 // session_write_close();
 // session_destroy();
 
 Session::manager()->settings([
    'cookie_httponly' => true,
    'use_only_cookies' => true,
 ]);
 // ini_set("session.cookie_httponly", true);
 // ini_set("session.use_only_cookies", true);
 
 Session::manager()->handler(new CustomHandler)->start();
 // used custom handler

helpers

Session::set('aaa', [
    'bbb' => [
        'ccc' => 111,
        'ddd' => 222,
    ],
]);
Session::set('eee', '333');
Session::set('fff', '444');

echo Session::get('aaa.bbb.ccc');
// 111

var_dump(Session::has('ccc'), Session::has('eee'));
// false, true

var_dump(Session::only(['eee', 'fff']));
// ['eee' => '333', 'fff' => '444']

var_dump(Session::except(['aaa']));
// ['eee' => '333', 'fff' => '444']

Session::forget('aaa.bbb'); //or Session::remove('aaa.bbb');
// unset($_SESSION['aaa']['bbb']);

details links : https://laravel.com/docs/5.3/helpers#arrays

collection

Session::set('aaa', [
    [
        "name" => "bangi",
        "position" => "god",
    ],
    [
        "name" => "faker",
        "position" => "human",
    ],
    [
        "name" => "duke",
        "position" => "human",
    ],
    [
        "name" => "wolf",
        "position" => "pig",
    ],
]);

var_dump(Session::collect('aaa')->where('position', 'human')->all());
// [
//     1 => [
//         "name" => "faker",
//         "position" => "human",
//     ],
//     2 => [
//         "name" => "duke",
//         "position" => "human",
//     ],
// ]

details links : https://laravel.com/docs/5.3/collections

PSR-7 Middleware (__invoke, Closure)

when reaches the middleware point, session start.

Slim3 Example

$app->add(Session::manager()->handler(new CustomHandler)->id('mySess')->middleware());

etc..

session blocking(http://konrness.com/php5/how-to-prevent-blocking-php-requests/) 때문에 괜찮은 핸들러 찾아보다가 먼가 조금씩들 아쉬워서 그냥 새로 맹듬... 세션락문제 없고 나중에 핸들러교체 되면서 글로벌세션 변수 사용도 가능하면서 간단하고 또 컴포저로 쓸수 있는걸로...

session's People

Contributors

skt-t1-byungi avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.