Skip to content

[HttpFoundation] inject SessionHandler in PdoSessionHandlerSchemaSubscriber #49097

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,24 @@

final class PdoSessionHandlerSchemaSubscriber extends AbstractSchemaSubscriber
{
private iterable $pdoSessionHandlers;
private PdoSessionHandler $sessionHandler;

/**
* @param iterable<mixed, PdoSessionHandler> $pdoSessionHandlers
*/
public function __construct(iterable $pdoSessionHandlers)
public function __construct(\SessionHandlerInterface $sessionHandler)
{
$this->pdoSessionHandlers = $pdoSessionHandlers;
if ($sessionHandler instanceof PdoSessionHandler) {
$this->sessionHandler = $sessionHandler;
}
}

public function getSubscribedEvents(): array
{
return isset($this->sessionHandler) ? parent::getSubscribedEvents() : [];
}

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

foreach ($this->pdoSessionHandlers as $pdoSessionHandler) {
$pdoSessionHandler->configureSchema($event->getSchema(), $this->getIsSameDatabaseChecker($connection));
}
$this->sessionHandler->configureSchema($event->getSchema(), $this->getIsSameDatabaseChecker($connection));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function testPostGenerateSchemaPdo()
->method('configureSchema')
->with($schema, fn () => true);

$subscriber = new PdoSessionHandlerSchemaSubscriber([$pdoSessionHandler]);
$subscriber = new PdoSessionHandlerSchemaSubscriber($pdoSessionHandler);
$subscriber->postGenerateSchema($event);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,12 @@ public function __construct(#[\SensitiveParameter] \PDO|string $pdoOrDsn = null,
$this->ttl = $options['ttl'] ?? null;
}

public function configureSchema(Schema $schema, \Closure $isSameDatabase): void
/**
* Adds the Table to the Schema if it doesn't exist.
*/
public function configureSchema(Schema $schema, \Closure $isSameDatabase = null): void
{
if ($schema->hasTable($this->table) || !$isSameDatabase($this->getConnection()->exec(...))) {
if ($schema->hasTable($this->table) || ($isSameDatabase && !$isSameDatabase($this->getConnection()->exec(...)))) {
return;
}

Expand Down