Skip to content

SessionContext

Matěj Bucek edited this page Mar 16, 2021 · 2 revisions

SessionContext

To make working with session easier, you can use our API for that.

Functionalities

namespace SimpleFW\Containers;

class SessionContext implements Context
{
    
    public function __construct(){
        session_start();
    }

    public function get($key)
    {
        if(isset($_SESSION[$key]))
            return $_SESSION[$key];
        else 
            return NULL;
    }

    public function put($key, $value)
    {
        $_SESSION[$key] = $value;
    }
    
    public function destroy(){
        session_destroy();
    }
}

Injection

#[Autowired("@SessionContext")]
private SessionContext $sessionContext;

You can inject the SessionContext through Attribute Autowired, or through the constructor.

Clone this wiki locally