Skip to content

Commit

Permalink
Merge pull request #2420 from franmomu/use_colocated_mapping
Browse files Browse the repository at this point in the history
Use colocated mapping driver
  • Loading branch information
malarzm authored Mar 22, 2022
2 parents e3da298 + 06dbdb2 commit d9e6da3
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
10 changes: 10 additions & 0 deletions UPGRADE-2.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,13 @@ private int $myProp;

This property will be stored in DB as `string` but casted back to `int`. Please note that at this
time, due to backward compatibility reasons, nullable type does not imply `nullable` mapping.

## BC Break: `AttributeDriver` and `AnnotationDriver` no longer extends parent class from `doctrine/persistence`

Both these classes used to extend an abstract `AnnotationDriver` class defined
in `doctrine/persistence`, and no longer do.

## Deprecate `AttributeDriver::getReader()` and `AnnotationDriver::getReader()`

That method was inherited from the abstract `AnnotationDriver` class of
`doctrine/persistence`, and does not seem to serve any purpose.
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"doctrine/collections": "^1.5",
"doctrine/event-manager": "^1.0",
"doctrine/instantiator": "^1.1",
"doctrine/persistence": "^2.2",
"doctrine/persistence": "^2.4",
"friendsofphp/proxy-manager-lts": "^1.0",
"jean85/pretty-package-versions": "^1.3.0 || ^2.0.1",
"mongodb/mongodb": "^1.2.0",
Expand Down Expand Up @@ -67,6 +67,9 @@
}
},
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
47 changes: 45 additions & 2 deletions lib/Doctrine/ODM/MongoDB/Mapping/Driver/AnnotationDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
use Doctrine\ODM\MongoDB\Mapping\Annotations\ShardKey;
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
use Doctrine\ODM\MongoDB\Mapping\MappingException;
use Doctrine\Persistence\Mapping\Driver\AnnotationDriver as AbstractAnnotationDriver;
use Doctrine\Persistence\Mapping\Driver\ColocatedMappingDriver;
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
use MongoDB\Driver\Exception\UnexpectedValueException;
use ReflectionClass;
use ReflectionMethod;
Expand All @@ -33,8 +34,33 @@
/**
* The AnnotationDriver reads the mapping metadata from docblock annotations.
*/
class AnnotationDriver extends AbstractAnnotationDriver
class AnnotationDriver implements MappingDriver
{
use ColocatedMappingDriver;

/**
* The annotation reader.
*
* @internal this property will be private in 3.0
*
* @var Reader
*/
protected $reader;

/**
* Initializes a new AnnotationDriver that uses the given AnnotationReader for reading
* docblock annotations.
*
* @param Reader $reader The AnnotationReader to use, duck-typed.
* @param string|string[]|null $paths One or multiple paths where mapping classes can be found.
*/
public function __construct($reader, $paths = null)
{
$this->reader = $reader;

$this->addPaths((array) $paths);
}

public function isTransient($className)
{
$classAnnotations = $this->reader->getClassAnnotations(new ReflectionClass($className));
Expand Down Expand Up @@ -335,6 +361,23 @@ private function setShardKey(ClassMetadata $class, ODM\ShardKey $shardKey): void
$class->setShardKey($shardKey->keys, $options);
}

/**
* Retrieve the current annotation reader
*
* @return Reader
*/
public function getReader()
{
trigger_deprecation(
'doctrine/mongodb-odm',
'2.4',
'%s is deprecated with no replacement',
__METHOD__
);

return $this->reader;
}

/**
* Factory method for the Annotation Driver
*
Expand Down

0 comments on commit d9e6da3

Please sign in to comment.