Last active
April 4, 2019 16:30
-
-
Save katakeynii/1be3e2811612e13508cda612ab7d4cc1 to your computer and use it in GitHub Desktop.
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
parameters: | |
app_schema: mon_super_schema | |
services: | |
app_schema_prefixer_subscriber: | |
class: App\EventSubscriber\TableSchemaSubscriber | |
arguments: ['%app_schema%'] | |
tags: | |
- { name: doctrine.event_subscriber } |
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
<?php | |
namespace App\EventSubscriber; | |
use \Doctrine\ORM\Event\LoadClassMetadataEventArgs; | |
use Doctrine\Common\EventSubscriber; | |
class TableSchemaSubscriber implements EventSubscriber | |
{ | |
protected $schemaName = ''; | |
public function __construct($schemaName) | |
{ | |
$this->schemaName = (string) $schemaName; | |
} | |
public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs) | |
{ | |
$classMetadata = $eventArgs->getClassMetadata(); | |
if (!$classMetadata->isInheritanceTypeSingleTable() || $classMetadata->getName() === $classMetadata->rootEntityName) { | |
$classMetadata->setPrimaryTable([ | |
'schema' => $this->schemaName | |
]); | |
} | |
} | |
public function getSubscribedEvents() { | |
return array('loadClassMetadata'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment