Skip to content

Instantly share code, notes, and snippets.

@katakeynii
Last active April 4, 2019 16:30
Show Gist options
  • Save katakeynii/1be3e2811612e13508cda612ab7d4cc1 to your computer and use it in GitHub Desktop.
Save katakeynii/1be3e2811612e13508cda612ab7d4cc1 to your computer and use it in GitHub Desktop.
parameters:
app_schema: mon_super_schema
services:
app_schema_prefixer_subscriber:
class: App\EventSubscriber\TableSchemaSubscriber
arguments: ['%app_schema%']
tags:
- { name: doctrine.event_subscriber }
<?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