Sfoglia il codice sorgente

[DoctrineBundle] allow entities in sub directories

Johannes Schmitt 14 anni fa
parent
commit
0d16ceed9b

+ 7 - 10
src/Symfony/Bundle/DoctrineBundle/Mapping/Driver/XmlDriver.php

@@ -64,20 +64,17 @@ class XmlDriver extends BaseXmlDriver
 
     protected function _findMappingFile($className)
     {
-        if (false !== $pos = strrpos($className, '\\')) {
-            $namespace = substr($className, 0, $pos);
-            $shortName = substr($className, $pos+1);
-        } else {
-            $namespace = '';
-            $shortName = $className;
-        }
-
         foreach ($this->_paths as $prefix => $path) {
-            if ($prefix === $namespace && file_exists($filename = $path.'/'.$shortName.$this->_fileExtension)) {
+            if (0 !== strpos($className, $prefix.'\\')) {
+                continue;
+            }
+
+            $subPath = strtr(substr($className, strlen($prefix)), '\\', '/');
+            if (file_exists($filename = $path.$subPath.$this->fileExtension)) {
                 return $filename;
             }
         }
 
-        throw MappingException::mappingFileNotFound($className, $shortName.$this->_fileExtension);
+        throw MappingException::mappingFileNotFound($className, substr($className, strrpos($className, '\\')).$this->_fileExtension);
     }
 }

+ 7 - 10
src/Symfony/Bundle/DoctrineBundle/Mapping/Driver/YamlDriver.php

@@ -64,20 +64,17 @@ class YamlDriver extends BaseYamlDriver
 
     protected function _findMappingFile($className)
     {
-        if (false !== $pos = strrpos($className, '\\')) {
-            $namespace = substr($className, 0, $pos);
-            $shortName = substr($className, $pos+1);
-        } else {
-            $namespace = '';
-            $shortName = $className;
-        }
-
         foreach ($this->_paths as $prefix => $path) {
-            if ($prefix === $namespace && file_exists($filename = $path.'/'.$shortName.$this->_fileExtension)) {
+            if (0 !== strpos($className, $prefix.'\\')) {
+                continue;
+            }
+
+            $subPath = strtr(substr($className, strlen($prefix)), '\\', '/');
+            if (file_exists($filename = $path.$subPath.$this->fileExtension)) {
                 return $filename;
             }
         }
 
-        throw MappingException::mappingFileNotFound($className, $shortName.$this->_fileExtension);
+        throw MappingException::mappingFileNotFound($className, substr($className, strrpos($className, '\\')).$this->_fileExtension);
     }
 }