-
-
Save stevelacey/4444247 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
services: | |
application.child1bundle.doctrine.listener.inheritance_mapping: | |
class: Application\BaseBundle\Doctrine\Listener\InheritanceMapping | |
arguments: [ %application.child1bundle.discriminator_mapping% ] | |
tags: | |
- { name: doctrine.event_listener, event: loadClassMetadata } | |
parameters: | |
application.child1bundle.discriminator_mapping: | |
- | |
parent: Application\ParentBundle\Entity\Category | |
child: Application\Child1Bundle\Entity\Category | |
- | |
parent: Application\ParentBundle\Entity\Product | |
child: Application\Child1Bundle\Entity\Product |
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
services: | |
application.child2bundle.doctrine.listener.inheritance_mapping: | |
class: Application\BaseBundle\Doctrine\Listener\InheritanceMapping | |
arguments: [ %application.child2bundle.discriminator_mapping% ] | |
tags: | |
- { name: doctrine.event_listener, event: loadClassMetadata } | |
parameters: | |
application.child2bundle.discriminator_mapping: | |
- | |
parent: Application\ParentBundle\Entity\SomethingElse | |
child: Application\Child2Bundle\Entity\SomethingElse |
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 Application\BaseBundle\Doctrine\Listener; | |
use Doctrine\ORM\Event\LoadClassMetadataEventArgs; | |
class InheritanceMapping | |
{ | |
protected $mappings; | |
public function __construct($mappings) | |
{ | |
$this->mappings = $mappings; | |
} | |
public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs) | |
{ | |
if (empty($this->mappings)) { | |
return; | |
} | |
$metadata = $eventArgs->getClassMetaData(); | |
$class = $metadata->getName(); | |
foreach ($this->mappings as $map) { | |
if ($class == $map['parent']) { | |
$metadata->addDiscriminatorMapClass($map['child'], $map['child']); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment