-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Http-Foundation][Session]feat: create automatically session table wi…
…th pdo connection
- Loading branch information
Showing
3 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/Symfony/Bridge/Doctrine/SchemaListener/PdoSessionHandlerSchemaSubscriber.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace Symfony\Bridge\Doctrine\SchemaListener; | ||
|
||
use Doctrine\Common\EventSubscriber; | ||
use Doctrine\DBAL\Exception; | ||
use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs; | ||
use Doctrine\ORM\Tools\ToolEvents; | ||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler; | ||
|
||
class PdoSessionHandlerSchemaSubscriber implements EventSubscriber | ||
{ | ||
private PdoSessionHandler $pdoSessionHandler; | ||
|
||
/** | ||
* @param PdoSessionHandler $pdoSessionHandler | ||
*/ | ||
public function __construct(PdoSessionHandler $pdoSessionHandler) | ||
{ | ||
$this->pdoSessionHandler = $pdoSessionHandler; | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
public function postGenerateSchema(GenerateSchemaEventArgs $event): void | ||
{ | ||
$dbalConnection = $event->getEntityManager()->getConnection(); | ||
$this->pdoSessionHandler->configureSchema($event->getSchema(), $dbalConnection); | ||
} | ||
|
||
public function getSubscribedEvents(): array | ||
{ | ||
$subscribedEvents = []; | ||
|
||
if (class_exists(ToolEvents::class)) { | ||
$subscribedEvents[] = ToolEvents::postGenerateSchema; | ||
} | ||
|
||
return $subscribedEvents; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/Symfony/Bridge/Doctrine/Tests/SchemaListener/PdoSessionHandlerSchemaSubscriberTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace Symfony\Bridge\Doctrine\Tests\SchemaListener; | ||
|
||
use Doctrine\DBAL\Connection; | ||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Bridge\Doctrine\SchemaListener\PdoSessionHandlerSchemaSubscriber; | ||
use Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler; | ||
|
||
class PdoSessionHandlerSchemaSubscriberTest extends TestCase | ||
{ | ||
public function testPostGenerateSchemaPdo() | ||
{ | ||
$schema = new Schema(); | ||
$dbalConnection = $this->createMock(Connection::class); | ||
$entityManager = $this->createMock(EntityManagerInterface::class); | ||
$entityManager->expects($this->once()) | ||
->method('getConnection') | ||
->willReturn($dbalConnection); | ||
$event = new GenerateSchemaEventArgs($entityManager, $schema); | ||
|
||
$pdoSessionHandler = $this->createMock(PdoSessionHandler::class); | ||
$pdoSessionHandler->expects($this->once()) | ||
->method('configureSchema') | ||
->with($schema, $dbalConnection); | ||
|
||
$subscriber = new PdoSessionHandlerSchemaSubscriber($pdoSessionHandler); | ||
$subscriber->postGenerateSchema($event); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters