PHP code example of stefna / session

1. Go to this page and download the library: Download stefna/session library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

stefna / session example snippets



$session = $request->getAttribute(\Stefna\Session\SessionStorage::class); 


$messageCollection = $request->getAttribute(\Stefna\Session\Flash\FlashMessages::class); 


use Psr\Http\Message\ServerRequestInterface;

class Action
{
	public function __invoke(ServerRequestInterface $request)
	{
		$session = $request->getAttribute(\Stefna\Session\SessionStorage::class);
		if ($session->getBool('loggedIn')) {
			$session->set('loggedIn', false);
		}
		elseif ($session->has('blocked')) {
			$session->remove('blocked');
		}
	}
}


use Psr\Http\Message\ServerRequestInterface;
use Stefna\Session\Flash\FlashMessage;
use Stefna\Session\Flash\FlashMessages;
use Stefna\Session\Flash\MessageType;

class Action
{
	public function __invoke(ServerRequestInterface $request)
	{
		$flashMessages = $request->getAttribute(FlashMessages::class);
		$flashMessages->add(new FlashMessage('Stuff happened', type: MessageType::Live));
	}
}


use Psr\Http\Message\ServerRequestInterface;
use Stefna\Session\Flash\FlashMessages;
use Stefna\Session\Flash\MessageType;

class Action
{
	public function __invoke(ServerRequestInterface $request)
	{
		$flashMessages = $request->getAttribute(FlashMessages::class);
		$messages = $flashMessages->getMessages(MessageType::Live);
		
		$this->renderGrowMessages($messages);
	}
}