mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
NEW: Move session activation to SessionMiddleware.
This commit is contained in:
parent
254204a3a6
commit
db080c0603
@ -3,6 +3,7 @@ Name: requestprocessors
|
||||
---
|
||||
SilverStripe\Control\Director:
|
||||
middlewares:
|
||||
SessionMiddleware: 'SilverStripe\Control\SessionMiddleware'
|
||||
RequestProcessor: 'SilverStripe\Control\RequestProcessor'
|
||||
FlushMiddleware: '%$SilverStripe\Control\FlushMiddleware'
|
||||
|
||||
|
@ -132,13 +132,7 @@ class Director implements TemplateGlobalProvider
|
||||
}
|
||||
|
||||
// Generate output
|
||||
$result = static::handleRequest($request);
|
||||
|
||||
// Save session data. Note that save() will start/resume the session if required.
|
||||
$request->getSession()->save();
|
||||
|
||||
// Return
|
||||
return $result;
|
||||
return static::handleRequest($request);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -96,8 +96,6 @@ class HTTPApplication implements Application
|
||||
|
||||
// Ensure boot is invoked
|
||||
return $this->execute($request, function (HTTPRequest $request) {
|
||||
// Start session and execute
|
||||
$request->getSession()->init();
|
||||
return Director::direct($request);
|
||||
}, $flush);
|
||||
}
|
||||
|
28
src/Control/SessionMiddleware.php
Normal file
28
src/Control/SessionMiddleware.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Control;
|
||||
|
||||
class SessionMiddleware implements HTTPMiddleware
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function process(HTTPRequest $request, callable $delegate)
|
||||
{
|
||||
try {
|
||||
// Start session and execute
|
||||
$request->getSession()->init();
|
||||
|
||||
// Generate output
|
||||
$response = $delegate($request);
|
||||
|
||||
// Save session data, even if there was an exception.
|
||||
// Note that save() will start/resume the session if required.
|
||||
} finally {
|
||||
$request->getSession()->save();
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user