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

Appearance settings

Commit 1de8768

Browse filesBrowse files
committed
bug #53057 [HttpKernel] Move @internal from AbstractSessionListener class to its methods and properties (Florian-Merle)
This PR was merged into the 5.4 branch. Discussion ---------- [HttpKernel] Move ``@internal`` from `AbstractSessionListener` class to its methods and properties | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | | License | MIT The `AbstractSessionListener` being marked as internal, its public constant `NO_AUTO_CACHE_CONTROL_HEADER` should not be used while the documentation [states it can](https://symfony.com/doc/current/http_cache.html#http-caching-and-user-sessions). In fact, static analysis tools like psalm says there is an error with code using this constant. ``` ERROR: InternalClass - xxx.php:32:33 - Symfony\Component\HttpKernel\EventListener\AbstractSessionListener is internal to Symfony but called from xxx (see https://psalm.dev/174) $response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER, 'true'); ``` ~~Another solution is to make every method of the `AbstractSessionListener` internal but this means the class could be extended.~~ ~~Also, maybe the class `AbstractSessionListener` should not be internal, but I don't think so.~~ ~~This is why I introduced a new interface that is not internal and allows to not introduce BC.~~ ~~The documentation will need to be updated if this pull request is merged, I'd be happy to do it later.~~ As discussed, I made public/protected properties and methods internal and removed the original internal mark on the class. This solves the issue and allows us to use the `AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER` const just like the documentation says we can. Commits ------- defe229 [HttpKernel] Move `@internal` from AbstractSessionListener class to its methods and properties
2 parents 50ec299 + defe229 commit 1de8768
Copy full SHA for 1de8768

File tree

Expand file treeCollapse file tree

1 file changed

+27
-2
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+27
-2
lines changed

‎src/Symfony/Component/HttpKernel/EventListener/AbstractSessionListener.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/EventListener/AbstractSessionListener.php
+27-2Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@
3636
*
3737
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
3838
* @author Tobias Schultze <http://tobion.de>
39-
*
40-
* @internal
4139
*/
4240
abstract class AbstractSessionListener implements EventSubscriberInterface, ResetInterface
4341
{
4442
public const NO_AUTO_CACHE_CONTROL_HEADER = 'Symfony-Session-NoAutoCacheControl';
4543

44+
45+
/**
46+
* @internal
47+
*/
4648
protected $container;
4749
private $sessionUsageStack = [];
4850
private $debug;
@@ -52,13 +54,19 @@ abstract class AbstractSessionListener implements EventSubscriberInterface, Rese
5254
*/
5355
private $sessionOptions;
5456

57+
/**
58+
* @internal
59+
*/
5560
public function __construct(ContainerInterface $container = null, bool $debug = false, array $sessionOptions = [])
5661
{
5762
$this->container = $container;
5863
$this->debug = $debug;
5964
$this->sessionOptions = $sessionOptions;
6065
}
6166

67+
/**
68+
* @internal
69+
*/
6270
public function onKernelRequest(RequestEvent $event)
6371
{
6472
if (!$event->isMainRequest()) {
@@ -94,6 +102,9 @@ public function onKernelRequest(RequestEvent $event)
94102
$this->sessionUsageStack[] = $session instanceof Session ? $session->getUsageIndex() : 0;
95103
}
96104

105+
/**
106+
* @internal
107+
*/
97108
public function onKernelResponse(ResponseEvent $event)
98109
{
99110
if (!$event->isMainRequest() || (!$this->container->has('initialized_session') && !$event->getRequest()->hasSession())) {
@@ -222,13 +233,19 @@ public function onKernelResponse(ResponseEvent $event)
222233
}
223234
}
224235

236+
/**
237+
* @internal
238+
*/
225239
public function onFinishRequest(FinishRequestEvent $event)
226240
{
227241
if ($event->isMainRequest()) {
228242
array_pop($this->sessionUsageStack);
229243
}
230244
}
231245

246+
/**
247+
* @internal
248+
*/
232249
public function onSessionUsage(): void
233250
{
234251
if (!$this->debug) {
@@ -264,6 +281,9 @@ public function onSessionUsage(): void
264281
throw new UnexpectedSessionUsageException('Session was used while the request was declared stateless.');
265282
}
266283

284+
/**
285+
* @internal
286+
*/
267287
public static function getSubscribedEvents(): array
268288
{
269289
return [
@@ -274,6 +294,9 @@ public static function getSubscribedEvents(): array
274294
];
275295
}
276296

297+
/**
298+
* @internal
299+
*/
277300
public function reset(): void
278301
{
279302
if (\PHP_SESSION_ACTIVE === session_status()) {
@@ -291,6 +314,8 @@ public function reset(): void
291314
/**
292315
* Gets the session object.
293316
*
317+
* @internal
318+
*
294319
* @return SessionInterface|null
295320
*/
296321
abstract protected function getSession();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.