Skip to content

Commit 6e89845

Browse files
konradobozaalongosz
authored andcommitted
IBX-8811: Rebranded SiteAccess session prefix
1 parent 96f656c commit 6e89845

File tree

7 files changed

+59
-149
lines changed

7 files changed

+59
-149
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -2140,11 +2140,6 @@ parameters:
21402140
count: 1
21412141
path: src/bundle/Core/EventListener/SessionInitByPostListener.php
21422142

2143-
-
2144-
message: "#^Method Ibexa\\\\Bundle\\\\Core\\\\EventListener\\\\SessionSetDynamicNameListener\\:\\:onSiteAccessMatch\\(\\) has no return type specified\\.$#"
2145-
count: 1
2146-
path: src/bundle/Core/EventListener/SessionSetDynamicNameListener.php
2147-
21482143
-
21492144
message: "#^Method Ibexa\\\\Bundle\\\\Core\\\\EventListener\\\\SiteAccessListener\\:\\:generateViewParametersArray\\(\\) return type has no value type specified in iterable type array\\.$#"
21502145
count: 1
@@ -24425,46 +24420,6 @@ parameters:
2442524420
count: 2
2442624421
path: tests/bundle/Core/EventListener/RoutingListenerTest.php
2442724422

24428-
-
24429-
message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Core\\\\EventListener\\\\SessionInitByPostListenerTest\\:\\:testGetSubscribedEvents\\(\\) has no return type specified\\.$#"
24430-
count: 1
24431-
path: tests/bundle/Core/EventListener/SessionInitByPostListenerTest.php
24432-
24433-
-
24434-
message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Core\\\\EventListener\\\\SessionInitByPostListenerTest\\:\\:testOnSiteAccessMatchNewSessionName\\(\\) has no return type specified\\.$#"
24435-
count: 1
24436-
path: tests/bundle/Core/EventListener/SessionInitByPostListenerTest.php
24437-
24438-
-
24439-
message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Core\\\\EventListener\\\\SessionInitByPostListenerTest\\:\\:testOnSiteAccessMatchNoSessionService\\(\\) has no return type specified\\.$#"
24440-
count: 1
24441-
path: tests/bundle/Core/EventListener/SessionInitByPostListenerTest.php
24442-
24443-
-
24444-
message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Core\\\\EventListener\\\\SessionInitByPostListenerTest\\:\\:testOnSiteAccessMatchRequestNoSessionName\\(\\) has no return type specified\\.$#"
24445-
count: 1
24446-
path: tests/bundle/Core/EventListener/SessionInitByPostListenerTest.php
24447-
24448-
-
24449-
message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Core\\\\EventListener\\\\SessionInitByPostListenerTest\\:\\:testOnSiteAccessMatchSubRequest\\(\\) has no return type specified\\.$#"
24450-
count: 1
24451-
path: tests/bundle/Core/EventListener/SessionInitByPostListenerTest.php
24452-
24453-
-
24454-
message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Core\\\\EventListener\\\\SessionSetDynamicNameListenerTest\\:\\:onSiteAccessMatchProvider\\(\\) has no return type specified\\.$#"
24455-
count: 1
24456-
path: tests/bundle/Core/EventListener/SessionSetDynamicNameListenerTest.php
24457-
24458-
-
24459-
message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Core\\\\EventListener\\\\SessionSetDynamicNameListenerTest\\:\\:testGetSubscribedEvents\\(\\) has no return type specified\\.$#"
24460-
count: 1
24461-
path: tests/bundle/Core/EventListener/SessionSetDynamicNameListenerTest.php
24462-
24463-
-
24464-
message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Core\\\\EventListener\\\\SessionSetDynamicNameListenerTest\\:\\:testOnSiteAccessMatch\\(\\) has no return type specified\\.$#"
24465-
count: 1
24466-
path: tests/bundle/Core/EventListener/SessionSetDynamicNameListenerTest.php
24467-
2446824423
-
2446924424
message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Core\\\\EventListener\\\\SessionSetDynamicNameListenerTest\\:\\:testOnSiteAccessMatch\\(\\) has parameter \\$configuredSessionStorageOptions with no type specified\\.$#"
2447024425
count: 1
@@ -24475,36 +24430,6 @@ parameters:
2447524430
count: 1
2447624431
path: tests/bundle/Core/EventListener/SessionSetDynamicNameListenerTest.php
2447724432

24478-
-
24479-
message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Core\\\\EventListener\\\\SessionSetDynamicNameListenerTest\\:\\:testOnSiteAccessMatchNoConfiguredSessionName\\(\\) has no return type specified\\.$#"
24480-
count: 1
24481-
path: tests/bundle/Core/EventListener/SessionSetDynamicNameListenerTest.php
24482-
24483-
-
24484-
message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Core\\\\EventListener\\\\SessionSetDynamicNameListenerTest\\:\\:testOnSiteAccessMatchNoSession\\(\\) has no return type specified\\.$#"
24485-
count: 1
24486-
path: tests/bundle/Core/EventListener/SessionSetDynamicNameListenerTest.php
24487-
24488-
-
24489-
message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Core\\\\EventListener\\\\SessionSetDynamicNameListenerTest\\:\\:testOnSiteAccessMatchNonNativeSessionStorage\\(\\) has no return type specified\\.$#"
24490-
count: 1
24491-
path: tests/bundle/Core/EventListener/SessionSetDynamicNameListenerTest.php
24492-
24493-
-
24494-
message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Core\\\\EventListener\\\\SessionSetDynamicNameListenerTest\\:\\:testOnSiteAccessMatchSubRequest\\(\\) has no return type specified\\.$#"
24495-
count: 1
24496-
path: tests/bundle/Core/EventListener/SessionSetDynamicNameListenerTest.php
24497-
24498-
-
24499-
message: "#^Parameter \\#1 \\$configResolver of class Ibexa\\\\Bundle\\\\Core\\\\EventListener\\\\SessionSetDynamicNameListener constructor expects Ibexa\\\\Contracts\\\\Core\\\\SiteAccess\\\\ConfigResolverInterface, PHPUnit\\\\Framework\\\\MockObject\\\\MockObject given\\.$#"
24500-
count: 6
24501-
path: tests/bundle/Core/EventListener/SessionSetDynamicNameListenerTest.php
24502-
24503-
-
24504-
message: "#^Parameter \\#2 \\$sessionStorageFactory of class Ibexa\\\\Bundle\\\\Core\\\\EventListener\\\\SessionSetDynamicNameListener constructor expects Symfony\\\\Component\\\\HttpFoundation\\\\Session\\\\Storage\\\\SessionStorageFactoryInterface, PHPUnit\\\\Framework\\\\MockObject\\\\MockObject given\\.$#"
24505-
count: 5
24506-
path: tests/bundle/Core/EventListener/SessionSetDynamicNameListenerTest.php
24507-
2450824433
-
2450924434
message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Core\\\\EventListener\\\\SiteAccessListenerTest\\:\\:siteAccessMatchProvider\\(\\) has no return type specified\\.$#"
2451024435
count: 1
@@ -44685,16 +44610,6 @@ parameters:
4468544610
count: 1
4468644611
path: tests/lib/Limitation/SubtreeLimitationTypeTest.php
4468744612

44688-
-
44689-
message: "#^Method Ibexa\\\\Tests\\\\Core\\\\MVC\\\\Symfony\\\\Component\\\\Serializer\\\\SimplifiedRequestNormalizerTest\\:\\:testNormalize\\(\\) has no return type specified\\.$#"
44690-
count: 1
44691-
path: tests/lib/MVC/Symfony/Component/Serializer/SimplifiedRequestNormalizerTest.php
44692-
44693-
-
44694-
message: "#^Method Ibexa\\\\Tests\\\\Core\\\\MVC\\\\Symfony\\\\Component\\\\Serializer\\\\SimplifiedRequestNormalizerTest\\:\\:testSupportsNormalization\\(\\) has no return type specified\\.$#"
44695-
count: 1
44696-
path: tests/lib/MVC/Symfony/Component/Serializer/SimplifiedRequestNormalizerTest.php
44697-
4469844613
-
4469944614
message: "#^Method Ibexa\\\\Tests\\\\Core\\\\MVC\\\\Symfony\\\\Component\\\\Serializer\\\\Stubs\\\\CompoundStub\\:\\:__construct\\(\\) has parameter \\$subMatchers with no value type specified in iterable type array\\.$#"
4470044615
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: 12 additions & 28 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,27 +22,16 @@
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

4737
public static function getSubscribedEvents(): array
@@ -51,7 +41,7 @@ public static function getSubscribedEvents(): array
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)