-
-
Save doctrinebot/a0e43b380ba6b4bf229e to your computer and use it in GitHub Desktop.
Attachments to Doctrine Jira Issue DDC-383 - https://github.com/doctrine/doctrine2/issues/4678
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 My\Doctrine; | |
use Doctrine\ORM\Tools\Export\Driver\YamlExporter, | |
Doctrine\ORM\Mapping\ClassMetadataInfo; | |
/** | |
* Modified yaml export driver | |
*/ | |
class YamlExportDriver extends YamlExporter | |
{ | |
/** | |
* Base namespace to append | |
* @var string | |
*/ | |
protected $classNamespace; | |
/** | |
* {@inheritDoc} | |
*/ | |
public function __construct($dir = null) | |
{ | |
parent::__construct($dir); | |
$this->classNamespace = 'My\Namespace\Entity\\'; | |
} | |
/** | |
* Set the array of ClassMetadataInfo instances to export | |
* | |
* @param array $metadata | |
* @return void | |
*/ | |
public function setMetadata(array $metadata) | |
{ | |
$this->_metadata = $metadata; | |
/* @var $metadata ClassMetadataInfo */ | |
foreach ($this->_metadata as &$metadata) { | |
$metadata->name = $this->classNamespace . $metadata->name; | |
foreach ($metadata->associationMappings as &$associationMapping) { | |
/* @var $associationMapping \Doctrine\ORM\Mapping\AssociationMapping */ | |
$associationMapping->targetEntityName = $this->classNamespace . $associationMapping->targetEntityName; | |
$associationMapping->sourceEntityName = $this->classNamespace . $associationMapping->sourceEntityName; | |
foreach ($associationMapping->joinColumnFieldNames as $joinColumnFieldName) { | |
$fieldName = $metadata->fieldNames[$joinColumnFieldName]; | |
unset($metadata->fieldMappings[$fieldName]); | |
unset($metadata->fieldNames[$joinColumnFieldName]); | |
unset($metadata->columnNames[$fieldName]); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment