PHP code example of snicco / session-bundle

1. Go to this page and download the library: Download snicco/session-bundle 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/ */

    

snicco / session-bundle example snippets



// /path/to/configuration/bundles.php

use Snicco\Bundle\Session\SessionBundle;

return [
    
    'bundles' => [
        Snicco\Component\Kernel\ValueObject\Environment::ALL => [
           SessionBundle::class
        ]   
    ]   
];

//path/to/config/middleware.php
use Snicco\Bundle\HttpRouting\Option\MiddlewareOption;
use Snicco\Bundle\Session\Middleware\AllowMutableSessionForReadVerbs;
use Snicco\Bundle\Session\Middleware\SaveResponseAttributes;
use Snicco\Bundle\Session\Middleware\SessionNoCache;
use Snicco\Bundle\Session\Middleware\ShareSessionWithViews;
use Snicco\Bundle\Session\Middleware\StatefulRequest;

return [

    MiddlewareOption::GROUPS => [
        'stateful' => [
            StatefulRequest::class,
            ShareSessionWithViews::class,
            SaveResponseAttributes::class,
//            SessionNoCache::class, optional
        ]   
    ],
    MiddlewareOption::ALIASES => [
        'session-allow-write' => AllowMutableSessionForReadVerbs::class,
        'session-no-cache' => SessionNoCache::class,
    ]
];

// inside a controller or middleware
use Snicco\Component\Session\ImmutableSession;
use Snicco\Component\Session\MutableSession;

$request->getAttribute(ImmutableSession::class);

// Only for unsafe request methods or if allowed explicitly for read requests.
$request->getAttribute(MutableSession::class);