Skip to content

Commit ab0ede0

Browse files
committed
IBX-8811: Rebranded SiteAccess session prefix
1 parent 04b97ef commit ab0ede0

File tree

7 files changed

+60
-150
lines changed

7 files changed

+60
-150
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -2160,11 +2160,6 @@ parameters:
21602160
count: 1
21612161
path: src/bundle/Core/EventListener/SessionInitByPostListener.php
21622162

2163-
-
2164-
message: "#^Method Ibexa\\\\Bundle\\\\Core\\\\EventListener\\\\SessionSetDynamicNameListener\\:\\:onSiteAccessMatch\\(\\) has no return type specified\\.$#"
2165-
count: 1
2166-
path: src/bundle/Core/EventListener/SessionSetDynamicNameListener.php
2167-
21682163
-
21692164
message: "#^Method Ibexa\\\\Bundle\\\\Core\\\\EventListener\\\\SiteAccessListener\\:\\:generateViewParametersArray\\(\\) return type has no value type specified in iterable type array\\.$#"
21702165
count: 1
@@ -24770,46 +24765,6 @@ parameters:
2477024765
count: 2
2477124766
path: tests/bundle/Core/EventListener/RoutingListenerTest.php
2477224767

24773-
-
24774-
message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Core\\\\EventListener\\\\SessionInitByPostListenerTest\\:\\:testGetSubscribedEvents\\(\\) has no return type specified\\.$#"
24775-
count: 1
24776-
path: tests/bundle/Core/EventListener/SessionInitByPostListenerTest.php
24777-
24778-
-
24779-
message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Core\\\\EventListener\\\\SessionInitByPostListenerTest\\:\\:testOnSiteAccessMatchNewSessionName\\(\\) has no return type specified\\.$#"
24780-
count: 1
24781-
path: tests/bundle/Core/EventListener/SessionInitByPostListenerTest.php
24782-
24783-
-
24784-
message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Core\\\\EventListener\\\\SessionInitByPostListenerTest\\:\\:testOnSiteAccessMatchNoSessionService\\(\\) has no return type specified\\.$#"
24785-
count: 1
24786-
path: tests/bundle/Core/EventListener/SessionInitByPostListenerTest.php
24787-
24788-
-
24789-
message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Core\\\\EventListener\\\\SessionInitByPostListenerTest\\:\\:testOnSiteAccessMatchRequestNoSessionName\\(\\) has no return type specified\\.$#"
24790-
count: 1
24791-
path: tests/bundle/Core/EventListener/SessionInitByPostListenerTest.php
24792-
24793-
-
24794-
message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Core\\\\EventListener\\\\SessionInitByPostListenerTest\\:\\:testOnSiteAccessMatchSubRequest\\(\\) has no return type specified\\.$#"
24795-
count: 1
24796-
path: tests/bundle/Core/EventListener/SessionInitByPostListenerTest.php
24797-
24798-
-
24799-
message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Core\\\\EventListener\\\\SessionSetDynamicNameListenerTest\\:\\:onSiteAccessMatchProvider\\(\\) has no return type specified\\.$#"
24800-
count: 1
24801-
path: tests/bundle/Core/EventListener/SessionSetDynamicNameListenerTest.php
24802-
24803-
-
24804-
message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Core\\\\EventListener\\\\SessionSetDynamicNameListenerTest\\:\\:testGetSubscribedEvents\\(\\) has no return type specified\\.$#"
24805-
count: 1
24806-
path: tests/bundle/Core/EventListener/SessionSetDynamicNameListenerTest.php
24807-
24808-
-
24809-
message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Core\\\\EventListener\\\\SessionSetDynamicNameListenerTest\\:\\:testOnSiteAccessMatch\\(\\) has no return type specified\\.$#"
24810-
count: 1
24811-
path: tests/bundle/Core/EventListener/SessionSetDynamicNameListenerTest.php
24812-
2481324768
-
2481424769
message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Core\\\\EventListener\\\\SessionSetDynamicNameListenerTest\\:\\:testOnSiteAccessMatch\\(\\) has parameter \\$configuredSessionStorageOptions with no type specified\\.$#"
2481524770
count: 1
@@ -24820,36 +24775,6 @@ parameters:
2482024775
count: 1
2482124776
path: tests/bundle/Core/EventListener/SessionSetDynamicNameListenerTest.php
2482224777

24823-
-
24824-
message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Core\\\\EventListener\\\\SessionSetDynamicNameListenerTest\\:\\:testOnSiteAccessMatchNoConfiguredSessionName\\(\\) has no return type specified\\.$#"
24825-
count: 1
24826-
path: tests/bundle/Core/EventListener/SessionSetDynamicNameListenerTest.php
24827-
24828-
-
24829-
message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Core\\\\EventListener\\\\SessionSetDynamicNameListenerTest\\:\\:testOnSiteAccessMatchNoSession\\(\\) has no return type specified\\.$#"
24830-
count: 1
24831-
path: tests/bundle/Core/EventListener/SessionSetDynamicNameListenerTest.php
24832-
24833-
-
24834-
message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Core\\\\EventListener\\\\SessionSetDynamicNameListenerTest\\:\\:testOnSiteAccessMatchNonNativeSessionStorage\\(\\) has no return type specified\\.$#"
24835-
count: 1
24836-
path: tests/bundle/Core/EventListener/SessionSetDynamicNameListenerTest.php
24837-
24838-
-
24839-
message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Core\\\\EventListener\\\\SessionSetDynamicNameListenerTest\\:\\:testOnSiteAccessMatchSubRequest\\(\\) has no return type specified\\.$#"
24840-
count: 1
24841-
path: tests/bundle/Core/EventListener/SessionSetDynamicNameListenerTest.php
24842-
24843-
-
24844-
message: "#^Parameter \\#1 \\$configResolver of class Ibexa\\\\Bundle\\\\Core\\\\EventListener\\\\SessionSetDynamicNameListener constructor expects Ibexa\\\\Contracts\\\\Core\\\\SiteAccess\\\\ConfigResolverInterface, PHPUnit\\\\Framework\\\\MockObject\\\\MockObject given\\.$#"
24845-
count: 6
24846-
path: tests/bundle/Core/EventListener/SessionSetDynamicNameListenerTest.php
24847-
24848-
-
24849-
message: "#^Parameter \\#2 \\$sessionStorageFactory of class Ibexa\\\\Bundle\\\\Core\\\\EventListener\\\\SessionSetDynamicNameListener constructor expects Symfony\\\\Component\\\\HttpFoundation\\\\Session\\\\Storage\\\\SessionStorageFactoryInterface, PHPUnit\\\\Framework\\\\MockObject\\\\MockObject given\\.$#"
24850-
count: 5
24851-
path: tests/bundle/Core/EventListener/SessionSetDynamicNameListenerTest.php
24852-
2485324778
-
2485424779
message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Core\\\\EventListener\\\\SiteAccessListenerTest\\:\\:siteAccessMatchProvider\\(\\) has no return type specified\\.$#"
2485524780
count: 1
@@ -45795,16 +45720,6 @@ parameters:
4579545720
count: 1
4579645721
path: tests/lib/Limitation/SubtreeLimitationTypeTest.php
4579745722

45798-
-
45799-
message: "#^Method Ibexa\\\\Tests\\\\Core\\\\MVC\\\\Symfony\\\\Component\\\\Serializer\\\\SimplifiedRequestNormalizerTest\\:\\:testNormalize\\(\\) has no return type specified\\.$#"
45800-
count: 1
45801-
path: tests/lib/MVC/Symfony/Component/Serializer/SimplifiedRequestNormalizerTest.php
45802-
45803-
-
45804-
message: "#^Method Ibexa\\\\Tests\\\\Core\\\\MVC\\\\Symfony\\\\Component\\\\Serializer\\\\SimplifiedRequestNormalizerTest\\:\\:testSupportsNormalization\\(\\) has no return type specified\\.$#"
45805-
count: 1
45806-
path: tests/lib/MVC/Symfony/Component/Serializer/SimplifiedRequestNormalizerTest.php
45807-
4580845723
-
4580945724
message: "#^Method Ibexa\\\\Tests\\\\Core\\\\MVC\\\\Symfony\\\\Component\\\\Serializer\\\\Stubs\\\\CompoundStub\\:\\:__construct\\(\\) has parameter \\$subMatchers with no value type specified in iterable type array\\.$#"
4581045725
count: 1

src/bundle/Core/DependencyInjection/Configuration/Parser/Common.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function addSemanticConfig(NodeBuilder $nodeBuilder)
8989
->children()
9090
->scalarNode('name')
9191
->info('The session name. If you want a session name per siteaccess, use "{siteaccess_hash}" token. Will override default session name from framework.session.name')
92-
->example('eZSESSID{siteaccess_hash}')
92+
->example('IBX_SESSION_ID{siteaccess_hash}')
9393
->end()
9494
->scalarNode('cookie_lifetime')->end()
9595
->scalarNode('cookie_path')->end()

src/bundle/Core/EventListener/SessionSetDynamicNameListener.php

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* @copyright Copyright (C) Ibexa AS. All rights reserved.
55
* @license For full copyright and license information view LICENSE file distributed with this source code.
66
*/
7+
declare(strict_types=1);
78

89
namespace Ibexa\Bundle\Core\EventListener;
910

@@ -21,37 +22,26 @@
2122
*
2223
* Allows to set a dynamic session name based on the siteaccess name.
2324
*/
24-
class SessionSetDynamicNameListener implements EventSubscriberInterface
25+
final readonly class SessionSetDynamicNameListener implements EventSubscriberInterface
2526
{
26-
public const MARKER = '{siteaccess_hash}';
27+
public const string MARKER = '{siteaccess_hash}';
2728

28-
/**
29-
* Prefix for session name.
30-
*/
31-
public const SESSION_NAME_PREFIX = 'eZSESSID';
32-
33-
/** @var \Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface */
34-
private $configResolver;
35-
36-
/** @var \Symfony\Component\HttpFoundation\Session\Storage\SessionStorageFactoryInterface */
37-
private $sessionStorageFactory;
29+
public const string SESSION_NAME_PREFIX = 'IBX_SESSION_ID';
3830

3931
public function __construct(
40-
ConfigResolverInterface $configResolver,
41-
SessionStorageFactoryInterface $sessionStorageFactory
32+
private ConfigResolverInterface $configResolver,
33+
private SessionStorageFactoryInterface $sessionStorageFactory
4234
) {
43-
$this->configResolver = $configResolver;
44-
$this->sessionStorageFactory = $sessionStorageFactory;
4535
}
4636

47-
public static function getSubscribedEvents()
37+
public static function getSubscribedEvents(): array
4838
{
4939
return [
5040
MVCEvents::SITEACCESS => ['onSiteAccessMatch', 250],
5141
];
5242
}
5343

54-
public function onSiteAccessMatch(PostSiteAccessMatchEvent $event)
44+
public function onSiteAccessMatch(PostSiteAccessMatchEvent $event): void
5545
{
5646
$request = $event->getRequest();
5747
$session = $request->hasSession() ? $request->getSession() : null;
@@ -69,26 +59,20 @@ public function onSiteAccessMatch(PostSiteAccessMatchEvent $event)
6959
}
7060

7161
$sessionOptions = (array)$this->configResolver->getParameter('session');
72-
$sessionName = isset($sessionOptions['name']) ? $sessionOptions['name'] : $session->getName();
62+
$sessionName = $sessionOptions['name'] ?? $session->getName();
7363
$sessionOptions['name'] = $this->getSessionName($sessionName, $event->getSiteAccess());
7464
$sessionStorage->setOptions($sessionOptions);
7565
}
7666

77-
/**
78-
* @param string $sessionName
79-
* @param \Ibexa\Core\MVC\Symfony\SiteAccess $siteAccess
80-
*
81-
* @return string
82-
*/
83-
private function getSessionName($sessionName, SiteAccess $siteAccess)
67+
private function getSessionName(string $sessionName, SiteAccess $siteAccess): string
8468
{
8569
// Add session prefix if needed.
86-
if (strpos($sessionName, static::SESSION_NAME_PREFIX) !== 0) {
87-
$sessionName = static::SESSION_NAME_PREFIX . '_' . $sessionName;
70+
if (!str_starts_with($sessionName, self::SESSION_NAME_PREFIX)) {
71+
$sessionName = self::SESSION_NAME_PREFIX . '_' . $sessionName;
8872
}
8973

9074
// Check if uniqueness marker is present. If so, session name will be unique for current siteaccess.
91-
if (strpos($sessionName, self::MARKER) !== false) {
75+
if (str_contains($sessionName, self::MARKER)) {
9276
$sessionName = str_replace(self::MARKER, md5($siteAccess->name), $sessionName);
9377
}
9478

src/bundle/Core/Resources/config/default_settings.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ parameters:
8383
# Common settings
8484
ibexa.repositories: {}
8585
ibexa.site_access.config.default.repository: ~
86-
ibexa.session_name.default: "eZSESSID{siteaccess_hash}"
86+
ibexa.session_name.default: "IBX_SESSION_ID{siteaccess_hash}"
8787
ibexa.site_access.config.default.session_name: '%ibexa.session_name.default%' # Using "{siteaccess_hash}" in session name makes it unique per siteaccess
8888
ibexa.site_access.config.default.session: { name: '%ibexa.session_name.default%' } # Session options that will override options from framework
8989
ibexa.site_access.config.default.url_alias_router: true # Use UrlAliasRouter by default

tests/bundle/Core/EventListener/SessionInitByPostListenerTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* @copyright Copyright (C) Ibexa AS. All rights reserved.
55
* @license For full copyright and license information view LICENSE file distributed with this source code.
66
*/
7+
declare(strict_types=1);
78

89
namespace Ibexa\Tests\Bundle\Core\EventListener;
910

@@ -18,18 +19,17 @@
1819
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
1920
use Symfony\Component\HttpKernel\HttpKernelInterface;
2021

21-
class SessionInitByPostListenerTest extends TestCase
22+
final class SessionInitByPostListenerTest extends TestCase
2223
{
23-
/** @var \Ibexa\Bundle\Core\EventListener\SessionInitByPostListener */
24-
private $listener;
24+
private SessionInitByPostListener $listener;
2525

2626
protected function setUp(): void
2727
{
2828
parent::setUp();
2929
$this->listener = new SessionInitByPostListener();
3030
}
3131

32-
public function testGetSubscribedEvents()
32+
public function testGetSubscribedEvents(): void
3333
{
3434
self::assertSame(
3535
[
@@ -39,7 +39,7 @@ public function testGetSubscribedEvents()
3939
);
4040
}
4141

42-
public function testOnSiteAccessMatchNoSessionService()
42+
public function testOnSiteAccessMatchNoSessionService(): void
4343
{
4444
$request = new Request();
4545
$request->setSession(new Session(new MockArraySessionStorage()));
@@ -49,7 +49,7 @@ public function testOnSiteAccessMatchNoSessionService()
4949
self::assertNull($listener->onSiteAccessMatch($event));
5050
}
5151

52-
public function testOnSiteAccessMatchSubRequest()
52+
public function testOnSiteAccessMatchSubRequest(): void
5353
{
5454
$session = $this->createMock(SessionInterface::class);
5555
$session
@@ -63,9 +63,9 @@ public function testOnSiteAccessMatchSubRequest()
6363
$this->listener->onSiteAccessMatch($event);
6464
}
6565

66-
public function testOnSiteAccessMatchRequestNoSessionName()
66+
public function testOnSiteAccessMatchRequestNoSessionName(): void
6767
{
68-
$sessionName = 'eZSESSID';
68+
$sessionName = 'IBX_SESSION_ID';
6969

7070
$session = $this->createMock(SessionInterface::class);
7171
$session
@@ -90,9 +90,9 @@ public function testOnSiteAccessMatchRequestNoSessionName()
9090
$this->listener->onSiteAccessMatch($event);
9191
}
9292

93-
public function testOnSiteAccessMatchNewSessionName()
93+
public function testOnSiteAccessMatchNewSessionName(): void
9494
{
95-
$sessionName = 'eZSESSID';
95+
$sessionName = 'IBX_SESSION_ID';
9696
$sessionId = 'foobar123';
9797
$session = $this->createMock(SessionInterface::class);
9898

0 commit comments

Comments
 (0)