Skip to content

Commit 9b4fa50

Browse files
alli83nicolas-grekas
authored andcommitted
[HttpFoundation] inject SessionHandler in PdoSessionHandlerSchemaSubscriber
1 parent e998b07 commit 9b4fa50

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

SchemaListener/PdoSessionHandlerSchemaSubscriber.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,24 @@
1616

1717
final class PdoSessionHandlerSchemaSubscriber extends AbstractSchemaSubscriber
1818
{
19-
private iterable $pdoSessionHandlers;
19+
private PdoSessionHandler $sessionHandler;
2020

21-
/**
22-
* @param iterable<mixed, PdoSessionHandler> $pdoSessionHandlers
23-
*/
24-
public function __construct(iterable $pdoSessionHandlers)
21+
public function __construct(\SessionHandlerInterface $sessionHandler)
2522
{
26-
$this->pdoSessionHandlers = $pdoSessionHandlers;
23+
if ($sessionHandler instanceof PdoSessionHandler) {
24+
$this->sessionHandler = $sessionHandler;
25+
}
26+
}
27+
28+
public function getSubscribedEvents(): array
29+
{
30+
return isset($this->sessionHandler) ? parent::getSubscribedEvents() : [];
2731
}
2832

2933
public function postGenerateSchema(GenerateSchemaEventArgs $event): void
3034
{
3135
$connection = $event->getEntityManager()->getConnection();
3236

33-
foreach ($this->pdoSessionHandlers as $pdoSessionHandler) {
34-
$pdoSessionHandler->configureSchema($event->getSchema(), $this->getIsSameDatabaseChecker($connection));
35-
}
37+
$this->sessionHandler->configureSchema($event->getSchema(), $this->getIsSameDatabaseChecker($connection));
3638
}
3739
}

Tests/SchemaListener/PdoSessionHandlerSchemaSubscriberTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function testPostGenerateSchemaPdo()
3636
->method('configureSchema')
3737
->with($schema, fn () => true);
3838

39-
$subscriber = new PdoSessionHandlerSchemaSubscriber([$pdoSessionHandler]);
39+
$subscriber = new PdoSessionHandlerSchemaSubscriber($pdoSessionHandler);
4040
$subscriber->postGenerateSchema($event);
4141
}
4242
}

0 commit comments

Comments
 (0)