Skip to content

Commit 5055d88

Browse files
committed
Refactored - creates and starts the session immediately
1 parent 4495e16 commit 5055d88

1 file changed

Lines changed: 3 additions & 22 deletions

File tree

SessionMiddleware.php

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,15 @@ class SessionMiddleware implements MiddlewareInterface
2121
{
2222
public const SESSION_STARTED = 'sessionStarted';
2323

24-
/**
25-
* @var array Options for session_start()
26-
* @see http://php.net/manual/en/session.configuration.php
27-
*/
28-
private $options = [];
29-
3024
public function __construct(ConfigurationFactory $settings)
3125
{
32-
$this->options = session_register_custom_handler($settings)->sessionParameters();
26+
$options = session_register_custom_handler($settings)->sessionParameters();
27+
session_start($options);
3328
}
3429

3530
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
3631
{
37-
session_write_close();
38-
39-
if (PHP_SESSION_ACTIVE !== session_status()) {
40-
$request = $request->withAttribute(self::SESSION_STARTED, $this->startSession());
41-
}
42-
32+
$request = $request->withAttribute(self::SESSION_STARTED, PHP_SESSION_ACTIVE === session_status());
4333
$response = $handler->handle($request);
4434

4535
if (500 !== $response->getStatusCode()) {
@@ -48,13 +38,4 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
4838

4939
return $response;
5040
}
51-
52-
private function startSession(): bool
53-
{
54-
if ($started = session_start($this->options)) {
55-
new PhpSession;
56-
}
57-
58-
return $started;
59-
}
6041
}

0 commit comments

Comments
 (0)