Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

PHPCR-37 - Sync doctrine common metadata changes in master #85

Merged
merged 14 commits into from

3 participants

@Ocramius
Owner

Hi there!
This is the PR for task http://www.doctrine-project.org/jira/browse/PHPCR-37
It should also add requested feature http://www.doctrine-project.org/jira/browse/PHPCR-31
I am here just asking for an early review as I first have to fix newlines on some of the committed files (you will surely notice them) before eventually having this merged into master.

Tested on windows, php 5.3.8. Result is "Tests: 192, Assertions: 871, Incomplete: 1, Skipped: 2.". No unit tests have been added, which is also open for suggestions :)

As we're working on metadata drivers here, also wanted to know what to do with the Doctrine\ODM\PHPCR\Mapping\Driver\BuiltinDocumentsDriver, which I didn't fully understand.

Adding reference to @beberlei as he could need these changes too in other doctrine related projects.
Also wanted to know by anyone who eventually has information about that where and who is working on this in other doctrine projects (for reference and to help back).

Build Status (because of Midgard PHP 5.4 issues)

lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php
((383 lines not shown))
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getFqcnFromAlias($namespaceAlias, $simpleClassName)
+ {
+ return $this->dm->getConfiguration()->getDocumentNamespace($namespaceAlias)
+ . '\\' . $simpleClassName;
+ }
+
+ /**
+ * {@inheritdoc}
+ *
+ * @todo unclear usage of rootEntityFound
+ */
+ protected function doLoadMetadata($class, $parent, $rootEntityFound) {
@lsmith77 Owner

opening bracket should be on the next line (same applies to the following methods)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php
((381 lines not shown))
+ return new ClassMetadata($className);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getFqcnFromAlias($namespaceAlias, $simpleClassName)
+ {
+ return $this->dm->getConfiguration()->getDocumentNamespace($namespaceAlias)
+ . '\\' . $simpleClassName;
+ }
+
+ /**
+ * {@inheritdoc}
+ *
+ * @todo unclear usage of rootEntityFound
@lsmith77 Owner

@beberlei we were unsure what the purpose is here ..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@lsmith77 lsmith77 commented on the diff
lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php
@@ -1,278 +1,141 @@
@lsmith77 Owner

as noted we need to fix the line endings in this file ..

@Ocramius Owner

Fixed :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@lsmith77 lsmith77 commented on the diff
lib/Doctrine/ODM/PHPCR/Mapping/MappingException.php
@@ -1,88 +1,88 @@
@lsmith77 Owner

needs line ending fixing

@Ocramius Owner

Fixed :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/Doctrine/ODM/PHPCR/Mapping/MappingException.php
((125 lines not shown))
+
+ public static function classIsNotAValidDocument($className)
+ {
+ return new self('Class '.$className.' is not a valid document or mapped super class.');
+ }
+
+ public static function reflectionFailure($document, \ReflectionException $previousException)
+ {
+ return new self('An error occurred in ' . $document, 0, $previousException);
+ }
+
+ /**
+ * @param string $document The document's name
+ * @param string $fieldName The name of the field that was already declared
+ */
+ public static function duplicateFieldMapping($document, $fieldName) {
@lsmith77 Owner

opening bracket is off ..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/Doctrine/ODM/PHPCR/Mapping/MappingException.php
((133 lines not shown))
+ return new self('An error occurred in ' . $document, 0, $previousException);
+ }
+
+ /**
+ * @param string $document The document's name
+ * @param string $fieldName The name of the field that was already declared
+ */
+ public static function duplicateFieldMapping($document, $fieldName) {
+ return new self('Property "'.$fieldName.'" in "'.$document.'" was already declared, but it must be declared only once');
+ }
+
+ /**
+ * @param string $document The document's name
+ * @param string $fieldName The name of the field that was already declared
+ */
+ public static function missingTypeDefinition($document, $fieldName) {
@lsmith77 Owner

opening bracket is off ..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@lsmith77 lsmith77 commented on the diff
lib/Doctrine/ODM/PHPCR/Proxy/ProxyFactory.php
@@ -1,339 +1,344 @@
@lsmith77 Owner

line endings need fixing

@Ocramius Owner

Fixed :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/Doctrine/ODM/PHPCR/Configuration.php
((5 lines not shown))
+ *
+ * @param Cache $metadataCacheImpl
+ */
+ public function setMetadataCacheImpl(Cache $metadataCacheImpl)
+ {
+ $this->attributes['metadataCacheImpl'] = $metadataCacheImpl;
+ }
+
+ /**
+ * Gets the cache driver implementation that is used for the mapping metadata.
+ *
+ * @return Cache|null
+ */
+ public function getMetadataCacheImpl()
+ {
+ if($this->attributes['metadataCacheImpl'] === null) {
@lsmith77 Owner

missing space after if

@Ocramius Owner

Removed (was code using during development)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php
((328 lines not shown))
+
+ /**
+ * The used metadata driver.
+ *
+ * @var \Doctrine\ODM\PHPCR\Mapping\Driver\Driver
+ */
+ private $driver;
+
+ /**
+ * Creates a new factory instance that uses the given DocumentManager instance.
+ *
+ * @param $dm The DocumentManager instance
+ */
+ public function __construct(DocumentManager $dm)
+ {
+ $this->dm = $dm;
@lsmith77 Owner

extra whitespace should be removed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@lsmith77
Owner

We might be able to steal a few unit tests from CouchDB ODM ..

@dbu
Collaborator

thanks for this work ocramius!
about the tests: did you look at the code coverage report? would be great if we have the non-trivial methods covered by tests.

do we need to figure out what the rootEntityFound thing is or can we just merge? if all tests still run, and applications still work i'd say we could merge.

@sixty-nine when you work on the versioning stuff in january, you want to look at this pull request (if its not merged by then) when you do any new annotations...

@lsmith77
Owner

@dbu: lets wait for some feedback from @beberlei before merging this. but its indeed quite exciting. especially since @Ocramius is "on the side" also implementing metadata caching.

@Ocramius
Owner

@dbu: this PR is almost only code cleanup/removal, but I'm going to check code coverage asap :)

I guess we MUST first know what rootEntityFound should look like... Can't just implement a feature because "it works! don't touch it!" :P

@lsmith77: if this stuff is not yet landed on other doctrine/* projects I'll first write this stuff for the others before getting back here (and I'm also curious about the status of OXM, which is sadly a bit stuck :( )

@Ocramius
Owner

I've just uploaded the test coverage results to http://marco-pivetta.com/phpcr-odm-sync-doctrine-common-metadata-changes/coverage/
Doesn't seem that terrible, but still, we actually could need to borrow some tests...

@lsmith77 lsmith77 commented on the diff
lib/Doctrine/ODM/PHPCR/Configuration.php
@@ -19,6 +19,7 @@
namespace Doctrine\ODM\PHPCR;
+use Doctrine\Common\Cache\Cache;
@lsmith77 Owner

this can probably be removed?

@Ocramius Owner

I use it for setMetadataCacheImpl(Cache $metadataCacheImpl) :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@lsmith77
Owner

can you enable travis-ci for this fork? at any rate .. looks good to me .. lets hop that @beberlei shows his face soon to review :)

lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php
((108 lines not shown))
{
- if (isset($this->loadedAliases[$alias])) {
- return $this->loadedAliases[$alias];
+ if ($metadata = parent::getMetadataFor($className)) {
@lsmith77 Owner

i think its better to do the assignment outside of the if statement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@Ocramius
Owner

As explained by @beberlei, the doLoadMetadata method should be fine for now, but will require some editing if PHPCR-ODM starts supporting inheritance.
Build looks ok to me: http://travis-ci.org/Ocramius/phpcr-odm/builds/454023

@lsmith77 lsmith77 merged commit 5842eb3 into doctrine:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 25, 2011
  1. @Ocramius
  2. @Ocramius
  3. @Ocramius
  4. @Ocramius

    First cleanup of code that is duplicate of what is inherited by Doctr…

    Ocramius authored
    …ine\Common\Persistence\ClassMetadataFactory
    
    Removing explicit public API that allowed loading metadata for alias.
    Fixing "use" coding conventions
    - still not ready for merge -
  5. @Ocramius
Commits on Dec 26, 2011
  1. @Ocramius
  2. @Ocramius
  3. @Ocramius
  4. @Ocramius

    Fixing coding conventions

    Ocramius authored
  5. @Ocramius

    Fixing line endings

    Ocramius authored
Commits on Dec 27, 2011
  1. @Ocramius
  2. @Ocramius

    Fixing coding conventions

    Ocramius authored
Commits on Dec 28, 2011
  1. @Ocramius

    Removing unused inheritance checks (will need them again when PHPCR-O…

    Ocramius authored
    …DM implements support for inheritance)
  2. @Ocramius
This page is out of date. Refresh to see the latest.
View
30 lib/Doctrine/ODM/PHPCR/Configuration.php
@@ -19,6 +19,7 @@
namespace Doctrine\ODM\PHPCR;
+use Doctrine\Common\Cache\Cache;
@lsmith77 Owner

this can probably be removed?

@Ocramius Owner

I use it for setMetadataCacheImpl(Cache $metadataCacheImpl) :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
use Doctrine\ODM\PHPCR\Mapping\Driver\Driver;
use Doctrine\ODM\PHPCR\Mapping\Driver\BuiltinDocumentsDriver;
use Doctrine\ODM\PHPCR\DocumentClassMapperInterface;
@@ -44,9 +45,10 @@ class Configuration
'writeDoctrineMetadata' => true,
'validateDoctrineMetadata' => true,
'metadataDriverImpl' => null,
+ 'metadataCacheImpl' => null,
'documentClassMapper' => null,
'proxyNamespace' => 'MyPHPCRProxyNS',
- 'autoGenerateProxyClasses' => true
+ 'autoGenerateProxyClasses' => true,
);
/**
@@ -128,7 +130,7 @@ public function setDocumentNamespaces(array $documentNamespaces)
}
/**
- * Sets the cache driver implementation that is used for metadata caching.
+ * Sets the driver implementation that is used to retrieve mapping metadata.
*
* @param Driver $driverImpl
* @todo Force parameter to be a Closure to ensure lazy evaluation
@@ -140,7 +142,7 @@ public function setMetadataDriverImpl(Driver $driverImpl)
}
/**
- * Gets the cache driver implementation that is used for the mapping metadata.
+ * Gets the driver implementation that is used to retrieve mapping metadata.
*
* @return Mapping\Driver\Driver
*/
@@ -150,6 +152,26 @@ public function getMetadataDriverImpl()
}
/**
+ * Sets the cache driver implementation that is used for metadata caching.
+ *
+ * @param Cache $metadataCacheImpl
+ */
+ public function setMetadataCacheImpl(Cache $metadataCacheImpl)
+ {
+ $this->attributes['metadataCacheImpl'] = $metadataCacheImpl;
+ }
+
+ /**
+ * Gets the cache driver implementation that is used for the mapping metadata.
+ *
+ * @return Cache|null
+ */
+ public function getMetadataCacheImpl()
+ {
+ return $this->attributes['metadataCacheImpl'];
+ }
+
+ /**
* Gets the cache driver implementation that is used for metadata caching.
*
* @return \Doctrine\ODM\PHPCR\DocumentClassMapperInterface
@@ -237,4 +259,4 @@ public function getAutoGenerateProxyClasses()
{
return $this->attributes['autoGenerateProxyClasses'];
}
-}
+}
View
238 lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php
@@ -19,10 +19,10 @@
namespace Doctrine\ODM\PHPCR\Mapping;
-use Doctrine\ODM\PHPCR\DocumentManager,
- Doctrine\ODM\PHPCR\Mapping\ClassMetadata,
- Doctrine\ODM\PHPCR\PHPCRException,
- Doctrine\Common\Cache\Cache;
+use Doctrine\ODM\PHPCR\DocumentManager;
+use Doctrine\ODM\PHPCR\Mapping\ClassMetadata;
+use Doctrine\ODM\PHPCR\PHPCRException;
+use Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory;
/**
* The ClassMetadataFactory is used to create ClassMetadata objects that contain all the
@@ -35,244 +35,106 @@
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @author Lukas Kahwe Smith <smith@pooteeweet.org>
*/
-class ClassMetadataFactory
+class ClassMetadataFactory extends AbstractClassMetadataFactory
{
- /**
- * @var DocumentManager
- */
- private $dm;
/**
- * @var array
+ * {@inheritdoc}
*/
- private $loadedMetadata = array();
-
+ protected $cacheSalt = '\$PHPCRODMCLASSMETADATA';
+
/**
- * @var array
+ * @var DocumentManager
*/
- private $loadedAliases = array();
+ private $dm;
/**
* The used metadata driver.
*
- * @var Doctrine\ODM\PHPCR\Mapping\Driver\Driver
+ * @var \Doctrine\ODM\PHPCR\Mapping\Driver\Driver
*/
private $driver;
/**
- * The used cache driver.
- *
- * @var Cache
- */
- private $cacheDriver;
-
- /**
* Creates a new factory instance that uses the given DocumentManager instance.
*
- * @param $dm The DocumentManager instance
+ * @param $dm The DocumentManager instance
*/
public function __construct(DocumentManager $dm)
{
$this->dm = $dm;
- $this->driver = $this->dm->getConfiguration()->getMetadataDriverImpl();
- }
-
- /**
- * Sets the cache driver used by the factory to cache ClassMetadata instances.
- *
- * @param Doctrine\Common\Cache\Cache $cacheDriver
- */
- public function setCacheDriver($cacheDriver)
- {
- $this->cacheDriver = $cacheDriver;
+ $conf = $this->dm->getConfiguration();
+ $this->setCacheDriver($conf->getMetadataCacheImpl());
+ $this->driver = $conf->getMetadataDriverImpl();
}
/**
- * Gets the cache driver used by the factory to cache ClassMetadata instances.
- *
- * @return Doctrine\Common\Cache\Cache
+ * {@inheritdoc}
+ *
+ * @throws MappingException
*/
- public function getCacheDriver()
- {
- return $this->cacheDriver;
- }
-
- /**
- * Gets the array of loaded ClassMetadata instances.
- *
- * @return array $loadedMetadata The loaded metadata.
- */
- public function getLoadedMetadata()
- {
- return $this->loadedMetadata;
- }
-
- /**
- * Forces the factory to load the metadata of all classes known to the underlying
- * mapping driver.
- *
- * @return array The ClassMetadata instances of all mapped classes.
- */
- public function getAllMetadata()
- {
- $metadata = array();
- foreach ($this->driver->getAllClassNames() as $className) {
- $metadata[] = $this->getMetadataFor($className);
- }
-
- return $metadata;
- }
-
- public function getMetadataForAlias($alias)
+ public function getMetadataFor($className)
{
- if (isset($this->loadedAliases[$alias])) {
- return $this->loadedAliases[$alias];
+ $metadata = parent::getMetadataFor($className);
+ if ($metadata) {
+ return $metadata;
}
-
- if ($this->cacheDriver && ($cached = $this->cacheDriver->fetch("$alias\$PHPCRODMALIAS")) !== false) {
- return $this->loadedAliases[$alias] = $cached;
- }
-
- foreach ($this->loadedMetadata as $metadata) {
- if ($metadata->alias === $alias) {
- $this->loadedAliases[$alias] = $metadata;
- if ($this->cacheDriver) {
- $this->cacheDriver->save(
- "$alias\$PHPCRODMALIAS", $this->loadedAliases[$alias], null
- );
- }
- return $metadata;
- }
- }
-
- foreach ($this->driver->getAllClassNames() as $className) {
- $metadata = $this->getMetadataFor($className);
- if ($metadata->alias === $alias) {
- $this->loadedAliases[$alias] = $metadata;
- if ($this->cacheDriver) {
- $this->cacheDriver->save(
- "$alias\$PHPCRODMALIAS", $this->loadedAliases[$alias], null
- );
- }
- return $metadata;
- }
- }
-
- throw new MappingException('Alias '.$alias.' could not be resolved to a document class name');
+ throw MappingException::classNotMapped($className);
}
/**
- * Gets the class metadata descriptor for a class.
- *
- * @param string $className The name of the class.
- * @return Doctrine\ODM\PHPCR\Mapping\ClassMetadata
+ * {@inheritdoc}
+ *
+ * @throws MappingException
*/
- public function getMetadataFor($className)
+ function loadMetadata($className)
{
- if (!isset($this->loadedMetadata[$className])) {
- $realClassName = $className;
-
- // Check for namespace alias
- if (strpos($className, ':') !== false) {
- list($namespaceAlias, $simpleClassName) = explode(':', $className);
- $realClassName = $this->dm->getConfiguration()->getDocumentNamespace($namespaceAlias) . '\\' . $simpleClassName;
-
- if (isset($this->loadedMetadata[$realClassName])) {
- // We do not have the alias name in the map, include it
- $this->loadedMetadata[$className] = $this->loadedMetadata[$realClassName];
-
- return $this->loadedMetadata[$realClassName];
- }
- }
-
- if ($this->cacheDriver) {
- if (($cached = $this->cacheDriver->fetch("$realClassName\$PHPCRODMCLASSMETADATA")) !== false) {
- $this->loadedMetadata[$realClassName] = $cached;
- } else {
- foreach ($this->loadMetadata($realClassName) as $loadedClassName) {
- $this->cacheDriver->save(
- "$loadedClassName\$PHPCRODMCLASSMETADATA", $this->loadedMetadata[$loadedClassName], null
- );
- }
- }
- } else {
- $this->loadMetadata($realClassName);
- }
-
- if ($className != $realClassName) {
- // We do not have the alias name in the map, include it
- $this->loadedMetadata[$className] = $this->loadedMetadata[$realClassName];
- }
+ if (class_exists($className)) {
+ return parent::loadMetadata($className);
}
-
- if (!isset($this->loadedMetadata[$className])) {
- throw MappingException::classNotMapped();
- }
-
- return $this->loadedMetadata[$className];
+ throw MappingException::classNotFound($className);
}
+
/**
- * Loads the metadata of the class in question and all it's ancestors whose metadata
- * is still not loaded.
- *
- * @param string $className The name of the class for which the metadata should get loaded.
+ * {@inheritdoc}
*/
- private function loadMetadata($className)
+ protected function newClassMetadataInstance($className)
{
- if (!class_exists($className)) {
- throw MappingException::classNotFound($className);
- }
-
- $this->loadedMetadata[$className] = new ClassMetadata($className);
- $this->driver->loadMetadataForClass($className, $this->loadedMetadata[$className]);
+ return new ClassMetadata($className);
}
-
+
/**
- * Checks whether the factory has the metadata for a class loaded already.
- *
- * @param string $className
- * @return boolean TRUE if the metadata of the class in question is already loaded, FALSE otherwise.
+ * {@inheritdoc}
*/
- public function hasMetadataFor($className)
+ protected function getFqcnFromAlias($namespaceAlias, $simpleClassName)
{
- return isset($this->loadedMetadata[$className]);
+ return $this->dm->getConfiguration()->getDocumentNamespace($namespaceAlias)
+ . '\\' . $simpleClassName;
}
/**
- * Sets the metadata descriptor for a specific class.
- *
- * NOTE: This is only useful in very special cases, like when generating proxy classes.
- *
- * @param string $className
- * @param ClassMetadata $class
+ * {@inheritdoc}
*/
- public function setMetadataFor($className, $class)
+ protected function doLoadMetadata($class, $parent, $rootEntityFound)
{
- $this->loadedMetadata[$className] = $class;
+ $this->getDriver()->loadMetadataForClass($class->getName(), $class);
}
/**
- * Creates a new ClassMetadata instance for the given class name.
- *
- * @param string $className
- * @return Doctrine\ODM\PHPCR\Mapping\ClassMetadata
+ * {@inheritdoc}
*/
- protected function newClassMetadataInstance($className)
+ protected function getDriver()
{
- return new ClassMetadata($className);
+ return $this->driver;
}
/**
- * Whether the class with the specified name should have its metadata loaded.
- * This is only the case if it is either mapped as an Entity or a
- * MappedSuperclass.
- *
- * @param string $className
- * @return boolean
+ * {@inheritdoc}
*/
- public function isTransient($className)
+ protected function initialize()
{
- return $this->driver->isTransient($className);
+ $this->initialized = true;
}
-}
+
+}
View
231 lib/Doctrine/ODM/PHPCR/Mapping/Driver/AnnotationDriver.php
@@ -21,9 +21,10 @@
use Doctrine\Common\Annotations\AnnotationReader,
Doctrine\Common\Annotations\Reader,
+ Doctrine\Common\Persistence\Mapping\Driver\AnnotationDriver as AbstractAnnotationDriver,
+ Doctrine\Common\Persistence\Mapping\ClassMetadata,
Doctrine\ODM\PHPCR\Event,
Doctrine\ODM\PHPCR\Mapping\Annotations as ODM,
- Doctrine\ODM\PHPCR\Mapping\ClassMetadata,
Doctrine\ODM\PHPCR\Mapping\MappingException;
/**
@@ -37,87 +38,29 @@
* @author Daniel Barsotti <daniel.barsotti@liip.ch>
* @author David Buchmann <david@liip.ch>
*/
-class AnnotationDriver implements Driver
+class AnnotationDriver extends AbstractAnnotationDriver implements Driver
{
- /**
- * The AnnotationReader.
- *
- * @var AnnotationReader
- */
- private $reader;
-
- /**
- * The paths where to look for mapping files.
- *
- * @var array
- */
- private $paths = array();
-
- /**
- * The file extension of mapping documents.
- *
- * @var string
- */
- private $fileExtension = '.php';
-
- /**
- * @param array
- */
- private $classNames;
/**
+ * {@inheritdoc}
+ *
* Document annotation classes, ordered by precedence.
*/
- static private $documentAnnotationClasses = array(
- 'Doctrine\\ODM\\PHPCR\\Mapping\\Annotations\\Document',
- 'Doctrine\\ODM\\PHPCR\\Mapping\\Annotations\\MappedSuperclass',
+ protected $entityAnnotationClasses = array(
+ 'Doctrine\\ODM\\PHPCR\\Mapping\\Annotations\\Document' => 0,
+ 'Doctrine\\ODM\\PHPCR\\Mapping\\Annotations\\MappedSuperclass' => 1,
);
/**
- * Initializes a new AnnotationDriver that uses the given AnnotationReader for reading
- * docblock annotations.
- *
- * @param $reader The AnnotationReader to use.
- * @param string|array $paths One or multiple paths where mapping classes can be found.
- */
- public function __construct(Reader $reader, $paths = null)
- {
- $this->reader = $reader;
- if ($paths) {
- $this->addPaths((array) $paths);
- }
- }
-
- /**
- * Append lookup paths to metadata driver.
- *
- * @param array $paths
- */
- public function addPaths(array $paths)
- {
- $this->paths = array_unique(array_merge($this->paths, $paths));
- }
-
- /**
- * Retrieve the defined metadata lookup paths.
- *
- * @return array
- */
- public function getPaths()
- {
- return $this->paths;
- }
-
- /**
* {@inheritdoc}
*/
- public function loadMetadataForClass($className, ClassMetadata $class)
+ public function loadMetadataForClass($className, ClassMetadata $metadata)
{
- $reflClass = $class->getReflectionClass();
+ $reflClass = $metadata->getReflectionClass();
$documentAnnots = array();
foreach ($this->reader->getClassAnnotations($reflClass) as $annot) {
- foreach (self::$documentAnnotationClasses as $i => $annotClass) {
+ foreach ($this->entityAnnotationClasses as $annotClass => $i) {
if ($annot instanceof $annotClass) {
$documentAnnots[$i] = $annot;
}
@@ -135,22 +78,22 @@ public function loadMetadataForClass($className, ClassMetadata $class)
throw new MappingException("Alias must be specified in the Document() annotation mapping of $className");
}
- $class->setAlias($documentAnnot->alias);
+ $metadata->setAlias($documentAnnot->alias);
if (isset($documentAnnot->versionable) && $documentAnnot->versionable) {
- $class->setVersioned(true);
+ $metadata->setVersioned(true);
}
- $class->setNodeType($documentAnnot->nodeType);
+ $metadata->setNodeType($documentAnnot->nodeType);
if (isset($documentAnnot->referenceable) && $documentAnnot->referenceable) {
- $class->setReferenceable(true);
+ $metadata->setReferenceable(true);
}
if ($documentAnnot->repositoryClass) {
- $class->setCustomRepositoryClassName($documentAnnot->repositoryClass);
+ $metadata->setCustomRepositoryClassName($documentAnnot->repositoryClass);
}
if ($documentAnnot->translator) {
- $class->setTranslator($documentAnnot->translator);
+ $metadata->setTranslator($documentAnnot->translator);
}
foreach ($reflClass->getProperties() as $property) {
@@ -158,39 +101,39 @@ public function loadMetadataForClass($className, ClassMetadata $class)
$mapping['fieldName'] = $property->getName();
foreach ($this->reader->getPropertyAnnotations($property) as $fieldAnnot) {
- if ($fieldAnnot instanceof \Doctrine\ODM\PHPCR\Mapping\Annotations\Property) {
+ if ($fieldAnnot instanceof ODM\Property) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
- $class->mapField($mapping);
- } elseif ($fieldAnnot instanceof \Doctrine\ODM\PHPCR\Mapping\Annotations\Id) {
+ $metadata->mapField($mapping);
+ } elseif ($fieldAnnot instanceof ODM\Id) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
- $class->mapId($mapping);
- } elseif ($fieldAnnot instanceof \Doctrine\ODM\PHPCR\Mapping\Annotations\Node) {
+ $metadata->mapId($mapping);
+ } elseif ($fieldAnnot instanceof ODM\Node) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
- $class->mapNode($mapping);
- } elseif ($fieldAnnot instanceof \Doctrine\ODM\PHPCR\Mapping\Annotations\Nodename) {
+ $metadata->mapNode($mapping);
+ } elseif ($fieldAnnot instanceof ODM\Nodename) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
- $class->mapNodename($mapping);
- } elseif ($fieldAnnot instanceof \Doctrine\ODM\PHPCR\Mapping\Annotations\ParentDocument) {
+ $metadata->mapNodename($mapping);
+ } elseif ($fieldAnnot instanceof ODM\ParentDocument) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
- $class->mapParentDocument($mapping);
- } elseif ($fieldAnnot instanceof \Doctrine\ODM\PHPCR\Mapping\Annotations\Child) {
+ $metadata->mapParentDocument($mapping);
+ } elseif ($fieldAnnot instanceof ODM\Child) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
- $class->mapChild($mapping);
- } elseif ($fieldAnnot instanceof \Doctrine\ODM\PHPCR\Mapping\Annotations\Children) {
+ $metadata->mapChild($mapping);
+ } elseif ($fieldAnnot instanceof ODM\Children) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
- $class->mapChildren($mapping);
- } elseif ($fieldAnnot instanceof \Doctrine\ODM\PHPCR\Mapping\Annotations\ReferenceOne) {
+ $metadata->mapChildren($mapping);
+ } elseif ($fieldAnnot instanceof ODM\ReferenceOne) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
- $class->mapManyToOne($mapping);
- } elseif ($fieldAnnot instanceof \Doctrine\ODM\PHPCR\Mapping\Annotations\ReferenceMany) {
+ $metadata->mapManyToOne($mapping);
+ } elseif ($fieldAnnot instanceof ODM\ReferenceMany) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
- $class->mapManyToMany($mapping);
- } elseif ($fieldAnnot instanceof \Doctrine\ODM\PHPCR\Mapping\Annotations\Referrers) {
+ $metadata->mapManyToMany($mapping);
+ } elseif ($fieldAnnot instanceof ODM\Referrers) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
- $class->mapReferrers($mapping);
- } elseif ($fieldAnnot instanceof \Doctrine\ODM\PHPCR\Mapping\Annotations\Locale) {
+ $metadata->mapReferrers($mapping);
+ } elseif ($fieldAnnot instanceof ODM\Locale) {
$mapping = array_merge($mapping, (array) $fieldAnnot);
- $class->mapLocale($mapping);
+ $metadata->mapLocale($mapping);
}
if (!isset($mapping['name'])) {
@@ -203,106 +146,32 @@ public function loadMetadataForClass($className, ClassMetadata $class)
if ($method->isPublic()) {
foreach ($this->reader->getMethodAnnotations($method) as $annot) {
if ($annot instanceof ODM\PrePersist) {
- $class->addLifecycleCallback($method->getName(), \Doctrine\ODM\PHPCR\Event::prePersist);
+ $metadata->addLifecycleCallback($method->getName(), Event::prePersist);
} elseif ($annot instanceof ODM\PostPersist) {
- $class->addLifecycleCallback($method->getName(), \Doctrine\ODM\PHPCR\Event::postPersist);
+ $metadata->addLifecycleCallback($method->getName(), Event::postPersist);
} elseif ($annot instanceof ODM\PreUpdate) {
- $class->addLifecycleCallback($method->getName(), \Doctrine\ODM\PHPCR\Event::preUpdate);
+ $metadata->addLifecycleCallback($method->getName(), Event::preUpdate);
} elseif ($annot instanceof ODM\PostUpdate) {
- $class->addLifecycleCallback($method->getName(), \Doctrine\ODM\PHPCR\Event::postUpdate);
+ $metadata->addLifecycleCallback($method->getName(), Event::postUpdate);
} elseif ($annot instanceof ODM\PreRemove) {
- $class->addLifecycleCallback($method->getName(), \Doctrine\ODM\PHPCR\Event::preRemove);
+ $metadata->addLifecycleCallback($method->getName(), Event::preRemove);
} elseif ($annot instanceof ODM\PostRemove) {
- $class->addLifecycleCallback($method->getName(), \Doctrine\ODM\PHPCR\Event::postRemove);
+ $metadata->addLifecycleCallback($method->getName(), Event::postRemove);
} elseif ($annot instanceof ODM\PreLoad) {
- $class->addLifecycleCallback($method->getName(), \Doctrine\ODM\PHPCR\Event::preLoad);
+ $metadata->addLifecycleCallback($method->getName(), Event::preLoad);
} elseif ($annot instanceof ODM\PostLoad) {
- $class->addLifecycleCallback($method->getName(), \Doctrine\ODM\PHPCR\Event::postLoad);
+ $metadata->addLifecycleCallback($method->getName(), Event::postLoad);
}
}
}
}
// Check there is a @Locale annotation for translatable documents
- if (count($class->translatableFields)) {
- if (!isset($class->localeMapping)) {
+ if (count($metadata->translatableFields)) {
+ if (!isset($metadata->localeMapping)) {
throw new MappingException("You must define a @Locale field for translatable document '$className'");
}
}
}
- /**
- * Whether the class with the specified name is transient. Only non-transient
- * classes, that is entities and mapped superclasses, should have their metadata loaded.
- * A class is non-transient if it is annotated with either @Entity or
- * @MappedSuperclass in the class doc block.
- *
- * @param string $className
- * @return boolean
- */
- public function isTransient($className)
- {
- $rc = new \ReflectionClass($className);
-
- if ($this->reader->getClassAnnotation($rc, 'Doctrine\ODM\PHPCR\Mapping\Annotations\Document')) {
- return false;
- }
-
- if ($this->reader->getClassAnnotation($rc, 'Doctrine\ODM\PHPCR\Mapping\Annotations\MappedSuperclass')) {
- return false;
- }
-
- return true;
- }
-
- /**
- * {@inheritDoc}
- */
- public function getAllClassNames()
- {
- if ($this->classNames !== null) {
- return $this->classNames;
- }
-
- if (!$this->paths) {
- throw MappingException::pathRequired();
- }
-
- $classes = array();
- $includedFiles = array();
-
- foreach ($this->paths as $path) {
- if (!is_dir($path)) {
- throw MappingException::fileMappingDriversRequireConfiguredDirectoryPath();
- }
-
- $iterator = new \RecursiveIteratorIterator(
- new \RecursiveDirectoryIterator($path),
- \RecursiveIteratorIterator::LEAVES_ONLY
- );
-
- foreach ($iterator as $file) {
- if (($file->getBasename($this->fileExtension)) == $file->getBasename()) {
- continue;
- }
-
- $sourceFile = realpath($file->getPathName());
- require_once $sourceFile;
- $includedFiles[] = $sourceFile;
- }
- }
-
- $declared = get_declared_classes();
-
- foreach ($declared as $className) {
- $rc = new \ReflectionClass($className);
- $sourceFile = $rc->getFileName();
- if (in_array($sourceFile, $includedFiles) && !$this->isTransient($className)) {
- $classes[] = $className;
- }
- }
- $this->classNames = $classes;
-
- return $classes;
- }
-}
+}
View
4 lib/Doctrine/ODM/PHPCR/Mapping/Driver/BuiltinDocumentsDriver.php
@@ -3,7 +3,7 @@
namespace Doctrine\ODM\PHPCR\Mapping\Driver;
use Doctrine\Common\Annotations\AnnotationReader;
-use Doctrine\ODM\PHPCR\Mapping\ClassMetadata;
+use Doctrine\Common\Persistence\Mapping\ClassMetadata;
use Doctrine\ODM\PHPCR\Mapping\MappingException;
use Doctrine\ODM\PHPCR\Mapping\Driver\AnnotationDriver;
@@ -90,4 +90,4 @@ public function isTransient($className)
return $this->wrappedDriver->isTransient($className);
}
-}
+}
View
29 lib/Doctrine/ODM/PHPCR/Mapping/Driver/Driver.php
@@ -19,7 +19,7 @@
namespace Doctrine\ODM\PHPCR\Mapping\Driver;
-use Doctrine\ODM\PHPCR\Mapping\ClassMetadata;
+use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
/**
* Contract for metadata drivers.
@@ -30,30 +30,7 @@
* @author Jonathan H. Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
*/
-interface Driver
+interface Driver extends MappingDriver
{
- /**
- * Loads the metadata for the specified class into the provided container.
- *
- * @param string $className
- * @param ClassMetadataInfo $metadata
- */
- function loadMetadataForClass($className, ClassMetadata $metadata);
- /**
- * Gets the names of all mapped classes known to this driver.
- *
- * @return array The names of all mapped classes known to this driver.
- */
- function getAllClassNames();
-
- /**
- * Whether the class with the specified name should have its metadata loaded.
- * This is only the case if it is either mapped as an Document or a
- * MappedSuperclass.
- *
- * @param string $className
- * @return boolean
- */
- function isTransient($className);
-}
+}
View
4 lib/Doctrine/ODM/PHPCR/Mapping/Driver/DriverChain.php
@@ -2,7 +2,7 @@
namespace Doctrine\ODM\PHPCR\Mapping\Driver;
-use Doctrine\ODM\PHPCR\Mapping\ClassMetadata;
+use Doctrine\Common\Persistence\Mapping\ClassMetadata;
use Doctrine\ODM\PHPCR\Mapping\MappingException;
/**
@@ -93,4 +93,4 @@ public function isTransient($className)
// class isTransient, i.e. not an document or mapped superclass
return true;
}
-}
+}
View
2  lib/Doctrine/ODM/PHPCR/Mapping/Driver/PHPDriver.php
@@ -19,7 +19,7 @@
namespace Doctrine\ODM\PHPCR\Mapping\Driver;
-use Doctrine\ODM\PHPCR\Mapping\ClassMetadata;
+use Doctrine\Common\Persistence\Mapping\ClassMetadata;
/**
* The PHPDriver invokes a static PHP function on the document class itself passing
View
4 lib/Doctrine/ODM/PHPCR/Mapping/Driver/XmlDriver.php
@@ -19,7 +19,7 @@
namespace Doctrine\ODM\PHPCR\Mapping\Driver;
-use Doctrine\ODM\PHPCR\Mapping\ClassMetadata;
+use Doctrine\Common\Persistence\Mapping\ClassMetadata;
use Doctrine\ODM\PHPCR\Mapping\MappingException;
use SimpleXmlElement;
@@ -204,4 +204,4 @@ protected function loadMappingFile($file)
return $result;
}
-}
+}
View
6 lib/Doctrine/ODM/PHPCR/Mapping/Driver/YamlDriver.php
@@ -19,8 +19,8 @@
namespace Doctrine\ODM\PHPCR\Mapping\Driver;
-use Doctrine\ODM\PHPCR\Mapping\ClassMetadata,
- Doctrine\ODM\PHPCR\Mapping\MappingException;
+use Doctrine\Common\Persistence\Mapping\ClassMetadata;
+use Doctrine\ODM\PHPCR\Mapping\MappingException;
/**
* The YamlDriver reads the mapping metadata from yaml schema files.
@@ -194,4 +194,4 @@ protected function loadMappingFile($file)
{
return \Symfony\Component\Yaml\Yaml::parse($file);
}
-}
+}
View
12 lib/Doctrine/ODM/PHPCR/Mapping/MappingException.php
@@ -49,7 +49,8 @@ public static function reflectionFailure($document, \ReflectionException $previo
* @param string $document The document's name
* @param string $fieldName The name of the field that was already declared
*/
- public static function duplicateFieldMapping($document, $fieldName) {
+ public static function duplicateFieldMapping($document, $fieldName)
+ {
return new self('Property "'.$fieldName.'" in "'.$document.'" was already declared, but it must be declared only once');
}
@@ -57,7 +58,8 @@ public static function duplicateFieldMapping($document, $fieldName) {
* @param string $document The document's name
* @param string $fieldName The name of the field that was already declared
*/
- public static function missingTypeDefinition($document, $fieldName) {
+ public static function missingTypeDefinition($document, $fieldName)
+ {
return new self('Property "'.$fieldName.'" in "'.$document.'" must have a type attribute defined');
}
@@ -71,9 +73,9 @@ public static function aliasIsNotSpecified($document)
return new self('Document '.$document.' must specify an alias');
}
- public static function classNotMapped()
+ public static function classNotMapped($className)
{
- return new self();
+ return new self('Class ' . $className . ' is not mapped to a document');
}
public static function noTypeSpecified()
@@ -85,4 +87,4 @@ public static function mappingNotFound($className, $fieldName)
{
return new self("No mapping found for field '$fieldName' in class '$className'.");
}
-}
+}
View
8 lib/Doctrine/ODM/PHPCR/Proxy/ProxyFactory.php
@@ -333,7 +333,11 @@ public function &__get($name)
return $this->$name;
}
+ public function __isInitialized()
+ {
+ return $this->__isInitialized__;
+ }
+
}
PHP;
-}
-
+}
2  lib/vendor/doctrine-common
@@ -1 +1 @@
-Subproject commit 583b0e1d461d63d928cbf5ca18a6a408eeaaf1e9
+Subproject commit 16b2385b3ce5319d88969f18694e4b36533bd258
Something went wrong with that request. Please try again.