Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix metadata loading of builtin documents

The wrapped metadata driver ensures that metadata for the builtin
documents is loaded. Still the DoctrineAnnotations need to be registered
with the AnnotationRegistry.
  • Loading branch information...
commit f2f9870e80dc0fd8aaa4a875046209e9d4d8604d 1 parent 48eb30b
@uwej711 uwej711 authored Johannes Stark committed
View
3  lib/Doctrine/ODM/PHPCR/Configuration.php
@@ -20,6 +20,7 @@
namespace Doctrine\ODM\PHPCR;
use Doctrine\ODM\PHPCR\Mapping\Driver\Driver;
+use Doctrine\ODM\PHPCR\Mapping\Driver\BuiltinDocumentsDriver;
use Doctrine\ODM\PHPCR\DocumentNameMapperInterface;
/**
@@ -133,7 +134,7 @@ public function setDocumentNamespaces(array $documentNamespaces)
*/
public function setMetadataDriverImpl(Driver $driverImpl)
{
- $this->attributes['metadataDriverImpl'] = $driverImpl;
+ $this->attributes['metadataDriverImpl'] = new BuiltinDocumentsDriver($driverImpl);
}
/**
View
93 lib/Doctrine/ODM/PHPCR/Mapping/Driver/BuiltinDocumentsDriver.php
@@ -0,0 +1,93 @@
+<?php
+
+namespace Doctrine\ODM\PHPCR\Mapping\Driver;
+
+use Doctrine\Common\Annotations\AnnotationReader;
+use Doctrine\ODM\PHPCR\Mapping\ClassMetadata;
+use Doctrine\ODM\PHPCR\Mapping\MappingException;
+use Doctrine\ODM\PHPCR\Mapping\Driver\AnnotationDriver;
+
+/**
+ * The BuiltinDocumentsDriver is used internally to make sure
+ * that the mapping for the built-in documents can be loaded
+ *
+ * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
+ * @link www.doctrine-project.org
+ * @since 1.0
+ * @author Uwe Jäger <uwej711e@googlemail.com>
+ */
+class BuiltinDocumentsDriver implements Driver
+{
+ /**
+ * namespace of built-in documents
+ */
+ const NAME_SPACE = 'Doctrine\ODM\PHPCR\Document';
+
+ /**
+ * @var Driver
+ */
+ private $wrappedDriver;
+
+ /**
+ * @var Driver
+ */
+ private $builtinDriver;
+
+ /**
+ * Create with a driver to wrap
+ *
+ * @param Driver $nestedDriver
+ * @param string $namespace
+ */
+ public function __construct(Driver $wrappedDriver)
+ {
+ $this->wrappedDriver = $wrappedDriver;
+
+ $reader = new AnnotationReader();
+ $this->builtinDriver = new AnnotationDriver($reader, array(realpath(__DIR__.'/../../Document')));
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function loadMetadataForClass($className, ClassMetadata $class)
+ {
+ if (strpos($className, self::NAME_SPACE) === 0) {
+ $this->builtinDriver->loadMetadataForClass($className, $class);
+ return;
+ }
+
+ $this->wrappedDriver->loadMetadataForClass($className, $class);
+ }
+
+
+ /**
+ * Gets the names of all mapped classes known to this driver.
+ *
+ * @return array The names of all mapped classes known to this driver.
+ */
+ public function getAllClassNames()
+ {
+ $classNames = array();
+ $classNames = array_merge($classNames, $this->builtinDriver->getAllClassNames());
+ $classNames = array_merge($classNames, $this->wrappedDriver->getAllClassNames());
+ return $classNames;
+ }
+
+ /**
+ * Whether the class with the specified name should have its metadata loaded.
+ *
+ * This is only the case for non-transient classes either mapped as an Document or MappedSuperclass.
+ *
+ * @param string $className
+ * @return boolean
+ */
+ public function isTransient($className)
+ {
+ if (strpos($className, self::NAME_SPACE) === 0) {
+ return $this->builtinDriver->isTransient($className);
+ }
+
+ return $this->wrappedDriver->isTransient($className);
+ }
+}
View
1  tests/Doctrine/Tests/ODM/PHPCR/PHPCRFunctionalTestCase.php
@@ -10,7 +10,6 @@ public function createDocumentManager()
$paths = array();
$paths[] = __DIR__ . "/../../Models";
- $paths[] = __DIR__ . "/../../../../../lib/Doctrine/ODM/PHPCR/Document";
$metaDriver = new \Doctrine\ODM\PHPCR\Mapping\Driver\AnnotationDriver($reader, $paths);
$factoryclass = isset($GLOBALS['DOCTRINE_PHPCR_FACTORY']) ?
Please sign in to comment.
Something went wrong with that request. Please try again.