Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3d67aba

Browse files
committed
feature#21421 Use proper error message when session write fails#20807 (digilist)
This PR was submitted for the 2.8 branch but it was merged into the 3.3-dev branch instead (closes#21421).Discussion----------Use proper error message when session write fails#20807This improves the error message that is thrown if a session write fails (see#20807)As there was no way to get the actual handler, I introduced a method on the SessionHandlerProxy. I hope that's okay, otherwise please give me a hint on what to do.| Q | A| ------------- | ---| Branch? | 2.8| Bug fix? | no| New feature? | no| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets |#20807| License | MITCommits-------c7a44be Use proper error message when session write fails#20807
2 parentsc6e1a49 +c7a44be commit3d67aba

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

‎src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespaceSymfony\Component\HttpFoundation\Session\Storage;
1313

14+
useSymfony\Component\Debug\Exception\ContextErrorException;
1415
useSymfony\Component\HttpFoundation\Session\SessionBagInterface;
1516
useSymfony\Component\HttpFoundation\Session\Storage\Handler\NativeSessionHandler;
1617
useSymfony\Component\HttpFoundation\Session\Storage\Proxy\AbstractProxy;
@@ -208,7 +209,28 @@ public function regenerate($destroy = false, $lifetime = null)
208209
*/
209210
publicfunctionsave()
210211
{
211-
session_write_close();
212+
// Register custom error handler to catch a possible failure warning during session write
213+
set_error_handler(function ($errno,$errstr,$errfile,$errline,$errcontext) {
214+
thrownewContextErrorException($errstr,$errno,E_WARNING,$errfile,$errline,$errcontext);
215+
},E_WARNING);
216+
217+
try {
218+
session_write_close();
219+
restore_error_handler();
220+
}catch (ContextErrorException$e) {
221+
// The default PHP error message is not very helpful, as it does not give any information on the current save handler.
222+
// Therefore, we catch this error and trigger a warning with a better error message
223+
$handler =$this->getSaveHandler();
224+
if ($handlerinstanceof SessionHandlerProxy) {
225+
$handler =$handler->getHandler();
226+
}
227+
228+
restore_error_handler();
229+
trigger_error(sprintf(
230+
'session_write_close(): Failed to write session data with %s handler',
231+
get_class($handler)
232+
),E_USER_WARNING);
233+
}
212234

213235
$this->closed =true;
214236
$this->started =false;

‎src/Symfony/Component/HttpFoundation/Session/Storage/Proxy/SessionHandlerProxy.php‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ public function __construct(\SessionHandlerInterface $handler)
3535
$this->saveHandlerName =$this->wrapper ?ini_get('session.save_handler') :'user';
3636
}
3737

38+
/**
39+
* @return \SessionHandlerInterface
40+
*/
41+
publicfunctiongetHandler()
42+
{
43+
return$this->handler;
44+
}
45+
3846
// \SessionHandlerInterface
3947

4048
/**

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp