Skip to content

Commit 583f6fd

Browse files
committed
Refactored the mapping drivers to use the base drivers from Common
1 parent eba5d74 commit 583f6fd

File tree

11 files changed

+63
-451
lines changed

11 files changed

+63
-451
lines changed

lib/Doctrine/ODM/MongoDB/Configuration.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
namespace Doctrine\ODM\MongoDB;
2121

22-
use Doctrine\ODM\MongoDB\Mapping\Driver\Driver,
22+
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver,
2323
Doctrine\ODM\MongoDB\Mapping\Driver\PHPDriver,
2424
Doctrine\Common\Cache\Cache;
2525

@@ -82,11 +82,11 @@ public function setDocumentNamespaces(array $documentNamespaces)
8282
/**
8383
* Sets the cache driver implementation that is used for metadata caching.
8484
*
85-
* @param Driver $driverImpl
85+
* @param MappingDriver $driverImpl
8686
* @todo Force parameter to be a Closure to ensure lazy evaluation
8787
* (as soon as a metadata cache is in effect, the driver never needs to initialize).
8888
*/
89-
public function setMetadataDriverImpl(Driver $driverImpl)
89+
public function setMetadataDriverImpl(MappingDriver $driverImpl)
9090
{
9191
$this->attributes['metadataDriverImpl'] = $driverImpl;
9292
}
@@ -107,7 +107,7 @@ public function newDefaultAnnotationDriver($paths = array())
107107
/**
108108
* Gets the cache driver implementation that is used for the mapping metadata.
109109
*
110-
* @return Mapping\Driver\Driver
110+
* @return MappingDriver
111111
*/
112112
public function getMetadataDriverImpl()
113113
{

lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class ClassMetadataFactory extends AbstractClassMetadataFactory
5151
/** @var Configuration The Configuration instance */
5252
private $config;
5353

54-
/** @var \Doctrine\ODM\MongoDB\Mapping\Driver\Driver The used metadata driver. */
54+
/** @var \Doctrine\Common\Persistence\Mapping\Driver\MappingDriver The used metadata driver. */
5555
private $driver;
5656

5757
/** @var \Doctrine\Common\EventManager The event manager instance */

lib/Doctrine/ODM/MongoDB/Mapping/Driver/AnnotationDriver.php

Lines changed: 9 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
use Doctrine\Common\Annotations\AnnotationReader,
2323
Doctrine\Common\Annotations\AnnotationRegistry,
2424
Doctrine\Common\Annotations\Reader,
25+
Doctrine\Common\Persistence\Mapping\ClassMetadata,
26+
Doctrine\Common\Persistence\Mapping\Driver\AnnotationDriver as AbstractAnnotationDriver,
2527
Doctrine\ODM\MongoDB\Events,
2628
Doctrine\ODM\MongoDB\Mapping\Annotations as ODM,
2729
Doctrine\ODM\MongoDB\Mapping\ClassMetadataInfo,
@@ -36,43 +38,14 @@
3638
* @author Jonathan H. Wage <jonwage@gmail.com>
3739
* @author Roman Borschel <roman@code-factory.org>
3840
*/
39-
class AnnotationDriver implements Driver
41+
class AnnotationDriver extends AbstractAnnotationDriver
4042
{
41-
/**
42-
* Document annotation classes, ordered by precedence.
43-
*/
44-
static private $documentAnnotationClasses = array(
45-
'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\Document',
46-
'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\MappedSuperclass',
47-
'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\EmbeddedDocument',
43+
protected $entityAnnotationClasses = array(
44+
'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\Document' => 1,
45+
'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\MappedSuperclass' => 2,
46+
'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\EmbeddedDocument' => 3,
4847
);
4948

50-
/**
51-
* The annotation reader.
52-
*
53-
* @var Reader
54-
*/
55-
private $reader;
56-
57-
/**
58-
* The paths where to look for mapping files.
59-
*
60-
* @var array
61-
*/
62-
private $paths = array();
63-
64-
/**
65-
* The file extension of mapping documents.
66-
*
67-
* @var string
68-
*/
69-
private $fileExtension = '.php';
70-
71-
/**
72-
* @param array
73-
*/
74-
private $classNames;
75-
7649
/**
7750
* Registers annotation classes to the common registry.
7851
*
@@ -83,56 +56,12 @@ public static function registerAnnotationClasses()
8356
AnnotationRegistry::registerFile(__DIR__ . '/../Annotations/DoctrineAnnotations.php');
8457
}
8558

86-
/**
87-
* Initializes a new AnnotationDriver that uses the given Reader for reading
88-
* docblock annotations.
89-
*
90-
* @param $reader Reader The annotation reader to use.
91-
* @param string|array $paths One or multiple paths where mapping classes can be found.
92-
*/
93-
public function __construct(Reader $reader, $paths = null)
94-
{
95-
$this->reader = $reader;
96-
if ($paths) {
97-
$this->addPaths((array) $paths);
98-
}
99-
}
100-
101-
/**
102-
* Append lookup paths to metadata driver.
103-
*
104-
* @param array $paths
105-
*/
106-
public function addPaths(array $paths)
107-
{
108-
$this->paths = array_unique(array_merge($this->paths, $paths));
109-
}
110-
111-
/**
112-
* Retrieve the defined metadata lookup paths.
113-
*
114-
* @return array
115-
*/
116-
public function getPaths()
117-
{
118-
return $this->paths;
119-
}
120-
121-
/**
122-
* Retrieve the current annotation reader
123-
*
124-
* @return AnnotationReader
125-
*/
126-
public function getReader()
127-
{
128-
return $this->reader;
129-
}
130-
13159
/**
13260
* {@inheritdoc}
13361
*/
134-
public function loadMetadataForClass($className, ClassMetadataInfo $class)
62+
public function loadMetadataForClass($className, ClassMetadata $class)
13563
{
64+
/** @var $class ClassMetadataInfo */
13665
$reflClass = $class->getReflectionClass();
13766

13867
$documentAnnots = array();
@@ -288,80 +217,6 @@ private function addIndex(ClassMetadataInfo $class, $index, array $keys = array(
288217
$class->addIndex($keys, $options);
289218
}
290219

291-
/**
292-
* Whether the class with the specified name is transient. Only non-transient
293-
* classes, that is entities and mapped superclasses, should have their metadata loaded.
294-
* A class is non-transient if it is annotated with either (at)Entity or
295-
* (at)MappedSuperclass in the class doc block.
296-
*
297-
* @param string $className
298-
* @return boolean
299-
*/
300-
public function isTransient($className)
301-
{
302-
$classAnnotations = $this->reader->getClassAnnotations(new \ReflectionClass($className));
303-
304-
foreach ($classAnnotations as $annot) {
305-
if ($annot instanceof ODM\AbstractDocument) {
306-
return false;
307-
}
308-
}
309-
310-
return true;
311-
}
312-
313-
/**
314-
* {@inheritDoc}
315-
*/
316-
public function getAllClassNames()
317-
{
318-
if ($this->classNames !== null) {
319-
return $this->classNames;
320-
}
321-
322-
if ( ! $this->paths) {
323-
throw MongoDBException::pathRequired();
324-
}
325-
326-
$classes = array();
327-
$includedFiles = array();
328-
329-
foreach ($this->paths as $path) {
330-
if ( ! is_dir($path)) {
331-
throw MongoDBException::fileMappingDriversRequireConfiguredDirectoryPath();
332-
}
333-
334-
$iterator = new \RecursiveIteratorIterator(
335-
new \RecursiveDirectoryIterator($path),
336-
\RecursiveIteratorIterator::LEAVES_ONLY
337-
);
338-
339-
foreach ($iterator as $file) {
340-
if (($fileName = $file->getBasename($this->fileExtension)) == $file->getBasename()) {
341-
continue;
342-
}
343-
344-
$sourceFile = realpath($file->getPathName());
345-
require_once $sourceFile;
346-
$includedFiles[] = $sourceFile;
347-
}
348-
}
349-
350-
$declared = get_declared_classes();
351-
352-
foreach ($declared as $className) {
353-
$rc = new \ReflectionClass($className);
354-
$sourceFile = $rc->getFileName();
355-
if (in_array($sourceFile, $includedFiles) && ! $this->isTransient($className)) {
356-
$classes[] = $className;
357-
}
358-
}
359-
360-
$this->classNames = $classes;
361-
362-
return $classes;
363-
}
364-
365220
/**
366221
* Factory method for the Annotation Driver
367222
*

lib/Doctrine/ODM/MongoDB/Mapping/Driver/Driver.php

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)