Skip to content
This repository

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

Merged
merged 14 commits into from over 2 years ago

3 participants

Marco Pivetta Lukas Kahwe Smith David Buchmann
Marco Pivetta

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))
  105
+    
  106
+    /**
  107
+     * {@inheritdoc}
  108
+     */
  109
+    protected function getFqcnFromAlias($namespaceAlias, $simpleClassName)
  110
+    {
  111
+        return $this->dm->getConfiguration()->getDocumentNamespace($namespaceAlias) 
  112
+            . '\\' . $simpleClassName;
  113
+    }
  114
+
  115
+    /**
  116
+     * {@inheritdoc}
  117
+     * 
  118
+     * @todo unclear usage of rootEntityFound
  119
+     */
  120
+    protected function doLoadMetadata($class, $parent, $rootEntityFound) {
1
Lukas Kahwe Smith Collaborator

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))
  103
+        return new ClassMetadata($className);
  104
+    }
  105
+    
  106
+    /**
  107
+     * {@inheritdoc}
  108
+     */
  109
+    protected function getFqcnFromAlias($namespaceAlias, $simpleClassName)
  110
+    {
  111
+        return $this->dm->getConfiguration()->getDocumentNamespace($namespaceAlias) 
  112
+            . '\\' . $simpleClassName;
  113
+    }
  114
+
  115
+    /**
  116
+     * {@inheritdoc}
  117
+     * 
  118
+     * @todo unclear usage of rootEntityFound
1
Lukas Kahwe Smith Collaborator

@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
Lukas Kahwe Smith lsmith77 commented on the diff December 25, 2011
lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php
... ...
@@ -1,278 +1,141 @@
2
Lukas Kahwe Smith Collaborator

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

Fixed :)

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

needs line ending fixing

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))
  37
+
  38
+    public static function classIsNotAValidDocument($className)
  39
+    {
  40
+        return new self('Class '.$className.' is not a valid document or mapped super class.');
  41
+    }
  42
+
  43
+    public static function reflectionFailure($document, \ReflectionException $previousException)
  44
+    {
  45
+        return new self('An error occurred in ' . $document, 0, $previousException);
  46
+    }
  47
+
  48
+    /**
  49
+     * @param string $document The document's name
  50
+     * @param string $fieldName The name of the field that was already declared
  51
+     */
  52
+    public static function duplicateFieldMapping($document, $fieldName) {
1
Lukas Kahwe Smith Collaborator

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))
  45
+        return new self('An error occurred in ' . $document, 0, $previousException);
  46
+    }
  47
+
  48
+    /**
  49
+     * @param string $document The document's name
  50
+     * @param string $fieldName The name of the field that was already declared
  51
+     */
  52
+    public static function duplicateFieldMapping($document, $fieldName) {
  53
+        return new self('Property "'.$fieldName.'" in "'.$document.'" was already declared, but it must be declared only once');
  54
+    }
  55
+
  56
+    /**
  57
+     * @param string $document The document's name
  58
+     * @param string $fieldName The name of the field that was already declared
  59
+     */
  60
+    public static function missingTypeDefinition($document, $fieldName) {
1
Lukas Kahwe Smith Collaborator

opening bracket is off ..

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

line endings need fixing

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))
  156
+     *
  157
+     * @param Cache $metadataCacheImpl
  158
+     */
  159
+    public function setMetadataCacheImpl(Cache $metadataCacheImpl)
  160
+    {
  161
+        $this->attributes['metadataCacheImpl'] = $metadataCacheImpl;
  162
+    }
  163
+
  164
+    /**
  165
+     * Gets the cache driver implementation that is used for the mapping metadata.
  166
+     *
  167
+     * @return Cache|null
  168
+     */
  169
+    public function getMetadataCacheImpl()
  170
+    {
  171
+        if($this->attributes['metadataCacheImpl'] === null) {
2
Lukas Kahwe Smith Collaborator

missing space after if

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))
  50
+
  51
+    /**
  52
+     *  The used metadata driver.
  53
+     *
  54
+     * @var \Doctrine\ODM\PHPCR\Mapping\Driver\Driver
  55
+     */
  56
+    private $driver;
  57
+
  58
+    /**
  59
+     * Creates a new factory instance that uses the given DocumentManager instance.
  60
+     *
  61
+     * @param $dm The DocumentManager instance
  62
+     */
  63
+    public function __construct(DocumentManager $dm)
  64
+    {
  65
+        $this->dm     = $dm;
1
Lukas Kahwe Smith Collaborator

extra whitespace should be removed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Lukas Kahwe Smith
Collaborator

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

David Buchmann
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...

Lukas Kahwe Smith
Collaborator

@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.

Marco Pivetta

@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 :( )

Marco Pivetta

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...

Lukas Kahwe Smith lsmith77 commented on the diff December 26, 2011
lib/Doctrine/ODM/PHPCR/Configuration.php
@@ -19,6 +19,7 @@
19 19
 
20 20
 namespace Doctrine\ODM\PHPCR;
21 21
 
  22
+use Doctrine\Common\Cache\Cache;
2
Lukas Kahwe Smith Collaborator

this can probably be removed?

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
Lukas Kahwe Smith
Collaborator

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))
127 77
     {
128  
-        if (isset($this->loadedAliases[$alias])) {
129  
-            return $this->loadedAliases[$alias];
  78
+        if ($metadata = parent::getMetadataFor($className)) {
1
Lukas Kahwe Smith Collaborator

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
Marco Pivetta

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

Lukas Kahwe Smith lsmith77 merged commit 5842eb3 into from December 28, 2011
Lukas Kahwe Smith lsmith77 closed this December 28, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
30  lib/Doctrine/ODM/PHPCR/Configuration.php
@@ -19,6 +19,7 @@
19 19
 
20 20
 namespace Doctrine\ODM\PHPCR;
21 21
 
  22
+use Doctrine\Common\Cache\Cache;
22 23
 use Doctrine\ODM\PHPCR\Mapping\Driver\Driver;
23 24
 use Doctrine\ODM\PHPCR\Mapping\Driver\BuiltinDocumentsDriver;
24 25
 use Doctrine\ODM\PHPCR\DocumentClassMapperInterface;
@@ -44,9 +45,10 @@ class Configuration
44 45
         'writeDoctrineMetadata' => true,
45 46
         'validateDoctrineMetadata' => true,
46 47
         'metadataDriverImpl' => null,
  48
+        'metadataCacheImpl' => null,
47 49
         'documentClassMapper' => null,
48 50
         'proxyNamespace' => 'MyPHPCRProxyNS',
49  
-        'autoGenerateProxyClasses' => true
  51
+        'autoGenerateProxyClasses' => true,
50 52
     );
51 53
 
52 54
     /**
@@ -128,7 +130,7 @@ public function setDocumentNamespaces(array $documentNamespaces)
128 130
     }
129 131
 
130 132
     /**
131  
-     * Sets the cache driver implementation that is used for metadata caching.
  133
+     * Sets the driver implementation that is used to retrieve mapping metadata.
132 134
      *
133 135
      * @param Driver $driverImpl
134 136
      * @todo Force parameter to be a Closure to ensure lazy evaluation
@@ -140,7 +142,7 @@ public function setMetadataDriverImpl(Driver $driverImpl)
140 142
     }
141 143
 
142 144
     /**
143  
-     * Gets the cache driver implementation that is used for the mapping metadata.
  145
+     * Gets the driver implementation that is used to retrieve mapping metadata.
144 146
      *
145 147
      * @return Mapping\Driver\Driver
146 148
      */
@@ -150,6 +152,26 @@ public function getMetadataDriverImpl()
150 152
     }
151 153
 
152 154
     /**
  155
+     * Sets the cache driver implementation that is used for metadata caching.
  156
+     *
  157
+     * @param Cache $metadataCacheImpl
  158
+     */
  159
+    public function setMetadataCacheImpl(Cache $metadataCacheImpl)
  160
+    {
  161
+        $this->attributes['metadataCacheImpl'] = $metadataCacheImpl;
  162
+    }
  163
+
  164
+    /**
  165
+     * Gets the cache driver implementation that is used for the mapping metadata.
  166
+     *
  167
+     * @return Cache|null
  168
+     */
  169
+    public function getMetadataCacheImpl()
  170
+    {
  171
+        return $this->attributes['metadataCacheImpl'];
  172
+    }
  173
+
  174
+    /**
153 175
      * Gets the cache driver implementation that is used for metadata caching.
154 176
      *
155 177
      * @return \Doctrine\ODM\PHPCR\DocumentClassMapperInterface
@@ -237,4 +259,4 @@ public function getAutoGenerateProxyClasses()
237 259
     {
238 260
         return $this->attributes['autoGenerateProxyClasses'];
239 261
     }
240  
-}
  262
+}
238  lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadataFactory.php
@@ -19,10 +19,10 @@
19 19
 
20 20
 namespace Doctrine\ODM\PHPCR\Mapping;
21 21
 
22  
-use Doctrine\ODM\PHPCR\DocumentManager,
23  
-    Doctrine\ODM\PHPCR\Mapping\ClassMetadata,
24  
-    Doctrine\ODM\PHPCR\PHPCRException,
25  
-    Doctrine\Common\Cache\Cache;
  22
+use Doctrine\ODM\PHPCR\DocumentManager;
  23
+use Doctrine\ODM\PHPCR\Mapping\ClassMetadata;
  24
+use Doctrine\ODM\PHPCR\PHPCRException;
  25
+use Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory;
26 26
 
27 27
 /**
28 28
  * The ClassMetadataFactory is used to create ClassMetadata objects that contain all the
@@ -35,244 +35,106 @@
35 35
  * @author      Benjamin Eberlei <kontakt@beberlei.de>
36 36
  * @author      Lukas Kahwe Smith <smith@pooteeweet.org>
37 37
  */
38  
-class ClassMetadataFactory
  38
+class ClassMetadataFactory extends AbstractClassMetadataFactory
39 39
 {
40  
-    /**
41  
-     * @var DocumentManager
42  
-     */
43  
-    private $dm;
44 40
 
45 41
     /**
46  
-     * @var array
  42
+     * {@inheritdoc}
47 43
      */
48  
-    private $loadedMetadata = array();
49  
-
  44
+    protected $cacheSalt = '\$PHPCRODMCLASSMETADATA';
  45
+    
50 46
     /**
51  
-     * @var array
  47
+     * @var DocumentManager
52 48
      */
53  
-    private $loadedAliases = array();
  49
+    private $dm;
54 50
 
55 51
     /**
56 52
      *  The used metadata driver.
57 53
      *
58  
-     * @var Doctrine\ODM\PHPCR\Mapping\Driver\Driver
  54
+     * @var \Doctrine\ODM\PHPCR\Mapping\Driver\Driver
59 55
      */
60 56
     private $driver;
61 57
 
62 58
     /**
63  
-     * The used cache driver.
64  
-     *
65  
-     * @var Cache
66  
-     */
67  
-    private $cacheDriver;
68  
-
69  
-    /**
70 59
      * Creates a new factory instance that uses the given DocumentManager instance.
71 60
      *
72  
-     * @param $dm  The DocumentManager instance
  61
+     * @param $dm The DocumentManager instance
73 62
      */
74 63
     public function __construct(DocumentManager $dm)
75 64
     {
76 65
         $this->dm = $dm;
77  
-        $this->driver = $this->dm->getConfiguration()->getMetadataDriverImpl();
78  
-    }
79  
-
80  
-    /**
81  
-     * Sets the cache driver used by the factory to cache ClassMetadata instances.
82  
-     *
83  
-     * @param Doctrine\Common\Cache\Cache $cacheDriver
84  
-     */
85  
-    public function setCacheDriver($cacheDriver)
86  
-    {
87  
-        $this->cacheDriver = $cacheDriver;
  66
+        $conf = $this->dm->getConfiguration();
  67
+        $this->setCacheDriver($conf->getMetadataCacheImpl());
  68
+        $this->driver = $conf->getMetadataDriverImpl();
88 69
     }
89 70
 
90 71
     /**
91  
-     * Gets the cache driver used by the factory to cache ClassMetadata instances.
92  
-     *
93  
-     * @return Doctrine\Common\Cache\Cache
  72
+     * {@inheritdoc}
  73
+     * 
  74
+     * @throws MappingException
94 75
      */
95  
-    public function getCacheDriver()
96  
-    {
97  
-        return $this->cacheDriver;
98  
-    }
99  
-
100  
-    /**
101  
-     * Gets the array of loaded ClassMetadata instances.
102  
-     *
103  
-     * @return array $loadedMetadata The loaded metadata.
104  
-     */
105  
-    public function getLoadedMetadata()
106  
-    {
107  
-        return $this->loadedMetadata;
108  
-    }
109  
-
110  
-    /**
111  
-     * Forces the factory to load the metadata of all classes known to the underlying
112  
-     * mapping driver.
113  
-     *
114  
-     * @return array The ClassMetadata instances of all mapped classes.
115  
-     */
116  
-    public function getAllMetadata()
117  
-    {
118  
-        $metadata = array();
119  
-        foreach ($this->driver->getAllClassNames() as $className) {
120  
-            $metadata[] = $this->getMetadataFor($className);
121  
-        }
122  
-
123  
-        return $metadata;
124  
-    }
125  
-
126  
-    public function getMetadataForAlias($alias)
  76
+    public function getMetadataFor($className)
127 77
     {
128  
-        if (isset($this->loadedAliases[$alias])) {
129  
-            return $this->loadedAliases[$alias];
  78
+        $metadata = parent::getMetadataFor($className);
  79
+        if ($metadata) {
  80
+            return $metadata;
130 81
         }
131  
-
132  
-        if ($this->cacheDriver && ($cached = $this->cacheDriver->fetch("$alias\$PHPCRODMALIAS")) !== false) {
133  
-            return $this->loadedAliases[$alias] = $cached;
134  
-        }
135  
-
136  
-        foreach ($this->loadedMetadata as $metadata) {
137  
-            if ($metadata->alias === $alias) {
138  
-                $this->loadedAliases[$alias] = $metadata;
139  
-                if ($this->cacheDriver) {
140  
-                    $this->cacheDriver->save(
141  
-                        "$alias\$PHPCRODMALIAS", $this->loadedAliases[$alias], null
142  
-                    );
143  
-                }
144  
-                return $metadata;
145  
-            }
146  
-        }
147  
-
148  
-        foreach ($this->driver->getAllClassNames() as $className) {
149  
-            $metadata = $this->getMetadataFor($className);
150  
-            if ($metadata->alias === $alias) {
151  
-                $this->loadedAliases[$alias] = $metadata;
152  
-                if ($this->cacheDriver) {
153  
-                    $this->cacheDriver->save(
154  
-                        "$alias\$PHPCRODMALIAS", $this->loadedAliases[$alias], null
155  
-                    );
156  
-                }
157  
-                return $metadata;
158  
-            }
159  
-        }
160  
-
161  
-        throw new MappingException('Alias '.$alias.' could not be resolved to a document class name');
  82
+        throw MappingException::classNotMapped($className);
162 83
     }
163 84
 
164 85
     /**
165  
-     * Gets the class metadata descriptor for a class.
166  
-     *
167  
-     * @param string $className The name of the class.
168  
-     * @return Doctrine\ODM\PHPCR\Mapping\ClassMetadata
  86
+     * {@inheritdoc}
  87
+     * 
  88
+     * @throws MappingException
169 89
      */
170  
-    public function getMetadataFor($className)
  90
+    function loadMetadata($className)
171 91
     {
172  
-        if (!isset($this->loadedMetadata[$className])) {
173  
-            $realClassName = $className;
174  
-
175  
-            // Check for namespace alias
176  
-            if (strpos($className, ':') !== false) {
177  
-                list($namespaceAlias, $simpleClassName) = explode(':', $className);
178  
-                $realClassName = $this->dm->getConfiguration()->getDocumentNamespace($namespaceAlias) . '\\' . $simpleClassName;
179  
-
180  
-                if (isset($this->loadedMetadata[$realClassName])) {
181  
-                    // We do not have the alias name in the map, include it
182  
-                    $this->loadedMetadata[$className] = $this->loadedMetadata[$realClassName];
183  
-
184  
-                    return $this->loadedMetadata[$realClassName];
185  
-                }
186  
-            }
187  
-
188  
-            if ($this->cacheDriver) {
189  
-                if (($cached = $this->cacheDriver->fetch("$realClassName\$PHPCRODMCLASSMETADATA")) !== false) {
190  
-                    $this->loadedMetadata[$realClassName] = $cached;
191  
-                } else {
192  
-                    foreach ($this->loadMetadata($realClassName) as $loadedClassName) {
193  
-                        $this->cacheDriver->save(
194  
-                            "$loadedClassName\$PHPCRODMCLASSMETADATA", $this->loadedMetadata[$loadedClassName], null
195  
-                        );
196  
-                    }
197  
-                }
198  
-            } else {
199  
-                $this->loadMetadata($realClassName);
200  
-            }
201  
-
202  
-            if ($className != $realClassName) {
203  
-                // We do not have the alias name in the map, include it
204  
-                $this->loadedMetadata[$className] = $this->loadedMetadata[$realClassName];
205  
-            }
  92
+        if (class_exists($className)) {
  93
+            return parent::loadMetadata($className);
206 94
         }
207  
-
208  
-        if (!isset($this->loadedMetadata[$className])) {
209  
-            throw MappingException::classNotMapped();
210  
-        }
211  
-
212  
-        return $this->loadedMetadata[$className];
  95
+        throw MappingException::classNotFound($className);
213 96
     }
214 97
 
  98
+
215 99
     /**
216  
-     * Loads the metadata of the class in question and all it's ancestors whose metadata
217  
-     * is still not loaded.
218  
-     *
219  
-     * @param string $className The name of the class for which the metadata should get loaded.
  100
+     * {@inheritdoc}
220 101
      */
221  
-    private function loadMetadata($className)
  102
+    protected function newClassMetadataInstance($className)
222 103
     {
223  
-        if (!class_exists($className)) {
224  
-            throw MappingException::classNotFound($className);
225  
-        }
226  
-
227  
-        $this->loadedMetadata[$className] = new ClassMetadata($className);
228  
-        $this->driver->loadMetadataForClass($className, $this->loadedMetadata[$className]);
  104
+        return new ClassMetadata($className);
229 105
     }
230  
-
  106
+    
231 107
     /**
232  
-     * Checks whether the factory has the metadata for a class loaded already.
233  
-     *
234  
-     * @param string $className
235  
-     * @return boolean TRUE if the metadata of the class in question is already loaded, FALSE otherwise.
  108
+     * {@inheritdoc}
236 109
      */
237  
-    public function hasMetadataFor($className)
  110
+    protected function getFqcnFromAlias($namespaceAlias, $simpleClassName)
238 111
     {
239  
-        return isset($this->loadedMetadata[$className]);
  112
+        return $this->dm->getConfiguration()->getDocumentNamespace($namespaceAlias) 
  113
+            . '\\' . $simpleClassName;
240 114
     }
241 115
 
242 116
     /**
243  
-     * Sets the metadata descriptor for a specific class.
244  
-     *
245  
-     * NOTE: This is only useful in very special cases, like when generating proxy classes.
246  
-     *
247  
-     * @param string $className
248  
-     * @param ClassMetadata $class
  117
+     * {@inheritdoc}
249 118
      */
250  
-    public function setMetadataFor($className, $class)
  119
+    protected function doLoadMetadata($class, $parent, $rootEntityFound)
251 120
     {
252  
-        $this->loadedMetadata[$className] = $class;
  121
+        $this->getDriver()->loadMetadataForClass($class->getName(), $class);
253 122
     }
254 123
 
255 124
     /**
256  
-     * Creates a new ClassMetadata instance for the given class name.
257  
-     *
258  
-     * @param string $className
259  
-     * @return Doctrine\ODM\PHPCR\Mapping\ClassMetadata
  125
+     * {@inheritdoc}
260 126
      */
261  
-    protected function newClassMetadataInstance($className)
  127
+    protected function getDriver()
262 128
     {
263  
-        return new ClassMetadata($className);
  129
+        return $this->driver;
264 130
     }
265 131
 
266 132
     /**
267  
-     * Whether the class with the specified name should have its metadata loaded.
268  
-     * This is only the case if it is either mapped as an Entity or a
269  
-     * MappedSuperclass.
270  
-     *
271  
-     * @param string $className
272  
-     * @return boolean
  133
+     * {@inheritdoc}
273 134
      */
274  
-    public function isTransient($className)
  135
+    protected function initialize()
275 136
     {
276  
-        return $this->driver->isTransient($className);
  137
+        $this->initialized = true;
277 138
     }
278  
-}
  139
+    
  140
+}
231  lib/Doctrine/ODM/PHPCR/Mapping/Driver/AnnotationDriver.php
@@ -21,9 +21,10 @@
21 21
 
22 22
 use Doctrine\Common\Annotations\AnnotationReader,
23 23
     Doctrine\Common\Annotations\Reader,
  24
+    Doctrine\Common\Persistence\Mapping\Driver\AnnotationDriver as AbstractAnnotationDriver,
  25
+    Doctrine\Common\Persistence\Mapping\ClassMetadata,
24 26
     Doctrine\ODM\PHPCR\Event,
25 27
     Doctrine\ODM\PHPCR\Mapping\Annotations as ODM,
26  
-    Doctrine\ODM\PHPCR\Mapping\ClassMetadata,
27 28
     Doctrine\ODM\PHPCR\Mapping\MappingException;
28 29
 
29 30
 /**
@@ -37,87 +38,29 @@
37 38
  * @author      Daniel Barsotti <daniel.barsotti@liip.ch>
38 39
  * @author      David Buchmann <david@liip.ch>
39 40
  */
40  
-class AnnotationDriver implements Driver
  41
+class AnnotationDriver extends AbstractAnnotationDriver implements Driver
41 42
 {
42  
-    /**
43  
-     * The AnnotationReader.
44  
-     *
45  
-     * @var AnnotationReader
46  
-     */
47  
-    private $reader;
48  
-
49  
-    /**
50  
-     * The paths where to look for mapping files.
51  
-     *
52  
-     * @var array
53  
-     */
54  
-    private $paths = array();
55  
-
56  
-    /**
57  
-     * The file extension of mapping documents.
58  
-     *
59  
-     * @var string
60  
-     */
61  
-    private $fileExtension = '.php';
62  
-
63  
-    /**
64  
-     * @param array
65  
-     */
66  
-    private $classNames;
67 43
 
68 44
     /**
  45
+     * {@inheritdoc}
  46
+     * 
69 47
      * Document annotation classes, ordered by precedence.
70 48
      */
71  
-    static private $documentAnnotationClasses = array(
72  
-        'Doctrine\\ODM\\PHPCR\\Mapping\\Annotations\\Document',
73  
-        'Doctrine\\ODM\\PHPCR\\Mapping\\Annotations\\MappedSuperclass',
  49
+    protected $entityAnnotationClasses = array(
  50
+        'Doctrine\\ODM\\PHPCR\\Mapping\\Annotations\\Document' => 0,
  51
+        'Doctrine\\ODM\\PHPCR\\Mapping\\Annotations\\MappedSuperclass' => 1,
74 52
     );
75 53
 
76 54
     /**
77  
-     * Initializes a new AnnotationDriver that uses the given AnnotationReader for reading
78  
-     * docblock annotations.
79  
-     *
80  
-     * @param $reader The AnnotationReader to use.
81  
-     * @param string|array $paths One or multiple paths where mapping classes can be found.
82  
-     */
83  
-    public function __construct(Reader $reader, $paths = null)
84  
-    {
85  
-        $this->reader = $reader;
86  
-        if ($paths) {
87  
-            $this->addPaths((array) $paths);
88  
-        }
89  
-    }
90  
-
91  
-    /**
92  
-     * Append lookup paths to metadata driver.
93  
-     *
94  
-     * @param array $paths
95  
-     */
96  
-    public function addPaths(array $paths)
97  
-    {
98  
-        $this->paths = array_unique(array_merge($this->paths, $paths));
99  
-    }
100  
-
101  
-    /**
102  
-     * Retrieve the defined metadata lookup paths.
103  
-     *
104  
-     * @return array
105  
-     */
106  
-    public function getPaths()
107  
-    {
108  
-        return $this->paths;
109  
-    }
110  
-
111  
-    /**
112 55
      * {@inheritdoc}
113 56
      */
114  
-    public function loadMetadataForClass($className, ClassMetadata $class)
  57
+    public function loadMetadataForClass($className, ClassMetadata $metadata)
115 58
     {
116  
-        $reflClass = $class->getReflectionClass();
  59
+        $reflClass = $metadata->getReflectionClass();
117 60
 
118 61
         $documentAnnots = array();
119 62
         foreach ($this->reader->getClassAnnotations($reflClass) as $annot) {
120  
-            foreach (self::$documentAnnotationClasses as $i => $annotClass) {
  63
+            foreach ($this->entityAnnotationClasses as $annotClass => $i) {
121 64
                 if ($annot instanceof $annotClass) {
122 65
                     $documentAnnots[$i] = $annot;
123 66
                 }
@@ -135,22 +78,22 @@ public function loadMetadataForClass($className, ClassMetadata $class)
135 78
             throw new MappingException("Alias must be specified in the Document() annotation mapping of $className");
136 79
         }
137 80
 
138  
-        $class->setAlias($documentAnnot->alias);
  81
+        $metadata->setAlias($documentAnnot->alias);
139 82
         if (isset($documentAnnot->versionable) && $documentAnnot->versionable) {
140  
-            $class->setVersioned(true);
  83
+            $metadata->setVersioned(true);
141 84
         }
142  
-        $class->setNodeType($documentAnnot->nodeType);
  85
+        $metadata->setNodeType($documentAnnot->nodeType);
143 86
 
144 87
         if (isset($documentAnnot->referenceable) && $documentAnnot->referenceable) {
145  
-            $class->setReferenceable(true);
  88
+            $metadata->setReferenceable(true);
146 89
         }
147 90
 
148 91
         if ($documentAnnot->repositoryClass) {
149  
-            $class->setCustomRepositoryClassName($documentAnnot->repositoryClass);
  92
+            $metadata->setCustomRepositoryClassName($documentAnnot->repositoryClass);
150 93
         }
151 94
 
152 95
         if ($documentAnnot->translator) {
153  
-            $class->setTranslator($documentAnnot->translator);
  96
+            $metadata->setTranslator($documentAnnot->translator);
154 97
         }
155 98
 
156 99
         foreach ($reflClass->getProperties() as $property) {
@@ -158,39 +101,39 @@ public function loadMetadataForClass($className, ClassMetadata $class)
158 101
             $mapping['fieldName'] = $property->getName();
159 102
 
160 103
             foreach ($this->reader->getPropertyAnnotations($property) as $fieldAnnot) {
161  
-                if ($fieldAnnot instanceof \Doctrine\ODM\PHPCR\Mapping\Annotations\Property) {
  104
+                if ($fieldAnnot instanceof ODM\Property) {
162 105
                     $mapping = array_merge($mapping, (array) $fieldAnnot);
163  
-                    $class->mapField($mapping);
164  
-                } elseif ($fieldAnnot instanceof \Doctrine\ODM\PHPCR\Mapping\Annotations\Id) {
  106
+                    $metadata->mapField($mapping);
  107
+                } elseif ($fieldAnnot instanceof ODM\Id) {
165 108
                     $mapping = array_merge($mapping, (array) $fieldAnnot);
166  
-                    $class->mapId($mapping);
167  
-                } elseif ($fieldAnnot instanceof \Doctrine\ODM\PHPCR\Mapping\Annotations\Node) {
  109
+                    $metadata->mapId($mapping);
  110
+                } elseif ($fieldAnnot instanceof ODM\Node) {
168 111
                     $mapping = array_merge($mapping, (array) $fieldAnnot);
169  
-                    $class->mapNode($mapping);
170  
-                } elseif ($fieldAnnot instanceof \Doctrine\ODM\PHPCR\Mapping\Annotations\Nodename) {
  112
+                    $metadata->mapNode($mapping);
  113
+                } elseif ($fieldAnnot instanceof ODM\Nodename) {
171 114
                     $mapping = array_merge($mapping, (array) $fieldAnnot);
172  
-                    $class->mapNodename($mapping);
173  
-                } elseif ($fieldAnnot instanceof \Doctrine\ODM\PHPCR\Mapping\Annotations\ParentDocument) {
  115
+                    $metadata->mapNodename($mapping);
  116
+                } elseif ($fieldAnnot instanceof ODM\ParentDocument) {
174 117
                     $mapping = array_merge($mapping, (array) $fieldAnnot);
175  
-                    $class->mapParentDocument($mapping);
176  
-                } elseif ($fieldAnnot instanceof \Doctrine\ODM\PHPCR\Mapping\Annotations\Child) {
  118
+                    $metadata->mapParentDocument($mapping);
  119
+                } elseif ($fieldAnnot instanceof ODM\Child) {
177 120
                     $mapping = array_merge($mapping, (array) $fieldAnnot);
178  
-                    $class->mapChild($mapping);
179  
-                } elseif ($fieldAnnot instanceof \Doctrine\ODM\PHPCR\Mapping\Annotations\Children) {
  121
+                    $metadata->mapChild($mapping);
  122
+                } elseif ($fieldAnnot instanceof ODM\Children) {
180 123
                     $mapping = array_merge($mapping, (array) $fieldAnnot);
181  
-                    $class->mapChildren($mapping);
182  
-                } elseif ($fieldAnnot instanceof \Doctrine\ODM\PHPCR\Mapping\Annotations\ReferenceOne) {
  124
+                    $metadata->mapChildren($mapping);
  125
+                } elseif ($fieldAnnot instanceof ODM\ReferenceOne) {
183 126
                     $mapping = array_merge($mapping, (array) $fieldAnnot);
184  
-                    $class->mapManyToOne($mapping);
185  
-                } elseif ($fieldAnnot instanceof \Doctrine\ODM\PHPCR\Mapping\Annotations\ReferenceMany) {
  127
+                    $metadata->mapManyToOne($mapping);
  128
+                } elseif ($fieldAnnot instanceof ODM\ReferenceMany) {
186 129
                     $mapping = array_merge($mapping, (array) $fieldAnnot);
187  
-                    $class->mapManyToMany($mapping);
188  
-                } elseif ($fieldAnnot instanceof \Doctrine\ODM\PHPCR\Mapping\Annotations\Referrers) {
  130
+                    $metadata->mapManyToMany($mapping);
  131
+                } elseif ($fieldAnnot instanceof ODM\Referrers) {
189 132
                     $mapping = array_merge($mapping, (array) $fieldAnnot);
190  
-                    $class->mapReferrers($mapping);
191  
-                } elseif ($fieldAnnot instanceof \Doctrine\ODM\PHPCR\Mapping\Annotations\Locale) {
  133
+                    $metadata->mapReferrers($mapping);
  134
+                } elseif ($fieldAnnot instanceof ODM\Locale) {
192 135
                     $mapping = array_merge($mapping, (array) $fieldAnnot);
193  
-                    $class->mapLocale($mapping);
  136
+                    $metadata->mapLocale($mapping);
194 137
                 }
195 138
 
196 139
                 if (!isset($mapping['name'])) {
@@ -203,106 +146,32 @@ public function loadMetadataForClass($className, ClassMetadata $class)
203 146
             if ($method->isPublic()) {
204 147
                 foreach ($this->reader->getMethodAnnotations($method) as $annot) {
205 148
                     if ($annot instanceof ODM\PrePersist) {
206  
-                        $class->addLifecycleCallback($method->getName(), \Doctrine\ODM\PHPCR\Event::prePersist);
  149
+                        $metadata->addLifecycleCallback($method->getName(), Event::prePersist);
207 150
                     } elseif ($annot instanceof  ODM\PostPersist) {
208  
-                        $class->addLifecycleCallback($method->getName(), \Doctrine\ODM\PHPCR\Event::postPersist);
  151
+                        $metadata->addLifecycleCallback($method->getName(), Event::postPersist);
209 152
                     } elseif ($annot instanceof ODM\PreUpdate) {
210  
-                        $class->addLifecycleCallback($method->getName(), \Doctrine\ODM\PHPCR\Event::preUpdate);
  153
+                        $metadata->addLifecycleCallback($method->getName(), Event::preUpdate);
211 154
                     } elseif ($annot instanceof ODM\PostUpdate) {
212  
-                        $class->addLifecycleCallback($method->getName(), \Doctrine\ODM\PHPCR\Event::postUpdate);
  155
+                        $metadata->addLifecycleCallback($method->getName(), Event::postUpdate);
213 156
                     } elseif ($annot instanceof ODM\PreRemove) {
214  
-                        $class->addLifecycleCallback($method->getName(), \Doctrine\ODM\PHPCR\Event::preRemove);
  157
+                        $metadata->addLifecycleCallback($method->getName(), Event::preRemove);
215 158
                     } elseif ($annot instanceof ODM\PostRemove) {
216  
-                        $class->addLifecycleCallback($method->getName(), \Doctrine\ODM\PHPCR\Event::postRemove);
  159
+                        $metadata->addLifecycleCallback($method->getName(), Event::postRemove);
217 160
                     } elseif ($annot instanceof ODM\PreLoad) {
218  
-                        $class->addLifecycleCallback($method->getName(), \Doctrine\ODM\PHPCR\Event::preLoad);
  161
+                        $metadata->addLifecycleCallback($method->getName(), Event::preLoad);
219 162
                     } elseif ($annot instanceof  ODM\PostLoad) {
220  
-                        $class->addLifecycleCallback($method->getName(), \Doctrine\ODM\PHPCR\Event::postLoad);
  163
+                        $metadata->addLifecycleCallback($method->getName(), Event::postLoad);
221 164
                     }
222 165
                 }
223 166
             }
224 167
         }
225 168
 
226 169
         // Check there is a @Locale annotation for translatable documents
227  
-        if (count($class->translatableFields)) {
228  
-            if (!isset($class->localeMapping)) {
  170
+        if (count($metadata->translatableFields)) {
  171
+            if (!isset($metadata->localeMapping)) {
229 172
                 throw new MappingException("You must define a @Locale field for translatable document '$className'");
230 173
             }
231 174
         }
232 175
     }
233 176
 
234  
-    /**
235  
-     * Whether the class with the specified name is transient. Only non-transient
236  
-     * classes, that is entities and mapped superclasses, should have their metadata loaded.
237  
-     * A class is non-transient if it is annotated with either @Entity or
238  
-     * @MappedSuperclass in the class doc block.
239  
-     *
240  
-     * @param string $className
241  
-     * @return boolean
242  
-     */
243  
-    public function isTransient($className)
244  
-    {
245  
-        $rc = new \ReflectionClass($className);
246  
-
247  
-        if ($this->reader->getClassAnnotation($rc, 'Doctrine\ODM\PHPCR\Mapping\Annotations\Document')) {
248  
-            return false;
249  
-        }
250  
-
251  
-        if ($this->reader->getClassAnnotation($rc, 'Doctrine\ODM\PHPCR\Mapping\Annotations\MappedSuperclass')) {
252  
-            return false;
253  
-        }
254  
-
255  
-        return true;
256  
-    }
257  
-
258  
-    /**
259  
-     * {@inheritDoc}
260  
-     */
261  
-    public function getAllClassNames()
262  
-    {
263  
-        if ($this->classNames !== null) {
264  
-            return $this->classNames;
265  
-        }
266  
-
267  
-        if (!$this->paths) {
268  
-            throw MappingException::pathRequired();
269  
-        }
270  
-
271  
-        $classes = array();
272  
-        $includedFiles = array();
273  
-
274  
-        foreach ($this->paths as $path) {
275  
-            if (!is_dir($path)) {
276  
-                throw MappingException::fileMappingDriversRequireConfiguredDirectoryPath();
277  
-            }
278  
-
279  
-            $iterator = new \RecursiveIteratorIterator(
280  
-                new \RecursiveDirectoryIterator($path),
281  
-                \RecursiveIteratorIterator::LEAVES_ONLY
282  
-            );
283  
-
284  
-            foreach ($iterator as $file) {
285  
-                if (($file->getBasename($this->fileExtension)) == $file->getBasename()) {
286  
-                    continue;
287  
-                }
288  
-
289  
-                $sourceFile = realpath($file->getPathName());
290  
-                require_once $sourceFile;
291  
-                $includedFiles[] = $sourceFile;
292  
-            }
293  
-        }
294  
-
295  
-        $declared = get_declared_classes();
296  
-
297  
-        foreach ($declared as $className) {
298  
-            $rc = new \ReflectionClass($className);
299  
-            $sourceFile = $rc->getFileName();
300  
-            if (in_array($sourceFile, $includedFiles) && !$this->isTransient($className)) {
301  
-                $classes[] = $className;
302  
-            }
303  
-        }
304  
-        $this->classNames = $classes;
305  
-
306  
-        return $classes;
307  
-    }
308  
-}
  177
+}
4  lib/Doctrine/ODM/PHPCR/Mapping/Driver/BuiltinDocumentsDriver.php
@@ -3,7 +3,7 @@
3 3
 namespace Doctrine\ODM\PHPCR\Mapping\Driver;
4 4
 
5 5
 use Doctrine\Common\Annotations\AnnotationReader;
6  
-use Doctrine\ODM\PHPCR\Mapping\ClassMetadata;
  6
+use Doctrine\Common\Persistence\Mapping\ClassMetadata;
7 7
 use Doctrine\ODM\PHPCR\Mapping\MappingException;
8 8
 use Doctrine\ODM\PHPCR\Mapping\Driver\AnnotationDriver;
9 9
 
@@ -90,4 +90,4 @@ public function isTransient($className)
90 90
 
91 91
         return $this->wrappedDriver->isTransient($className);
92 92
     }
93  
-}
  93
+}
29  lib/Doctrine/ODM/PHPCR/Mapping/Driver/Driver.php
@@ -19,7 +19,7 @@
19 19
 
20 20
 namespace Doctrine\ODM\PHPCR\Mapping\Driver;
21 21
 
22  
-use Doctrine\ODM\PHPCR\Mapping\ClassMetadata;
  22
+use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
23 23
 
24 24
 /**
25 25
  * Contract for metadata drivers.
@@ -30,30 +30,7 @@
30 30
  * @author      Jonathan H. Wage <jonwage@gmail.com>
31 31
  * @author      Roman Borschel <roman@code-factory.org>
32 32
  */
33  
-interface Driver
  33
+interface Driver extends MappingDriver
34 34
 {
35  
-    /**
36  
-     * Loads the metadata for the specified class into the provided container.
37  
-     *
38  
-     * @param string $className
39  
-     * @param ClassMetadataInfo $metadata
40  
-     */
41  
-    function loadMetadataForClass($className, ClassMetadata $metadata);
42 35
 
43  
-    /**
44  
-     * Gets the names of all mapped classes known to this driver.
45  
-     *
46  
-     * @return array The names of all mapped classes known to this driver.
47  
-     */
48  
-    function getAllClassNames();
49  
-
50  
-    /**
51  
-     * Whether the class with the specified name should have its metadata loaded.
52  
-     * This is only the case if it is either mapped as an Document or a
53  
-     * MappedSuperclass.
54  
-     *
55  
-     * @param string $className
56  
-     * @return boolean
57  
-     */
58  
-    function isTransient($className);
59  
-}
  36
+}
4  lib/Doctrine/ODM/PHPCR/Mapping/Driver/DriverChain.php
@@ -2,7 +2,7 @@
2 2
 
3 3
 namespace Doctrine\ODM\PHPCR\Mapping\Driver;
4 4
 
5  
-use Doctrine\ODM\PHPCR\Mapping\ClassMetadata;
  5
+use Doctrine\Common\Persistence\Mapping\ClassMetadata;
6 6
 use Doctrine\ODM\PHPCR\Mapping\MappingException;
7 7
 
8 8
 /**
@@ -93,4 +93,4 @@ public function isTransient($className)
93 93
         // class isTransient, i.e. not an document or mapped superclass
94 94
         return true;
95 95
     }
96  
-}
  96
+}
2  lib/Doctrine/ODM/PHPCR/Mapping/Driver/PHPDriver.php
@@ -19,7 +19,7 @@
19 19
 
20 20
 namespace Doctrine\ODM\PHPCR\Mapping\Driver;
21 21
 
22  
-use Doctrine\ODM\PHPCR\Mapping\ClassMetadata;
  22
+use Doctrine\Common\Persistence\Mapping\ClassMetadata;
23 23
 
24 24
 /**
25 25
  * The PHPDriver invokes a static PHP function on the document class itself passing
4  lib/Doctrine/ODM/PHPCR/Mapping/Driver/XmlDriver.php
@@ -19,7 +19,7 @@
19 19
 
20 20
 namespace Doctrine\ODM\PHPCR\Mapping\Driver;
21 21
 
22  
-use Doctrine\ODM\PHPCR\Mapping\ClassMetadata;
  22
+use Doctrine\Common\Persistence\Mapping\ClassMetadata;
23 23
 use Doctrine\ODM\PHPCR\Mapping\MappingException;
24 24
 use SimpleXmlElement;
25 25
 
@@ -204,4 +204,4 @@ protected function loadMappingFile($file)
204 204
 
205 205
         return $result;
206 206
     }
207  
-}
  207
+}
6  lib/Doctrine/ODM/PHPCR/Mapping/Driver/YamlDriver.php
@@ -19,8 +19,8 @@
19 19
 
20 20
 namespace Doctrine\ODM\PHPCR\Mapping\Driver;
21 21
 
22  
-use Doctrine\ODM\PHPCR\Mapping\ClassMetadata,
23  
-    Doctrine\ODM\PHPCR\Mapping\MappingException;
  22
+use Doctrine\Common\Persistence\Mapping\ClassMetadata;
  23
+use Doctrine\ODM\PHPCR\Mapping\MappingException;
24 24
 
25 25
 /**
26 26
  * The YamlDriver reads the mapping metadata from yaml schema files.
@@ -194,4 +194,4 @@ protected function loadMappingFile($file)
194 194
     {
195 195
         return \Symfony\Component\Yaml\Yaml::parse($file);
196 196
     }
197  
-}
  197
+}
12  lib/Doctrine/ODM/PHPCR/Mapping/MappingException.php
@@ -49,7 +49,8 @@ public static function reflectionFailure($document, \ReflectionException $previo
49 49
      * @param string $document The document's name
50 50
      * @param string $fieldName The name of the field that was already declared
51 51
      */
52  
-    public static function duplicateFieldMapping($document, $fieldName) {
  52
+    public static function duplicateFieldMapping($document, $fieldName)
  53
+    {
53 54
         return new self('Property "'.$fieldName.'" in "'.$document.'" was already declared, but it must be declared only once');
54 55
     }
55 56
 
@@ -57,7 +58,8 @@ public static function duplicateFieldMapping($document, $fieldName) {
57 58
      * @param string $document The document's name
58 59
      * @param string $fieldName The name of the field that was already declared
59 60
      */