Skip to content

Commit 07f7919

Browse files
committed
removed StrongerNativeSessionStorage workaround and redirect stdout to client.
1 parent 3cbe1bb commit 07f7919

File tree

3 files changed

+20
-68
lines changed

3 files changed

+20
-68
lines changed

Bootstraps/Symfony.php

-7
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,6 @@ public function getApplication()
7171
$app->initializeContainer();
7272
}, $app);
7373

74-
//now we can modify the container
75-
$nativeStorage = new StrongerNativeSessionStorage(
76-
$app->getContainer()->getParameter('session.storage.options'),
77-
$app->getContainer()->has('session.handler') ? $app->getContainer()->get('session.handler'): null
78-
);
79-
$app->getContainer()->set('session.storage.native', $nativeStorage);
80-
8174
Utils::bindAndCall(function() use ($app) {
8275
foreach ($app->getBundles() as $bundle) {
8376
$bundle->setContainer($app->container);

Bridges/HttpKernel.php

+20-19
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use PHPPM\Bootstraps\BootstrapInterface;
77
use PHPPM\Bootstraps\HooksInterface;
88
use PHPPM\Bootstraps\RequestClassProviderInterface;
9-
use PHPPM\Utils;
109
use Psr\Http\Message\ServerRequestInterface;
1110
use Psr\Http\Message\ResponseInterface;
1211
use RingCentral\Psr7;
@@ -95,10 +94,8 @@ public function handle(ServerRequestInterface $request)
9594
return $response;
9695
}
9796

98-
// should not receive output from application->handle()
99-
@ob_end_clean();
100-
101-
$response = $this->mapResponse($syResponse);
97+
$out = ob_get_clean();
98+
$response = $this->mapResponse($syResponse, $out);
10299

103100
if ($this->application instanceof TerminableInterface) {
104101
$this->application->terminate($syRequest, $syResponse);
@@ -114,7 +111,8 @@ public function handle(ServerRequestInterface $request)
114111
/**
115112
* Convert React\Http\Request to Symfony\Component\HttpFoundation\Request
116113
*
117-
* @param ReactRequest $reactRequest
114+
* @param ServerRequestInterface $psrRequest
115+
*
118116
* @return SymfonyRequest $syRequest
119117
*/
120118
protected function mapRequest(ServerRequestInterface $psrRequest)
@@ -124,7 +122,6 @@ protected function mapRequest(ServerRequestInterface $psrRequest)
124122

125123
// cookies
126124
$_COOKIE = [];
127-
$sessionCookieSet = false;
128125

129126
foreach ($psrRequest->getHeader('Cookie') as $cookieHeader) {
130127
$cookies = explode(';', $cookieHeader);
@@ -135,19 +132,10 @@ protected function mapRequest(ServerRequestInterface $psrRequest)
135132

136133
if ($name === session_name()) {
137134
session_id($value);
138-
$sessionCookieSet = true;
139135
}
140136
}
141137
}
142138

143-
if (!$sessionCookieSet && session_id()) {
144-
// session id already set from the last round but not obtained
145-
// from the cookie header, so generate a new one, since php is
146-
// not doing it automatically with session_start() if session
147-
// has already been started.
148-
session_id(Utils::generateSessionId());
149-
}
150-
151139
/** @var \React\Http\Io\UploadedFile $file */
152140
$uploadedFiles = $psrRequest->getUploadedFiles();
153141

@@ -174,7 +162,6 @@ protected function mapRequest(ServerRequestInterface $psrRequest)
174162
$mapFiles($uploadedFiles);
175163

176164
// @todo check howto handle additional headers
177-
178165
// @todo check howto support other HTTP methods with bodies
179166
$post = $psrRequest->getParsedBody() ?: array();
180167

@@ -197,16 +184,26 @@ protected function mapRequest(ServerRequestInterface $psrRequest)
197184
* Convert Symfony\Component\HttpFoundation\Response to React\Http\Response
198185
*
199186
* @param SymfonyResponse $syResponse
187+
* @param string $stdout Additional stdout that was catched during handling a request.
188+
*
200189
* @return ResponseInterface
201190
*/
202-
protected function mapResponse(SymfonyResponse $syResponse)
191+
protected function mapResponse(SymfonyResponse $syResponse, $stdout='')
203192
{
204193
// end active session
205194
if (PHP_SESSION_ACTIVE === session_status()) {
195+
// make sure open session are saved to the storage
196+
// in case the framework hasn't closed it correctly.
206197
session_write_close();
207-
session_unset(); // reset $_SESSION
208198
}
209199

200+
// reset session_id in any case to something not valid, for next request
201+
session_id('');
202+
203+
//reset $_SESSION
204+
session_unset();
205+
unset($_SESSION);
206+
210207
$nativeHeaders = [];
211208

212209
foreach (headers_list() as $header) {
@@ -278,6 +275,10 @@ protected function mapResponse(SymfonyResponse $syResponse)
278275
@ob_end_flush();
279276
}
280277

278+
if ($stdout) {
279+
$content = $stdout . $content;
280+
}
281+
281282
if (!isset($headers['Content-Length'])) {
282283
$psrResponse = $psrResponse->withAddedHeader('Content-Length', strlen($content));
283284
}

Symfony/StrongerNativeSessionStorage.php

-42
This file was deleted.

0 commit comments

Comments
 (0)