PHP code example of germania-kg / aurasession-middleware

1. Go to this page and download the library: Download germania-kg/aurasession-middleware 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/ */

    

germania-kg / aurasession-middleware example snippets



use Germania\AuraSessionMiddleware\AuraSessionSegmentMiddleware;

// Create session and segment, cf. Aura.Session docs
$session_factory = new \Aura\Session\SessionFactory;
$session = $session_factory->newInstance($_COOKIE);
$segment = $session->getSegment('Vendor\Package\ClassName');

// Optional with PSR-3 Logger
$mw = new AuraSessionSegmentMiddleware( $segment );
$mw = new AuraSessionSegmentMiddleware( $segment, $logger );


$app = new \Slim\App();
$app->get('/books/{id}', function ($request, $response, $args) {
	// This is your Aura.Session segment
    $session = $request->getAttribute("session");
	...    
});


$mw = new AuraSessionSegmentMiddleware( $segment );

// "session" per default
echo $mv->getRequestAttributeName( );

// Choose another one...
$mv->setRequestAttributeName( "custom_name" );

// Inside route:
$session = $request->getAttribute("custom_name");


use Germania\AuraSessionMiddleware\PimpleServiceProvider;
use Aura\Session\SegmentInterface;
use Psr\Log\LoggerInterface;

// have your Pimple DIC ready, and optionally a PSR3 Logger:
$sp = new PimpleServiceProvider("session", "request_attr");
$sp = new PimpleServiceProvider("session", "request_attr", $psr3_logger);
$sp->register( $dic );

// Grab your services
$yes = $dic['Session'] instanceOf SegmentInterface;
$yes = $dic['Session.Logger'] instanceOf LoggerInterface;
$yes = is_callable( $dic['Session.Middleware'] );


$app = new \Slim\App;
$app->add( $dic['Session.Middleware'] );