diff --git a/UPDATE.md b/UPDATE.md index 76c1a759a3..993a024a0c 100644 --- a/UPDATE.md +++ b/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): diff --git a/src/Symfony/Bundle/DoctrineAbstractBundle/DependencyInjection/AbstractDoctrineExtension.php b/src/Symfony/Bundle/DoctrineAbstractBundle/DependencyInjection/AbstractDoctrineExtension.php index dd3c16dbaa..fd828c56f9 100644 --- a/src/Symfony/Bundle/DoctrineAbstractBundle/DependencyInjection/AbstractDoctrineExtension.php +++ b/src/Symfony/Bundle/DoctrineAbstractBundle/DependencyInjection/AbstractDoctrineExtension.php @@ -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'; } diff --git a/src/Symfony/Bundle/DoctrineBundle/Command/GenerateEntityDoctrineCommand.php b/src/Symfony/Bundle/DoctrineBundle/Command/GenerateEntityDoctrineCommand.php index 80ab21d85e..9d53d771ff 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Command/GenerateEntityDoctrineCommand.php +++ b/src/Symfony/Bundle/DoctrineBundle/Command/GenerateEntityDoctrineCommand.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(); diff --git a/src/Symfony/Bundle/DoctrineBundle/Command/ImportMappingDoctrineCommand.php b/src/Symfony/Bundle/DoctrineBundle/Command/ImportMappingDoctrineCommand.php index 489043ed6d..ff8c5f37a8 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Command/ImportMappingDoctrineCommand.php +++ b/src/Symfony/Bundle/DoctrineBundle/Command/ImportMappingDoctrineCommand.php @@ -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 %s', $path)); $code = $exporter->exportClassMetadata($class); diff --git a/src/Symfony/Bundle/DoctrineBundle/Command/InfoDoctrineCommand.php b/src/Symfony/Bundle/DoctrineBundle/Command/InfoDoctrineCommand.php index 14b0134a23..9939b3d66a 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Command/InfoDoctrineCommand.php +++ b/src/Symfony/Bundle/DoctrineBundle/Command/InfoDoctrineCommand.php @@ -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.' ); } diff --git a/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/DoctrineExtension.php b/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/DoctrineExtension.php index 86f3ca067a..10f2022432 100755 --- a/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/DoctrineExtension.php +++ b/src/Symfony/Bundle/DoctrineBundle/DependencyInjection/DoctrineExtension.php @@ -315,7 +315,7 @@ class DoctrineExtension extends AbstractDoctrineExtension protected function getMappingResourceConfigDirectory() { - return 'Resources/config/doctrine/metadata/orm'; + return 'Resources/config'; } /** diff --git a/src/Symfony/Bundle/DoctrineBundle/Mapping/Driver/XmlDriver.php b/src/Symfony/Bundle/DoctrineBundle/Mapping/Driver/XmlDriver.php new file mode 100644 index 0000000000..c4a36ace20 --- /dev/null +++ b/src/Symfony/Bundle/DoctrineBundle/Mapping/Driver/XmlDriver.php @@ -0,0 +1,63 @@ + + * + * 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 + */ +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)); + } + } + } +} diff --git a/src/Symfony/Bundle/DoctrineBundle/Mapping/Driver/YamlDriver.php b/src/Symfony/Bundle/DoctrineBundle/Mapping/Driver/YamlDriver.php new file mode 100644 index 0000000000..08e9c4c96a --- /dev/null +++ b/src/Symfony/Bundle/DoctrineBundle/Mapping/Driver/YamlDriver.php @@ -0,0 +1,63 @@ + + * + * 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 + */ +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)); + } + } + } +} diff --git a/src/Symfony/Bundle/DoctrineBundle/Resources/config/orm.xml b/src/Symfony/Bundle/DoctrineBundle/Resources/config/orm.xml index 5180cd6bc4..248f90cd41 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Resources/config/orm.xml +++ b/src/Symfony/Bundle/DoctrineBundle/Resources/config/orm.xml @@ -21,8 +21,8 @@ Doctrine\ORM\Mapping\Driver\DriverChain Doctrine\ORM\Mapping\Driver\AnnotationDriver Doctrine\Common\Annotations\AnnotationReader - Doctrine\ORM\Mapping\Driver\XmlDriver - Doctrine\ORM\Mapping\Driver\YamlDriver + Symfony\Bundle\DoctrineBundle\Mapping\Driver\XmlDriver + Symfony\Bundle\DoctrineBundle\Mapping\Driver\YamlDriver Doctrine\ORM\Mapping\Driver\PHPDriver Doctrine\ORM\Mapping\Driver\StaticPHPDriver diff --git a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php index e1b5d0093f..6b8cdd5807 100755 --- a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php +++ b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/AbstractDoctrineExtensionTest.php @@ -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') )); } diff --git a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/XmlBundle/Resources/config/doctrine/metadata/orm/Fixtures.Bundles.XmlBundle.Entity.Test.xml b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/XmlBundle/Resources/config/Fixtures.Bundles.XmlBundle.Entity.Test.orm.dcm.xml similarity index 100% rename from src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/XmlBundle/Resources/config/doctrine/metadata/orm/Fixtures.Bundles.XmlBundle.Entity.Test.xml rename to src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/XmlBundle/Resources/config/Fixtures.Bundles.XmlBundle.Entity.Test.orm.dcm.xml diff --git a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/YamlBundle/Resources/config/doctrine/metadata/orm/Fixtures.Bundles.YamlBundle.Entity.Test.dcm.yml b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/YamlBundle/Resources/config/Fixtures.Bundles.YamlBundle.Entity.Test.orm.dcm.yml similarity index 100% rename from src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/YamlBundle/Resources/config/doctrine/metadata/orm/Fixtures.Bundles.YamlBundle.Entity.Test.dcm.yml rename to src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/Bundles/YamlBundle/Resources/config/Fixtures.Bundles.YamlBundle.Entity.Test.orm.dcm.yml diff --git a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_multiple_em_bundle_mappings.xml b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_multiple_em_bundle_mappings.xml index 0cbaf44674..b93473239f 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_multiple_em_bundle_mappings.xml +++ b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_multiple_em_bundle_mappings.xml @@ -16,9 +16,9 @@ - + diff --git a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_single_em_bundle_mappings.xml b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_single_em_bundle_mappings.xml index 232fd964f2..0350a692db 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_single_em_bundle_mappings.xml +++ b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/xml/orm_single_em_bundle_mappings.xml @@ -13,9 +13,9 @@ - + diff --git a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/yml/orm_multiple_em_bundle_mappings.yml b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/yml/orm_multiple_em_bundle_mappings.yml index 782a4ca2d2..16390ecc71 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/yml/orm_multiple_em_bundle_mappings.yml +++ b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/yml/orm_multiple_em_bundle_mappings.yml @@ -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 diff --git a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/yml/orm_single_em_bundle_mappings.yml b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/yml/orm_single_em_bundle_mappings.yml index 84b18152ba..2050d1290b 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/yml/orm_single_em_bundle_mappings.yml +++ b/src/Symfony/Bundle/DoctrineBundle/Tests/DependencyInjection/Fixtures/config/yml/orm_single_em_bundle_mappings.yml @@ -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 diff --git a/src/Symfony/Bundle/DoctrineBundle/Tests/TestCase.php b/src/Symfony/Bundle/DoctrineBundle/Tests/TestCase.php index 07fb5731d4..e28aa6ecea 100644 --- a/src/Symfony/Bundle/DoctrineBundle/Tests/TestCase.php +++ b/src/Symfony/Bundle/DoctrineBundle/Tests/TestCase.php @@ -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', ) )