Skip to content

Commit 05cd1ac

Browse files
bug #49745 [FrameworkBundle] Fix wiring session.handler when handler_id is null (nicolas-grekas)
This PR was merged into the 5.4 branch. Discussion ---------- [FrameworkBundle] Fix wiring session.handler when handler_id is null | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - When the session `handler_id` is null, we currently set the `$handler` argument of the storage/factory services to null, which means to them "create your own handler internally from the native one". This means that the `session.handler` service is "a lie": it's not the real handler used by the storage. It also means that the `%session.save_path%` parameter is lying too, because it is set to `%kernel.cache_dir%/sessions` (by default), while the storage will use `ini_get('session.save_path')` in practice. This issue is 10 years old... #5290 Commits ------- e23be58348 [FrameworkBundle] Fix wiring session.handler when handler_id is null
2 parents 023087f + 44acb50 commit 05cd1ac

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

Session/Storage/Handler/NativeFileSessionHandler.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ public function __construct(string $savePath = null)
4949
throw new \RuntimeException(sprintf('Session Storage was not able to create directory "%s".', $baseDir));
5050
}
5151

52-
ini_set('session.save_path', $savePath);
53-
ini_set('session.save_handler', 'files');
52+
if ($savePath !== \ini_get('session.save_path')) {
53+
ini_set('session.save_path', $savePath);
54+
}
55+
if ('files' !== \ini_get('session.save_handler')) {
56+
ini_set('session.save_handler', 'files');
57+
}
5458
}
5559
}

Session/Storage/NativeSessionStorage.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,10 @@ public function setOptions(array $options)
455455
*/
456456
public function setSaveHandler($saveHandler = null)
457457
{
458-
if (!$saveHandler instanceof AbstractProxy &&
459-
!$saveHandler instanceof \SessionHandlerInterface &&
460-
null !== $saveHandler) {
458+
if (!$saveHandler instanceof AbstractProxy
459+
&& !$saveHandler instanceof \SessionHandlerInterface
460+
&& null !== $saveHandler
461+
) {
461462
throw new \InvalidArgumentException('Must be instance of AbstractProxy; implement \SessionHandlerInterface; or be null.');
462463
}
463464

0 commit comments

Comments
 (0)