[DoctrineBundle] made Doctrine metadata configuration easier
You can now configure your Doctrine metadata in one single file named 'doctrine': Resources/config/doctrine.orm.dcm.yml Resources/config/doctirne.orm.dcm.xml You can still use one file per entity, but the directory has changed (see the UPDATE file)
This commit is contained in:
parent
ec226cd4bc
commit
b7c8442068
14
UPDATE.md
14
UPDATE.md
@ -9,6 +9,20 @@ timeline closely anyway.
|
||||
beta1 to beta2
|
||||
--------------
|
||||
|
||||
* The Doctrine metadata files has moved from
|
||||
``Resources/config/doctrine/metadata/orm/`` to ``Resources/config/`` and the
|
||||
extension from ``.dcm.yml`` to ``.orm.dcm.yml``
|
||||
|
||||
Before:
|
||||
|
||||
Resources/config/doctrine/metadata/orm/Bundle.Entity.dcm.xml
|
||||
Resources/config/doctrine/metadata/orm/Bundle.Entity.dcm.yml
|
||||
|
||||
After:
|
||||
|
||||
Resources/config/Bundle.Entity.orm.dcm.xml
|
||||
Resources/config/Bundle.Entity.orm.dcm.yml
|
||||
|
||||
* With the introduction of a new Doctrine Registry class, the following
|
||||
parameters have been removed (replaced by methods on the `doctrine`
|
||||
service):
|
||||
|
@ -263,11 +263,11 @@ abstract class AbstractDoctrineExtension extends Extension
|
||||
}
|
||||
$container->addResource(new FileResource($resource));
|
||||
|
||||
if (($files = glob($dir.'/'.$configPath.'/*.xml')) && count($files)) {
|
||||
if (($files = glob($dir.'/'.$configPath.'/*.orm.dcm.xml')) && count($files)) {
|
||||
return 'xml';
|
||||
} elseif (($files = glob($dir.'/'.$configPath.'/*.yml')) && count($files)) {
|
||||
} elseif (($files = glob($dir.'/'.$configPath.'/*.orm.dcm.yml')) && count($files)) {
|
||||
return 'yml';
|
||||
} elseif (($files = glob($dir.'/'.$configPath.'/*.php')) && count($files)) {
|
||||
} elseif (($files = glob($dir.'/'.$configPath.'/*.orm.dcm.php')) && count($files)) {
|
||||
return 'php';
|
||||
}
|
||||
|
||||
|
@ -103,7 +103,7 @@ EOT
|
||||
$mappingPath = $mappingCode = false;
|
||||
} else {
|
||||
$mappingType = 'yaml' == $mappingType ? 'yml' : $mappingType;
|
||||
$mappingPath = $bundle->getPath().'/Resources/config/doctrine/metadata/orm/'.str_replace('\\', '.', $fullEntityClassName).'.dcm.'.$mappingType;
|
||||
$mappingPath = $bundle->getPath().'/Resources/config/'.str_replace('\\', '.', $fullEntityClassName).'.orm.dcm.'.$mappingType;
|
||||
$mappingCode = $exporter->exportClassMetadata($class);
|
||||
|
||||
$entityGenerator = $this->getEntityGenerator();
|
||||
|
@ -58,7 +58,7 @@ EOT
|
||||
if ('annotation' === $type) {
|
||||
$destPath .= '/Entity';
|
||||
} else {
|
||||
$destPath .= '/Resources/config/doctrine/metadata/orm';
|
||||
$destPath .= '/Resources/config';
|
||||
}
|
||||
if ('yaml' === $type) {
|
||||
$type = 'yml';
|
||||
@ -89,9 +89,9 @@ EOT
|
||||
$className = $class->name;
|
||||
$class->name = $bundle->getNamespace().'\\Entity\\'.$className;
|
||||
if ('annotation' === $type) {
|
||||
$path = $destPath.'/'.$className.'.php';
|
||||
$path = $destPath.'/'.$className.'.orm.dcm.php';
|
||||
} else {
|
||||
$path = $destPath.'/'.str_replace('\\', '.', $class->name).'.dcm.'.$type;
|
||||
$path = $destPath.'/'.str_replace('\\', '.', $class->name).'.orm.dcm.'.$type;
|
||||
}
|
||||
$output->writeln(sprintf(' > writing <comment>%s</comment>', $path));
|
||||
$code = $exporter->exportClassMetadata($class);
|
||||
|
@ -60,7 +60,7 @@ EOT
|
||||
'You do not have any mapped Doctrine ORM entities for any of your bundles. '.
|
||||
'Create a class inside the Entity namespace of any of your bundles and provide '.
|
||||
'mapping information for it with Annotations directly in the classes doc blocks '.
|
||||
'or with XML/YAML in your bundles Resources/config/doctrine/metadata/orm directory.'
|
||||
'or with XML/YAML in your bundles Resources/config directory.'
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -315,7 +315,7 @@ class DoctrineExtension extends AbstractDoctrineExtension
|
||||
|
||||
protected function getMappingResourceConfigDirectory()
|
||||
{
|
||||
return 'Resources/config/doctrine/metadata/orm';
|
||||
return 'Resources/config';
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bundle\DoctrineBundle\Mapping\Driver;
|
||||
|
||||
use Doctrine\ORM\Mapping\Driver\XmlDriver as BaseXmlDriver;
|
||||
|
||||
/**
|
||||
* XmlDriver that additionnaly looks for mapping information in a global file.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class XmlDriver extends BaseXmlDriver
|
||||
{
|
||||
protected $_globalFile = 'doctrine';
|
||||
protected $_classCache;
|
||||
protected $_fileExtension = '.orm.dcm.xml';
|
||||
|
||||
public function isTransient($className)
|
||||
{
|
||||
return !in_array($className, $this->getAllClassNames());
|
||||
}
|
||||
|
||||
public function getAllClassNames()
|
||||
{
|
||||
if (null === $this->_classCache) {
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
return array_merge(parent::getAllClassNames(), array_keys($this->_classCache));
|
||||
}
|
||||
|
||||
public function getElement($className)
|
||||
{
|
||||
if (null === $this->_classCache) {
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
if (!isset($this->_classCache[$className])) {
|
||||
$this->_classCache[$className] = parent::getElement($className);
|
||||
}
|
||||
|
||||
return $this->_classCache[$className];
|
||||
}
|
||||
|
||||
protected function initialize()
|
||||
{
|
||||
$this->_classCache = array();
|
||||
foreach ($this->_paths as $path) {
|
||||
if (file_exists($file = $path.'/'.$this->_globalFile.$this->_fileExtension)) {
|
||||
$this->_classCache = array_merge($this->_classCache, $this->_loadMappingFile($file));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bundle\DoctrineBundle\Mapping\Driver;
|
||||
|
||||
use Doctrine\ORM\Mapping\Driver\YamlDriver as BaseYamlDriver;
|
||||
|
||||
/**
|
||||
* YamlDriver that additionnaly looks for mapping information in a global file.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class YamlDriver extends BaseYamlDriver
|
||||
{
|
||||
protected $_globalFile = 'doctrine';
|
||||
protected $_classCache;
|
||||
protected $_fileExtension = '.orm.dcm.yml';
|
||||
|
||||
public function isTransient($className)
|
||||
{
|
||||
return !in_array($className, $this->getAllClassNames());
|
||||
}
|
||||
|
||||
public function getAllClassNames()
|
||||
{
|
||||
if (null === $this->_classCache) {
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
return array_merge(parent::getAllClassNames(), array_keys($this->_classCache));
|
||||
}
|
||||
|
||||
public function getElement($className)
|
||||
{
|
||||
if (null === $this->_classCache) {
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
if (!isset($this->_classCache[$className])) {
|
||||
$this->_classCache[$className] = parent::getElement($className);
|
||||
}
|
||||
|
||||
return $this->_classCache[$className];
|
||||
}
|
||||
|
||||
protected function initialize()
|
||||
{
|
||||
$this->_classCache = array();
|
||||
foreach ($this->_paths as $path) {
|
||||
if (file_exists($file = $path.'/'.$this->_globalFile.$this->_fileExtension)) {
|
||||
$this->_classCache = array_merge($this->_classCache, $this->_loadMappingFile($file));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -21,8 +21,8 @@
|
||||
<parameter key="doctrine.orm.metadata.driver_chain.class">Doctrine\ORM\Mapping\Driver\DriverChain</parameter>
|
||||
<parameter key="doctrine.orm.metadata.annotation.class">Doctrine\ORM\Mapping\Driver\AnnotationDriver</parameter>
|
||||
<parameter key="doctrine.orm.metadata.annotation_reader.class">Doctrine\Common\Annotations\AnnotationReader</parameter>
|
||||
<parameter key="doctrine.orm.metadata.xml.class">Doctrine\ORM\Mapping\Driver\XmlDriver</parameter>
|
||||
<parameter key="doctrine.orm.metadata.yml.class">Doctrine\ORM\Mapping\Driver\YamlDriver</parameter>
|
||||
<parameter key="doctrine.orm.metadata.xml.class">Symfony\Bundle\DoctrineBundle\Mapping\Driver\XmlDriver</parameter>
|
||||
<parameter key="doctrine.orm.metadata.yml.class">Symfony\Bundle\DoctrineBundle\Mapping\Driver\YamlDriver</parameter>
|
||||
<parameter key="doctrine.orm.metadata.php.class">Doctrine\ORM\Mapping\Driver\PHPDriver</parameter>
|
||||
<parameter key="doctrine.orm.metadata.staticphp.class">Doctrine\ORM\Mapping\Driver\StaticPHPDriver</parameter>
|
||||
|
||||
|
@ -120,8 +120,8 @@ abstract class AbstractDoctrineExtensionTest extends TestCase
|
||||
$this->assertEquals('Doctrine\ORM\Mapping\Driver\DriverChain', $container->getParameter('doctrine.orm.metadata.driver_chain.class'));
|
||||
$this->assertEquals('Doctrine\ORM\Mapping\Driver\AnnotationDriver', $container->getParameter('doctrine.orm.metadata.annotation.class'));
|
||||
$this->assertEquals('Doctrine\Common\Annotations\AnnotationReader', $container->getParameter('doctrine.orm.metadata.annotation_reader.class'));
|
||||
$this->assertEquals('Doctrine\ORM\Mapping\Driver\XmlDriver', $container->getParameter('doctrine.orm.metadata.xml.class'));
|
||||
$this->assertEquals('Doctrine\ORM\Mapping\Driver\YamlDriver', $container->getParameter('doctrine.orm.metadata.yml.class'));
|
||||
$this->assertEquals('Symfony\Bundle\DoctrineBundle\Mapping\Driver\XmlDriver', $container->getParameter('doctrine.orm.metadata.xml.class'));
|
||||
$this->assertEquals('Symfony\Bundle\DoctrineBundle\Mapping\Driver\YamlDriver', $container->getParameter('doctrine.orm.metadata.yml.class'));
|
||||
|
||||
$config = array(
|
||||
'proxy_namespace' => 'MyProxies',
|
||||
@ -554,12 +554,12 @@ abstract class AbstractDoctrineExtensionTest extends TestCase
|
||||
|
||||
$ymlDef = $container->getDefinition('doctrine.orm.default_yml_metadata_driver');
|
||||
$this->assertDICConstructorArguments($ymlDef, array(
|
||||
array(__DIR__ .DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'Bundles'.DIRECTORY_SEPARATOR.'YamlBundle'.DIRECTORY_SEPARATOR.'Resources'.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'doctrine'.DIRECTORY_SEPARATOR.'metadata')
|
||||
array(__DIR__ .DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'Bundles'.DIRECTORY_SEPARATOR.'YamlBundle'.DIRECTORY_SEPARATOR.'Resources'.DIRECTORY_SEPARATOR.'config')
|
||||
));
|
||||
|
||||
$xmlDef = $container->getDefinition('doctrine.orm.default_xml_metadata_driver');
|
||||
$this->assertDICConstructorArguments($xmlDef, array(
|
||||
array(__DIR__ .DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'Bundles'.DIRECTORY_SEPARATOR.'XmlBundle'.DIRECTORY_SEPARATOR.'Resources'.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'doctrine'.DIRECTORY_SEPARATOR.'metadata')
|
||||
array(__DIR__ .DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'Bundles'.DIRECTORY_SEPARATOR.'XmlBundle'.DIRECTORY_SEPARATOR.'Resources'.DIRECTORY_SEPARATOR.'config')
|
||||
));
|
||||
}
|
||||
|
||||
@ -602,12 +602,12 @@ abstract class AbstractDoctrineExtensionTest extends TestCase
|
||||
|
||||
$ymlDef = $container->getDefinition('doctrine.orm.em2_yml_metadata_driver');
|
||||
$this->assertDICConstructorArguments($ymlDef, array(
|
||||
array(__DIR__ .DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'Bundles'.DIRECTORY_SEPARATOR.'YamlBundle'.DIRECTORY_SEPARATOR.'Resources'.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'doctrine'.DIRECTORY_SEPARATOR.'metadata')
|
||||
array(__DIR__ .DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'Bundles'.DIRECTORY_SEPARATOR.'YamlBundle'.DIRECTORY_SEPARATOR.'Resources'.DIRECTORY_SEPARATOR.'config')
|
||||
));
|
||||
|
||||
$xmlDef = $container->getDefinition('doctrine.orm.em2_xml_metadata_driver');
|
||||
$this->assertDICConstructorArguments($xmlDef, array(
|
||||
array(__DIR__ .DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'Bundles'.DIRECTORY_SEPARATOR.'XmlBundle'.DIRECTORY_SEPARATOR.'Resources'.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'doctrine'.DIRECTORY_SEPARATOR.'metadata')
|
||||
array(__DIR__ .DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR.'Bundles'.DIRECTORY_SEPARATOR.'XmlBundle'.DIRECTORY_SEPARATOR.'Resources'.DIRECTORY_SEPARATOR.'config')
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -16,9 +16,9 @@
|
||||
<mapping name="AnnotationsBundle" />
|
||||
</entity-manager>
|
||||
<entity-manager name="em2">
|
||||
<mapping name="YamlBundle" dir="Resources/config/doctrine/metadata" alias="yml" />
|
||||
<mapping name="YamlBundle" dir="Resources/config" alias="yml" />
|
||||
<mapping name="manual" type="xml" prefix="Fixtures\Bundles\XmlBundle"
|
||||
dir="%kernel.root_dir%/../src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/XmlBundle/Resources/config/doctrine/metadata"
|
||||
dir="%kernel.root_dir%/../src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/XmlBundle/Resources/config"
|
||||
alias="TestAlias"
|
||||
/>
|
||||
</entity-manager>
|
||||
|
@ -13,9 +13,9 @@
|
||||
|
||||
<orm>
|
||||
<mapping name="AnnotationsBundle" />
|
||||
<mapping name="YamlBundle" dir="Resources/config/doctrine/metadata" alias="yml" />
|
||||
<mapping name="YamlBundle" dir="Resources/config" alias="yml" />
|
||||
<mapping name="manual" type="xml" prefix="Fixtures\Bundles\XmlBundle"
|
||||
dir="%kernel.root_dir%/../src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/XmlBundle/Resources/config/doctrine/metadata"
|
||||
dir="%kernel.root_dir%/../src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/XmlBundle/Resources/config"
|
||||
alias="TestAlias"
|
||||
/>
|
||||
</orm>
|
||||
|
@ -14,10 +14,10 @@ doctrine:
|
||||
em2:
|
||||
mappings:
|
||||
YamlBundle:
|
||||
dir: Resources/config/doctrine/metadata
|
||||
dir: Resources/config
|
||||
alias: yml
|
||||
manual:
|
||||
type: xml
|
||||
prefix: Fixtures\Bundles\XmlBundle
|
||||
dir: %kernel.root_dir%/../src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/XmlBundle/Resources/config/doctrine/metadata
|
||||
dir: %kernel.root_dir%/../src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/XmlBundle/Resources/config
|
||||
alias: TestAlias
|
||||
|
@ -9,10 +9,10 @@ doctrine:
|
||||
mappings:
|
||||
AnnotationsBundle: ~
|
||||
YamlBundle:
|
||||
dir: Resources/config/doctrine/metadata
|
||||
dir: Resources/config
|
||||
alias: yml
|
||||
manual:
|
||||
type: xml
|
||||
prefix: Fixtures\Bundles\XmlBundle
|
||||
dir: %kernel.root_dir%/../src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/XmlBundle/Resources/config/doctrine/metadata
|
||||
dir: %kernel.root_dir%/../src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/XmlBundle/Resources/config
|
||||
alias: TestAlias
|
||||
|
@ -77,7 +77,7 @@ class TestCase extends \PHPUnit_Framework_TestCase
|
||||
'default' => array(
|
||||
'mappings' => array('YamlBundle' => array(
|
||||
'type' => 'yml',
|
||||
'dir' => __DIR__ . "/DependencyInjection/Fixtures/Bundles/YamlBundle/Resources/config/doctrine/metadata/orm",
|
||||
'dir' => __DIR__ . "/DependencyInjection/Fixtures/Bundles/YamlBundle/Resources/config",
|
||||
'prefix' => 'Fixtures\Bundles\YamlBundle',
|
||||
)
|
||||
)
|
||||
|
Reference in New Issue
Block a user