<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
dwendrich / expressive-session-middleware example snippets
$aggregator = new ConfigAggregator([
// enable SessionMiddleware
SessionMiddleware\ConfigProvider::class,
// ... other stuff goes here
// Load application config in a pre-defined order in such a way that local settings
// overwrite global settings. (Loaded as first to last):
// - `global.php`
// - `*.global.php`
// - `local.php`
// - `*.local.php`
new PhpFileProvider('config/autoload/{{,*.}global,{,*.}local}.php'),
// Load development config if it exists
new PhpFileProvider('config/development.config.php'),
], $cacheConfig['config_cache_path']);
// Register session handling middleware
$app->pipe(SessionMiddleware::class);
// Register the routing middleware in the middleware pipeline
$app->pipe(\Zend\Expressive\Router\Middleware\RouteMiddleware::class);
$app->pipe(ImplicitHeadMiddleware::class);
$app->pipe(ImplicitOptionsMiddleware::class);
$app->pipe(UrlHelperMiddleware::class);
/**
* Process an incoming server request and return a response, optionally delegating
* to the next middleware component to create the response.
*
* @param ServerRequestInterface $request
* @param DelegateInterface $delegate
*
* @return ResponseInterface
*/
public function process(ServerRequestInterface $request, DelegateInterface $delegate) : ResponseInterface
{
$sessionManager = $request->getAttribute(SessionMiddleware::SESSION_ATTRIBUTE, false);
if ($sessionManager) {
// sessionManager is present and can be used
}
// further request processing goes here...
}
use Zend\Session\Container;
$container = Container('my_namespace');
// save 'foo' into the `item` key
$container->item = 'foo';
use Zend\Session\Container;
$container = Container('my_namespace');
// read the content from the `item` key
$foo = $container->item;