8000 [HttpFoundation] inject AbstractSessionHandler in PdoSessionHandlerSc… · symfony/symfony@1e24eba · GitHub
[go: up one dir, main page]

Skip to content

Commit 1e24eba

Browse files
committed
[HttpFoundation] inject AbstractSessionHandler in PdoSessionHandlerSchemaSubscriber
1 parent e480a66 commit 1e24eba

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

src/Symfony/Bridge/Doctrine/SchemaListener/PdoSessionHandlerSchemaSubscriber.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,26 @@
1212
namespace Symfony\Bridge\Doctrine\SchemaListener;
1313

1414
use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs;
15+
use Symfony\Component\HttpFoundation\Session\Storage\Handler\AbstractSessionHandler;
1516
use Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler;
1617

1718
final class PdoSessionHandlerSchemaSubscriber extends AbstractSchemaSubscriber
1819
{
19-
private iterable $pdoSessionHandlers;
20-
2120
/**
22-
* @param iterable<mixed, PdoSessionHandler> $pdoSessionHandlers
21+
* @param AbstractSessionHandler $sessionHandler
2322
*/
24-
public function __construct(iterable $pdoSessionHandlers)
23+
public function __construct(private AbstractSessionHandler $sessionHandler)
2524
{
26-
$this->pdoSessionHandlers = $pdoSessionHandlers;
2725
}
2826

2927
public function postGenerateSchema(GenerateSchemaEventArgs $event): void
3028
{
29+
if (!$this->sessionHandler instanceof PdoSessionHandler) {
30+
return;
31+
}
32+
3133
$connection = $event->getEntityManager()->getConnection();
3234

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

src/Symfony/Bridge/Doctrine/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
}

src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,13 @@ public function __construct(#[\SensitiveParameter] \PDO|string $pdoOrDsn = null,
178178
$this->ttl = $options['ttl'] ?? null;
179179
}
180180

181-
public function configureSchema(Schema $schema, \Closure $isSameDatabase): void
181+
/**
182+
* Adds the Table to the Schema if it doesn't exist.
183+
*/
184+
public function configureSchema(Schema $schema, \Closure $isSameDatabase = null): void
182185
{
186+
$isSameDatabase = is_callable($isSameDatabase) ? $isSameDatabase : static fn () => true;
187+
183188
if ($schema->hasTable($this->table) || !$isSameDatabase($this->getConnection()->exec(...))) {
184189
return;
185190
}

0 commit comments

Comments
 (0)
0