From 591759c54596cd7233bebf375e0ed6aa5fb79ed3 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Mon, 15 Apr 2019 15:57:21 +0200 Subject: [PATCH 1/5] Update cursor deprecations * Introduce new iterator interface to allow people to update typehints * Deprecate CommandCursor and Cursor class * Remove deprecation warning from EagerCursor class Since we're now deprecating all cursor classes, we can't really trigger deprecation warnings anymore since any read operation in MongoDB would cause deprecations that a user can't solve. Thus, we rely on other ways of deprecating these classes. --- UPGRADE-1.3.md | 8 ++++++++ lib/Doctrine/ODM/MongoDB/CommandCursor.php | 1 + lib/Doctrine/ODM/MongoDB/Cursor.php | 4 +++- lib/Doctrine/ODM/MongoDB/EagerCursor.php | 10 +--------- lib/Doctrine/ODM/MongoDB/Iterator/Iterator.php | 11 +++++++++++ 5 files changed, 24 insertions(+), 10 deletions(-) create mode 100644 lib/Doctrine/ODM/MongoDB/Iterator/Iterator.php diff --git a/UPGRADE-1.3.md b/UPGRADE-1.3.md index c1cfee19d9..8f3ef615ee 100644 --- a/UPGRADE-1.3.md +++ b/UPGRADE-1.3.md @@ -1,5 +1,13 @@ # UPGRADE FROM 1.2 TO 1.3 +## Cursors + + * The `Doctrine\ODM\MongoDB\Cursor`, `Doctrine\ODM\MongoDB\CommandCursor`, and + `Doctrine\ODM\MongoDB\EagerCursor` classes have been deprecated and will be + removed in 2.0. Their functionality will be covered by basic iterators. To + typehint an ODM specific iterator, use the new + `Doctrine\ODM\MongoDB\Iterator\Iterator` interface. + ## Events ### `onClassMetadataNotFound` event added diff --git a/lib/Doctrine/ODM/MongoDB/CommandCursor.php b/lib/Doctrine/ODM/MongoDB/CommandCursor.php index f736e2e207..f8867dd178 100644 --- a/lib/Doctrine/ODM/MongoDB/CommandCursor.php +++ b/lib/Doctrine/ODM/MongoDB/CommandCursor.php @@ -29,6 +29,7 @@ * * @since 1.1 * @author alcaeus + * @deprecated This class is deprecated and will be removed in 2.0. You should typehint against the {@see Iterator} interface instead. */ class CommandCursor implements Iterator { diff --git a/lib/Doctrine/ODM/MongoDB/Cursor.php b/lib/Doctrine/ODM/MongoDB/Cursor.php index 28d61ad3bf..1e5f31fd20 100644 --- a/lib/Doctrine/ODM/MongoDB/Cursor.php +++ b/lib/Doctrine/ODM/MongoDB/Cursor.php @@ -23,6 +23,7 @@ use Doctrine\MongoDB\Connection; use Doctrine\MongoDB\CursorInterface; use Doctrine\MongoDB\EagerCursor as BaseEagerCursor; +use Doctrine\ODM\MongoDB\Iterator\Iterator; use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; use Doctrine\ODM\MongoDB\Query\Query; use Doctrine\ODM\MongoDB\Query\ReferencePrimer; @@ -37,8 +38,9 @@ * For compatibility, this class also extends Doctrine\MongoDB\Cursor. * * @since 1.0 + * @deprecated This class is deprecated and will be removed in 2.0. You should typehint against the {@see Iterator} interface instead. */ -class Cursor implements CursorInterface +class Cursor implements CursorInterface, Iterator { /** * The Doctrine\MongoDB\Cursor instance being wrapped. diff --git a/lib/Doctrine/ODM/MongoDB/EagerCursor.php b/lib/Doctrine/ODM/MongoDB/EagerCursor.php index d2925435a0..8a1a54e9ed 100644 --- a/lib/Doctrine/ODM/MongoDB/EagerCursor.php +++ b/lib/Doctrine/ODM/MongoDB/EagerCursor.php @@ -27,16 +27,8 @@ * initialization. * * @since 1.0 - * @deprecated Deprecated in favor of using Cursor; will be removed in 2.0 + * @deprecated This class is deprecated and will be removed in 2.0. You should typehint against the {@see Iterator} interface instead. */ class EagerCursor extends Cursor { - public function __construct(CursorInterface $baseCursor, UnitOfWork $unitOfWork, ClassMetadata $class) - { - @trigger_error( - sprintf('%s is deprecated - use %s instead.', __CLASS__, Cursor::class), - E_USER_DEPRECATED - ); - parent::__construct($baseCursor, $unitOfWork, $class); - } } diff --git a/lib/Doctrine/ODM/MongoDB/Iterator/Iterator.php b/lib/Doctrine/ODM/MongoDB/Iterator/Iterator.php new file mode 100644 index 0000000000..c18a678f9a --- /dev/null +++ b/lib/Doctrine/ODM/MongoDB/Iterator/Iterator.php @@ -0,0 +1,11 @@ + Date: Mon, 15 Apr 2019 16:16:29 +0200 Subject: [PATCH 2/5] Add BC layer for DocumentPersister::prepareSortOrProjection --- UPGRADE-1.3.md | 6 ++ .../ODM/MongoDB/Aggregation/Builder.php | 2 +- lib/Doctrine/ODM/MongoDB/Cursor.php | 2 +- .../MongoDB/Persisters/DocumentPersister.php | 57 ++++++++++++++++++- lib/Doctrine/ODM/MongoDB/Query/Builder.php | 4 +- 5 files changed, 65 insertions(+), 6 deletions(-) diff --git a/UPGRADE-1.3.md b/UPGRADE-1.3.md index 8f3ef615ee..262105349c 100644 --- a/UPGRADE-1.3.md +++ b/UPGRADE-1.3.md @@ -8,6 +8,12 @@ typehint an ODM specific iterator, use the new `Doctrine\ODM\MongoDB\Iterator\Iterator` interface. +## Document Persister + + * The `Doctrine\ODM\MongoDB\Persisters\DocumentPersister::prepareSortOrProjection` + method was deprecated and will be dropped in 2.0. Use `prepareSort` or + `prepareProjection` accordingly. + ## Events ### `onClassMetadataNotFound` event added diff --git a/lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php b/lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php index deafcbc869..5c4e19e6e9 100644 --- a/lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php +++ b/lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php @@ -186,7 +186,7 @@ public function sortByCount($expression) public function sort($fieldName, $order = null) { $fields = is_array($fieldName) ? $fieldName : [$fieldName => $order]; - return parent::sort($this->getDocumentPersister()->prepareSortOrProjection($fields)); + return parent::sort($this->getDocumentPersister()->prepareSort($fields)); } /** diff --git a/lib/Doctrine/ODM/MongoDB/Cursor.php b/lib/Doctrine/ODM/MongoDB/Cursor.php index 1e5f31fd20..4e975014f9 100644 --- a/lib/Doctrine/ODM/MongoDB/Cursor.php +++ b/lib/Doctrine/ODM/MongoDB/Cursor.php @@ -596,7 +596,7 @@ public function sort($fields) { $fields = $this->unitOfWork ->getDocumentPersister($this->class->name) - ->prepareSortOrProjection($fields); + ->prepareSort($fields); $this->baseCursor->sort($fields); return $this; diff --git a/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php b/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php index 7db25b50b2..67caa94385 100644 --- a/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php +++ b/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php @@ -509,7 +509,7 @@ public function load($criteria, $document = null, array $hints = array(), $lockM $cursor = $this->collection->find($criteria); if (null !== $sort) { - $cursor->sort($this->prepareSortOrProjection($sort)); + $cursor->sort($this->prepareSort($sort)); } $result = $cursor->getSingleResult(); @@ -921,10 +921,26 @@ public function createReferenceManyWithRepositoryMethodCursor(PersistentCollecti * * @param array $fields * @return array + * + * @deprecated This method was deprecated in ODM 1.3 and will be dropped in 2.0. Use prepareSort or prepareProjection accordingly. */ public function prepareSortOrProjection(array $fields) { - $preparedFields = array(); + @trigger_error( + sprintf('The "%s" method was deprecated in MongoDB ODM 1.3 and will be dropped in 2.0. Use "prepareSort" or "prepareProjection" accordingly.', __METHOD__), + E_USER_DEPRECATED + ); + + return $this->prepareProjection($fields); + } + + /** + * Prepare a projection array by converting keys, which are PHP property + * names, to MongoDB field names. + */ + public function prepareProjection(array $fields) + { + $preparedFields = []; foreach ($fields as $key => $value) { $preparedFields[$this->prepareFieldName($key)] = $value; @@ -933,6 +949,43 @@ public function prepareSortOrProjection(array $fields) return $preparedFields; } + /** + * @param int|string $sort + * + * @return int|string|null + */ + private function getSortDirection($sort) + { + switch (strtolower((string) $sort)) { + case 'desc': + return -1; + + case 'asc': + return 1; + } + + return $sort; + } + + /** + * Prepare a sort specification array by converting keys to MongoDB field + * names and changing direction strings to int. + */ + public function prepareSort(array $fields) + { + $sortFields = []; + + foreach ($fields as $key => $value) { + if (is_array($value)) { + $sortFields[$this->prepareFieldName($key)] = $value; + } else { + $sortFields[$this->prepareFieldName($key)] = $this->getSortDirection($value); + } + } + + return $sortFields; + } + /** * Prepare a mongodb field name and convert the PHP property names to MongoDB field names. * diff --git a/lib/Doctrine/ODM/MongoDB/Query/Builder.php b/lib/Doctrine/ODM/MongoDB/Query/Builder.php index 214f77a226..337a9325f6 100644 --- a/lib/Doctrine/ODM/MongoDB/Query/Builder.php +++ b/lib/Doctrine/ODM/MongoDB/Query/Builder.php @@ -418,7 +418,7 @@ public function getQuery(array $options = array()) } if ( ! empty($query['select'])) { - $query['select'] = $documentPersister->prepareSortOrProjection($query['select']); + $query['select'] = $documentPersister->prepareProjection($query['select']); if ($this->hydrate && $this->class->inheritanceType === ClassMetadata::INHERITANCE_TYPE_SINGLE_COLLECTION && ! isset($query['select'][$this->class->discriminatorField])) { $includeMode = 0 < count(array_filter($query['select'], function($mode) { return $mode == 1; })); @@ -429,7 +429,7 @@ public function getQuery(array $options = array()) } if (isset($query['sort'])) { - $query['sort'] = $documentPersister->prepareSortOrProjection($query['sort']); + $query['sort'] = $documentPersister->prepareSort($query['sort']); } if ($this->class->slaveOkay) { From b1effdf9cd87acd429213ee551deb247ad1ed5b9 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Tue, 16 Apr 2019 08:08:18 +0200 Subject: [PATCH 3/5] Document more BC breaks for 2.0 --- UPGRADE-1.3.md | 104 +++++++++++++++- lib/Doctrine/ODM/MongoDB/Aggregation/Expr.php | 9 ++ .../ODM/MongoDB/Aggregation/Stage/Match.php | 39 ++++++ lib/Doctrine/ODM/MongoDB/Configuration.php | 112 +++++++++++++++++- .../MongoDB/Mapping/Annotations/Distance.php | 12 ++ .../ODM/MongoDB/Mapping/ClassMetadata.php | 8 ++ lib/Doctrine/ODM/MongoDB/MongoDBException.php | 23 ++++ .../MongoDB/Persisters/DocumentPersister.php | 1 + lib/Doctrine/ODM/MongoDB/Query/Builder.php | 106 +++++++++++++++++ lib/Doctrine/ODM/MongoDB/Query/Expr.php | 106 +++++++++++++++++ lib/Doctrine/ODM/MongoDB/Query/Query.php | 33 ++++++ lib/Doctrine/ODM/MongoDB/Types/Type.php | 2 + 12 files changed, 552 insertions(+), 3 deletions(-) diff --git a/UPGRADE-1.3.md b/UPGRADE-1.3.md index 262105349c..31a94c56f1 100644 --- a/UPGRADE-1.3.md +++ b/UPGRADE-1.3.md @@ -1,5 +1,34 @@ # UPGRADE FROM 1.2 TO 1.3 +## Aggregation builder + + * The `debug`, `maxDistance` and `minDistance` methods in + `Doctrine\ODM\MongoDB\Aggregation\Stage\Match` have been deprecated and will + be removed in 2.0. + * The `Doctrine\ODM\MongoDB\Aggregation\Expr::ensureArray` method will be + private in 2.0. + * The `Doctrine\ODM\MongoDB\Aggregation\Stage\Bucket::convertExpression` method + will be private in 2.0. + * The `Doctrine\ODM\MongoDB\Aggregation\Stage\BucketAuto::convertExpression` + method will be private in 2.0. + * The following methods in `Doctrine\ODM\MongoDB\Aggregation\Stage\GraphLookup` + will be private in 2.0: `convertExpression`, `convertTargetFieldName`. + * The `Doctrine\ODM\MongoDB\Aggregation\Stage\ReplaceRoot::convertExpression` + method will be private in 2.0. + +## Configuration + + * The following methods in `Doctrine\ODM\MongoDB\Configuration` have been + deprecated and will be removed in MongoDB ODM 2.0: `getLoggerCallable`, + `getMongoCmd`, `getRetryConnect`, `getRetryQuery`, `setLoggerCallable`, + `setMongoCmd`, `setRetryConnect`, `setRetryQuery`. + * The `attributes` property will be private in MongoDB ODM 2.0 - if you are + extending the configuration class you should no longer rely on it. + * The `getDefaultRepositoryClassName` and `setDefaultRepositoryClassName` + methods in `Doctrine\ODM\MongoDB\Configuration` have been deprecated in favor + of `getDefaultDocumentRepositoryClassName` and + `setDefaultDocumentRepositoryClassName`, respectively. + ## Cursors * The `Doctrine\ODM\MongoDB\Cursor`, `Doctrine\ODM\MongoDB\CommandCursor`, and @@ -8,6 +37,26 @@ typehint an ODM specific iterator, use the new `Doctrine\ODM\MongoDB\Iterator\Iterator` interface. +## Document Class Generation + +Functionality regarding generation of document and repository classes was +deprecated and will be dropped in 2.0. The following classes related to this +functionality have been deprecated: + * `Doctrine\ODM\MongoDB\Query\FieldExtractor` + * `Doctrine\ODM\MongoDB\Tools\Console\Command\GenerateDocumentsCommand` + * `Doctrine\ODM\MongoDB\Tools\Console\Command\GenerateRepositoriesCommand` + * `Doctrine\ODM\MongoDB\Tools\DisconnectedClassMetadataFactory` + * `Doctrine\ODM\MongoDB\Tools\DocumentGenerator` + * `Doctrine\ODM\MongoDB\Tools\DocumentRepositoryGenerator` + +## Document Manager + + * The `Doctrine\ODM\MongoDB\DocumentManager::createDBRef` method was deprecated + in favor of `createReference`. It will be dropped in 2.0. + * The `Doctrine\ODM\MongoDB\DocumentManager::getConnection` method was + deprecated and will be dropped in 2.0. The replacement, `getClient` will + return a `MongoDB\Client` instance, but is not available in 1.x. + ## Document Persister * The `Doctrine\ODM\MongoDB\Persisters\DocumentPersister::prepareSortOrProjection` @@ -94,6 +143,16 @@ The `Doctrine\ODM\MongoDB\Mapping\ClassMetadataInfo` class has been deprecated in favor of `Doctrine\ODM\MongoDB\Mapping\ClassMetadata` and will be dropped in 2.0. +### Obsolete features deprecated + + * The following methods in `Doctrine\ODM\MongoDB\Mapping\ClassMetadata` were + deprecated and will be removed in 2.0: `getDistance`, `getFile`, + `getNamespace`, `isFile`, `mapFile`, `setDistance`, `setFile`, + `setRequireIndexes`, `setSlaveOkay`. + * The following properties `Doctrine\ODM\MongoDB\Mapping\ClassMetadata` were + deprecated and will be removed in 2.0: `distance`, `file`, `namespace`, + `requireIndexes`, `slaveOkay`. + ### Annotation mappings * The `@NotSaved` annotation was deprecated and will be dropped in 2.0. Use the @@ -105,6 +164,10 @@ in favor of `Doctrine\ODM\MongoDB\Mapping\ClassMetadata` and will be dropped in * The `dropDups` option on the `@Index` annotation was deprecated and will be dropped without replacement in 2.0. This functionality is no longer available. + * The `simple` option on the `@ReferenceOne` and `@ReferenceMany` annotations + was deprecated and will be dropped in 2.0. Use `storeAs="id"` instead. + * The `@Distance` annotation was deprecated and will be dropped in 2.0. GeoNear + queries will no longer be supported, use the aggregation pipeline instead. ### XML mappings @@ -115,7 +178,7 @@ in favor of `Doctrine\ODM\MongoDB\Mapping\ClassMetadata` and will be dropped in * The `drop-dups` attribute in the `index` element was deprecated and will be dropped without replacement in 2.0. This functionality is no longer available. - + ### Full discriminator maps required When using a discriminator map on a reference or embedded relationship, @@ -161,6 +224,31 @@ set. * The following methods in `Doctrine\ODM\MongoDB\Query\Builder` were deprecated and will be dropped in 2.0: `mapReduce`, `map`, `reduce`, `finalize`, `out`, `mapReduceOptions`, `distanceMultiplier`, `geoNear`, `spherical`. + * The following properties in `Doctrine\ODM\MongoDB\Query\Builder` will be + private in MongoDB ODM 2.0: `collection`, `expr`, `query`. + * The following properties in `Doctrine\ODM\MongoDB\Query\Expr` will be private + in MongoDB ODM 2.0: `currentField`, `newObj`, `query`. + * The `addManyToSet` and `pushAll` methods in + `Doctrine\ODM\MongoDB\Query\Builder` and `Doctrine\ODM\MongoDB\Query\Expr` + were deprecated and will be removed in 2.0. Use `each` in combination with + `addToSet` and `push` respectively. + * The following methods from `Doctrine\ODM\MongoDB\Query\Builder` and + `Doctrine\ODM\MongoDB\Query\Expr` were deprecated and will be removed in 2.0: + `maxDistance`, `minDistance`, `withinBox`, `withinCenter`, + `withinCenterSphere`, `withinPolygon`. + * The `Doctrine\MongoDB\Query\Query::count` method was deprecated and will be + removed in MongoDB ODM 2.0. Iterators will not be countable in 2.0. Users + should run separate count queries instead. + * The `Doctrine\MongoDB\Query\Query::iterate` method was deprecated and will be + removed in MongoDB ODM 2.0. Use `Doctrine\MongoDB\Query\Query::getIterator` + instead. + * The following properties in `Doctrine\ODM\MongoDB\Query\Query` will be + private in MongoDB ODM 2.0: `iterator`, `options`, `query`. + * The following constants in `Doctrine\ODM\MongoDB\Query\Query` will be removed + in MongoDB ODM 2.0: `HINT_READ_PREFERENCE_TAGS`, `HINT_SLAVE_OKAY`, + `TYPE_GEO_NEAR`. + * The `Doctrine\ODM\MongoDB\Query\Query::prepareCursor` method will be removed + in MongoDB ODM 2.0. You should wrap the returned cursor instead. ## Schema manager @@ -169,3 +257,17 @@ set. option instead. * The `indexOptions` argument in the `ensureSharding` and `ensureDocumentSharding` methods was deprecated and will be dropped in 2.0. + +## Types + + * The following classes in the `Doctrine\ODM\MongoDB\Types` namespace were + deprecated and will be removed in 2.0: `FileType`, `IncrementType`. + * The `FILE` and `INCREMENT` constants in `Doctrine\ODM\MongoDB\Types\Type` + were deprecated and will be removed in 2.0. + +## UnitOfWork + + * The `isScheduledForDirtyCheck` and `scheduleForDirtyCheck` methods in + `Doctrine\ODM\MongoDB\UnitOfWork` have been deprecated and will be dropped in + 2.0. Use `isScheduledForSynchronization` and `scheduleForSynchronization` + instead. diff --git a/lib/Doctrine/ODM/MongoDB/Aggregation/Expr.php b/lib/Doctrine/ODM/MongoDB/Aggregation/Expr.php index f9e151fbed..f502fb396a 100644 --- a/lib/Doctrine/ODM/MongoDB/Aggregation/Expr.php +++ b/lib/Doctrine/ODM/MongoDB/Aggregation/Expr.php @@ -23,6 +23,9 @@ use Doctrine\MongoDB\Aggregation\Expr as BaseExpr; use Doctrine\ODM\MongoDB\DocumentManager; use Doctrine\ODM\MongoDB\Types\Type; +use const E_USER_DEPRECATED; +use function sprintf; +use function trigger_error; /** * Fluent interface for building aggregation pipelines. @@ -64,9 +67,15 @@ public function field($fieldName) /** * @param mixed|self $expression * @return mixed + * + * @internal This method will be private in MongoDB ODM 2.0. */ protected function ensureArray($expression) { + if (self::class !== static::class) { + @trigger_error(sprintf('The "%s" method will be private in MongoDB ODM 2.0. You should not rely on calling this method.', __METHOD__), E_USER_DEPRECATED); + } + // Convert field names in expressions if (is_string($expression) && substr($expression, 0, 1) === '$') { return '$' . $this->getDocumentPersister()->prepareFieldName(substr($expression, 1)); diff --git a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Match.php b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Match.php index e7cd44f570..5051587514 100644 --- a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Match.php +++ b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Match.php @@ -20,6 +20,9 @@ namespace Doctrine\ODM\MongoDB\Aggregation\Stage; use Doctrine\MongoDB\Aggregation\Stage as BaseStage; +use const E_USER_DEPRECATED; +use function sprintf; +use function trigger_error; /** * Fluent interface for building aggregation pipelines. @@ -47,4 +50,40 @@ public function includesReferenceTo($document) return $this; } + + /** + * {@inheritdoc} + * + * @deprecated This method is deprecated and will be removed in MongoDB ODM 2.0. + */ + public function debug($name = null) + { + @trigger_error(sprintf('The "%s" method is deprecated and will be removed in MongoDB ODM 2.0.', __METHOD__), E_USER_DEPRECATED); + + return parent::debug($name); + } + + /** + * {@inheritdoc} + * + * @deprecated This method is deprecated and will be removed in MongoDB ODM 2.0. + */ + public function maxDistance($maxDistance) + { + @trigger_error(sprintf('The "%s" method is deprecated and will be removed in MongoDB ODM 2.0.', __METHOD__), E_USER_DEPRECATED); + + return parent::maxDistance($maxDistance); + } + + /** + * {@inheritdoc} + * + * @deprecated This method is deprecated and will be removed in MongoDB ODM 2.0. + */ + public function minDistance($minDistance) + { + @trigger_error(sprintf('The "%s" method is deprecated and will be removed in MongoDB ODM 2.0.', __METHOD__), E_USER_DEPRECATED); + + return parent::minDistance($minDistance); + } } diff --git a/lib/Doctrine/ODM/MongoDB/Configuration.php b/lib/Doctrine/ODM/MongoDB/Configuration.php index 1e0aba0ec8..ca7ff3e134 100644 --- a/lib/Doctrine/ODM/MongoDB/Configuration.php +++ b/lib/Doctrine/ODM/MongoDB/Configuration.php @@ -86,6 +86,18 @@ class Configuration extends \Doctrine\MongoDB\Configuration */ const AUTOGENERATE_EVAL = 3; + /** + * Array of attributes for this configuration instance. + * + * @var array + * @deprecated This property will be private in MongoDB ODM 2.0. + */ + protected $attributes = [ + 'mongoCmd' => '$', + 'retryConnect' => 0, + 'retryQuery' => 0, + ]; + /** * Adds a namespace under a certain alias. * @@ -532,7 +544,7 @@ public function getFilterParameters($name) public function setDefaultRepositoryClassName($className) { @trigger_error( - sprintf('%s was deprecated in version 1.2 and will be removed in 2.0. Please use setDefaultDocumentRepositoryClassName instead.', __METHOD__), + sprintf('"%s" was deprecated in MongoDB ODM 1.2 and will be removed in 2.0. Please use "%s::setDefaultDocumentRepositoryClassName" instead.', __METHOD__, __CLASS__), E_USER_DEPRECATED ); $this->setDefaultDocumentRepositoryClassName($className); @@ -548,7 +560,7 @@ public function setDefaultRepositoryClassName($className) public function getDefaultRepositoryClassName() { @trigger_error( - sprintf('%s was deprecated in version 1.2 and will be removed in 2.0. Please use getDefaultDocumentRepositoryClassName instead.', __METHOD__), + sprintf('"%s" was deprecated in MongoDB ODM 1.2 and will be removed in 2.0. Please use "%s::getDefaultDocumentRepositoryClassName" instead.', __METHOD__, __CLASS__), E_USER_DEPRECATED ); return $this->getDefaultDocumentRepositoryClassName(); @@ -648,4 +660,100 @@ public function getPersistentCollectionGenerator() } return $this->attributes['persistentCollectionGenerator']; } + + /** + * {@inheritdoc} + * + * @deprecated This method is deprecated and will be removed in MongoDB ODM 2.0. + */ + public function getLoggerCallable() + { + @trigger_error(sprintf('The "%s" method is deprecated and will be removed in MongoDB ODM 2.0.', __METHOD__), E_USER_DEPRECATED); + + return parent::getLoggerCallable(); + } + + /** + * {@inheritdoc} + * + * @deprecated This method is deprecated and will be removed in MongoDB ODM 2.0. + */ + public function setLoggerCallable($loggerCallable) + { + @trigger_error(sprintf('The "%s" method is deprecated and will be removed in MongoDB ODM 2.0.', __METHOD__), E_USER_DEPRECATED); + + parent::setLoggerCallable($loggerCallable); + } + + /** + * {@inheritdoc} + * + * @deprecated This method is deprecated and will be removed in MongoDB ODM 2.0. + */ + public function getMongoCmd() + { + @trigger_error(sprintf('The "%s" method is deprecated and will be removed in MongoDB ODM 2.0.', __METHOD__), E_USER_DEPRECATED); + + return parent::getMongoCmd(); + } + + /** + * {@inheritdoc} + * + * @deprecated This method is deprecated and will be removed in MongoDB ODM 2.0. + */ + public function setMongoCmd($cmd) + { + @trigger_error(sprintf('The "%s" method is deprecated and will be removed in MongoDB ODM 2.0.', __METHOD__), E_USER_DEPRECATED); + + parent::setMongoCmd($cmd); + } + + /** + * {@inheritdoc} + * + * @deprecated This method is deprecated and will be removed in MongoDB ODM 2.0. + */ + public function getRetryConnect() + { + @trigger_error(sprintf('The "%s" method is deprecated and will be removed in MongoDB ODM 2.0.', __METHOD__), E_USER_DEPRECATED); + + return parent::getRetryConnect(); + } + + /** + * {@inheritdoc} + * + * @deprecated This method is deprecated and will be removed in MongoDB ODM 2.0. + */ + public function setRetryConnect($retryConnect) + { + @trigger_error(sprintf('The "%s" method is deprecated and will be removed in MongoDB ODM 2.0.', __METHOD__), E_USER_DEPRECATED); + + parent::setRetryConnect($retryConnect); + } + + /** + * {@inheritdoc} + * + * @deprecated This method is deprecated and will be removed in MongoDB ODM 2.0. + */ + public function getRetryQuery() + { + @trigger_error(sprintf('The "%s" method is deprecated and will be removed in MongoDB ODM 2.0.', __METHOD__), E_USER_DEPRECATED); + + return parent::getRetryQuery(); + } + + /** + * {@inheritdoc} + * + * @deprecated This method is deprecated and will be removed in MongoDB ODM 2.0. + */ + public function setRetryQuery($retryQuery) + { + @trigger_error(sprintf('The "%s" method is deprecated and will be removed in MongoDB ODM 2.0.', __METHOD__), E_USER_DEPRECATED); + + parent::setRetryQuery($retryQuery); + } } diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/Distance.php b/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/Distance.php index 29f40dd37f..efc49ae35e 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/Distance.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/Distance.php @@ -23,8 +23,20 @@ * Use this field to store distance information for geoNear queries * * @Annotation + * + * @deprecated This annotation was deprecated in MongoDB ODM 1.3 and will be removed in 2.0. */ final class Distance extends AbstractField { public $distance = true; + + public function getDeprecationMessage() + { + return sprintf('The "%s" annotation class was deprecated in MongoDB ODM 1.3 and will be removed in 2.0. GeoNear queries will no longer be supported, use the aggregation pipeline instead.', __CLASS__); + } + + public function isDeprecated() + { + return true; + } } diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php b/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php index 4a02f61b10..76ab998ee8 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php @@ -1312,9 +1312,13 @@ public function setFile($file) * Returns the distance field name. * * @return string $distance The distance field name. + * + * @deprecated Deprecated in 1.3 and will be dropped in 2.0. */ public function getDistance() { + @trigger_error(sprintf('The "%s" method is deprecated and will be dropped in MongoDB ODM 2.0.', __METHOD__), E_USER_DEPRECATED); + return $this->distance; } @@ -1322,9 +1326,13 @@ public function getDistance() * Set the field name that stores the distance. * * @param string $distance + * + * @deprecated Deprecated in 1.3 and will be dropped in 2.0. */ public function setDistance($distance) { + @trigger_error(sprintf('The "%s" method is deprecated and will be dropped in MongoDB ODM 2.0.', __METHOD__), E_USER_DEPRECATED); + $this->distance = $distance; } diff --git a/lib/Doctrine/ODM/MongoDB/MongoDBException.php b/lib/Doctrine/ODM/MongoDB/MongoDBException.php index 64f58ebe55..d58a7872b9 100644 --- a/lib/Doctrine/ODM/MongoDB/MongoDBException.php +++ b/lib/Doctrine/ODM/MongoDB/MongoDBException.php @@ -19,6 +19,10 @@ namespace Doctrine\ODM\MongoDB; +use const E_USER_DEPRECATED; +use function sprintf; +use function trigger_error; + /** * Class for all exceptions related to the Doctrine MongoDB ODM * @@ -31,9 +35,16 @@ class MongoDBException extends \Exception * @param string $fieldName * @param string $method * @return MongoDBException + * + * @deprecated This method was deprecated in 1.3 and will be dropped in ODM 2.0. */ public static function invalidFindByCall($documentName, $fieldName, $method) { + @trigger_error( + sprintf('The "%s" method is deprecated in MongoDB ODM 1.3 and will be removed in 2.0. Magic findBy methods will no longer be supported.', __METHOD__), + E_USER_DEPRECATED + ); + return new self(sprintf('Invalid find by call %s::$fieldName (%s)', $documentName, $fieldName, $method)); } @@ -74,9 +85,16 @@ public static function documentManagerClosed() /** * @param string $methodName * @return MongoDBException + * + * @deprecated This method was deprecated in 1.3 and will be dropped in ODM 2.0. */ public static function findByRequiresParameter($methodName) { + @trigger_error( + sprintf('The "%s" method is deprecated in MongoDB ODM 1.3 and will be removed in 2.0. Magic findBy methods will no longer be supported.', __METHOD__), + E_USER_DEPRECATED + ); + return new self("You need to pass a parameter to '".$methodName."'"); } @@ -107,6 +125,11 @@ public static function cannotPersistMappedSuperclass($className) */ public static function queryNotIndexed($className, $unindexedFields) { + @trigger_error( + sprintf('The "%s" method is deprecated in MongoDB ODM 1.2 and will be removed in 2.0. The requireIndexes functionality will no longer be supported.', __METHOD__), + E_USER_DEPRECATED + ); + return new self(sprintf('Cannot execute unindexed queries on %s. Unindexed fields: %s', $className, implode(', ', $unindexedFields) diff --git a/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php b/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php index 67caa94385..a1097987b4 100644 --- a/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php +++ b/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php @@ -38,6 +38,7 @@ use Doctrine\ODM\MongoDB\Query\Query; use Doctrine\ODM\MongoDB\Types\Type; use Doctrine\ODM\MongoDB\UnitOfWork; +use const E_USER_DEPRECATED; /** * The DocumentPersister is responsible for persisting documents. diff --git a/lib/Doctrine/ODM/MongoDB/Query/Builder.php b/lib/Doctrine/ODM/MongoDB/Query/Builder.php index 337a9325f6..d0435cce34 100644 --- a/lib/Doctrine/ODM/MongoDB/Query/Builder.php +++ b/lib/Doctrine/ODM/MongoDB/Query/Builder.php @@ -54,6 +54,27 @@ class Builder extends \Doctrine\MongoDB\Query\Builder */ protected $currentField; + /** + * @inheritdoc + * + * @internal This field will be private in MongoDB ODM 2.0. + */ + protected $collection; + + /** + * @inheritdoc + * + * @internal This field will be private in MongoDB ODM 2.0. + */ + protected $query = ['type' => Query::TYPE_FIND]; + + /** + * @inheritdoc + * + * @internal This field will be private in MongoDB ODM 2.0. + */ + protected $expr; + /** * Whether or not to hydrate the data to documents. * @@ -646,4 +667,89 @@ public function spherical($spherical = true) return parent::spherical($spherical); } + + /** + * @inheritdoc + * @deprecated Deprecated in version 1.3 - use Aggregation Pipeline instead + */ + public function maxDistance($maxDistance) + { + @trigger_error( + sprintf('The %s method is deprecated since MongoDB ODM 1.3 and will be removed in 2.0. Please use the aggregation pipeline instead.', __METHOD__), + E_USER_DEPRECATED + ); + + return parent::maxDistance($maxDistance); + } + + /** + * @inheritdoc + * @deprecated Deprecated in version 1.3 - use Aggregation Pipeline instead + */ + public function minDistance($minDistance) + { + @trigger_error( + sprintf('The %s method is deprecated since MongoDB ODM 1.3 and will be removed in 2.0. Please use the aggregation pipeline instead.', __METHOD__), + E_USER_DEPRECATED + ); + + return parent::minDistance($minDistance); + } + + /** + * @inheritdoc + * @deprecated Deprecated in version 1.3 - use Aggregation Pipeline instead + */ + public function withinBox($x1, $y1, $x2, $y2) + { + @trigger_error( + sprintf('The %s method is deprecated since MongoDB ODM 1.3 and will be removed in 2.0. Please use the aggregation pipeline instead.', __METHOD__), + E_USER_DEPRECATED + ); + + return parent::withinBox($x1, $y1, $x2, $y2); + } + + /** + * @inheritdoc + * @deprecated Deprecated in version 1.3 - use Aggregation Pipeline instead + */ + public function withinCenter($x, $y, $radius) + { + @trigger_error( + sprintf('The %s method is deprecated since MongoDB ODM 1.3 and will be removed in 2.0. Please use the aggregation pipeline instead.', __METHOD__), + E_USER_DEPRECATED + ); + + return parent::withinCenter($x, $y, $radius); + } + + /** + * @inheritdoc + * @deprecated Deprecated in version 1.3 - use Aggregation Pipeline instead + */ + public function withinCenterSphere($x, $y, $radius) + { + @trigger_error( + sprintf('The %s method is deprecated since MongoDB ODM 1.3 and will be removed in 2.0. Please use the aggregation pipeline instead.', __METHOD__), + E_USER_DEPRECATED + ); + + return parent::withinCenterSphere($x, $y, $radius); + } + + /** + * @inheritdoc + * @deprecated Deprecated in version 1.3 - use Aggregation Pipeline instead + */ + public function withinPolygon() + { + @trigger_error( + sprintf('The %s method is deprecated since MongoDB ODM 1.3 and will be removed in 2.0. Please use the aggregation pipeline instead.', __METHOD__), + E_USER_DEPRECATED + ); + + return parent::withinPolygon(...func_get_args()); + } + } diff --git a/lib/Doctrine/ODM/MongoDB/Query/Expr.php b/lib/Doctrine/ODM/MongoDB/Query/Expr.php index 6516d6c892..474fc43dd9 100644 --- a/lib/Doctrine/ODM/MongoDB/Query/Expr.php +++ b/lib/Doctrine/ODM/MongoDB/Query/Expr.php @@ -22,6 +22,7 @@ use Doctrine\ODM\MongoDB\DocumentManager; use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; use Doctrine\ODM\MongoDB\Mapping\MappingException; +use function func_get_args; /** * Query expression builder for ODM. @@ -30,6 +31,27 @@ */ class Expr extends \Doctrine\MongoDB\Query\Expr { + /** + * @inheritdoc + * + * @internal This field will be private in MongoDB ODM 2.0. + */ + protected $query = []; + + /** + * @inheritdoc + * + * @internal This field will be private in MongoDB ODM 2.0. + */ + protected $newObj = []; + + /** + * @inheritdoc + * + * @internal This field will be private in MongoDB ODM 2.0. + */ + protected $currentField; + /** * The DocumentManager instance for this query * @@ -222,4 +244,88 @@ private function getReferenceMapping() } return $mapping; } + + /** + * @inheritdoc + * @deprecated Deprecated in version 1.3 - use Aggregation Pipeline instead + */ + public function maxDistance($maxDistance) + { + @trigger_error( + sprintf('The %s method is deprecated since MongoDB ODM 1.3 and will be removed in 2.0. Please use the aggregation pipeline instead.', __METHOD__), + E_USER_DEPRECATED + ); + + return parent::maxDistance($maxDistance); + } + + /** + * @inheritdoc + * @deprecated Deprecated in version 1.3 - use Aggregation Pipeline instead + */ + public function minDistance($minDistance) + { + @trigger_error( + sprintf('The %s method is deprecated since MongoDB ODM 1.3 and will be removed in 2.0. Please use the aggregation pipeline instead.', __METHOD__), + E_USER_DEPRECATED + ); + + return parent::minDistance($minDistance); + } + + /** + * @inheritdoc + * @deprecated Deprecated in version 1.3 - use Aggregation Pipeline instead + */ + public function withinBox($x1, $y1, $x2, $y2) + { + @trigger_error( + sprintf('The %s method is deprecated since MongoDB ODM 1.3 and will be removed in 2.0. Please use the aggregation pipeline instead.', __METHOD__), + E_USER_DEPRECATED + ); + + return parent::withinBox($x1, $y1, $x2, $y2); + } + + /** + * @inheritdoc + * @deprecated Deprecated in version 1.3 - use Aggregation Pipeline instead + */ + public function withinCenter($x, $y, $radius) + { + @trigger_error( + sprintf('The %s method is deprecated since MongoDB ODM 1.3 and will be removed in 2.0. Please use the aggregation pipeline instead.', __METHOD__), + E_USER_DEPRECATED + ); + + return parent::withinCenter($x, $y, $radius); + } + + /** + * @inheritdoc + * @deprecated Deprecated in version 1.3 - use Aggregation Pipeline instead + */ + public function withinCenterSphere($x, $y, $radius) + { + @trigger_error( + sprintf('The %s method is deprecated since MongoDB ODM 1.3 and will be removed in 2.0. Please use the aggregation pipeline instead.', __METHOD__), + E_USER_DEPRECATED + ); + + return parent::withinCenterSphere($x, $y, $radius); + } + + /** + * @inheritdoc + * @deprecated Deprecated in version 1.3 - use Aggregation Pipeline instead + */ + public function withinPolygon() + { + @trigger_error( + sprintf('The %s method is deprecated since MongoDB ODM 1.3 and will be removed in 2.0. Please use the aggregation pipeline instead.', __METHOD__), + E_USER_DEPRECATED + ); + + return parent::withinPolygon(...func_get_args()); + } } diff --git a/lib/Doctrine/ODM/MongoDB/Query/Query.php b/lib/Doctrine/ODM/MongoDB/Query/Query.php index f6303a995d..c1d72c092c 100644 --- a/lib/Doctrine/ODM/MongoDB/Query/Query.php +++ b/lib/Doctrine/ODM/MongoDB/Query/Query.php @@ -45,8 +45,11 @@ class Query extends \Doctrine\MongoDB\Query\Query /** @deprecated */ const HINT_SLAVE_OKAY = 2; const HINT_READ_PREFERENCE = 3; + /** @deprecated */ const HINT_READ_PREFERENCE_TAGS = 4; const HINT_READ_ONLY = 5; + /** @deprecated */ + const TYPE_GEO_NEAR = 10; /** * The DocumentManager instance. @@ -359,6 +362,8 @@ public function execute() * @see \Doctrine\MongoDB\Cursor::prepareCursor() * @param BaseCursor $cursor * @return CursorInterface + * + * @deprecated This method will be removed in MongoDB ODM 2.0. */ protected function prepareCursor(BaseCursor $cursor) { @@ -388,4 +393,32 @@ private function isIndexRequired() { return $this->requireIndexes !== null ? $this->requireIndexes : $this->class->requireIndexes; } + + /** + * @inheritdoc + * @deprecated Deprecated in version 1.3. Countable iterators will be removed in 2.0. Run separate queries instead + */ + public function count($foundOnly = false) + { + @trigger_error( + sprintf('The %s method is deprecated since MongoDB ODM 1.3 and will be removed in 2.0. Please run separate count queries instead.', __METHOD__), + E_USER_DEPRECATED + ); + + return parent::count($foundOnly); + } + + /** + * @inheritdoc + * @deprecated Deprecated in version 1.3. Use getIterator instead. + */ + public function iterate() + { + @trigger_error( + sprintf('The %s method is deprecated since MongoDB ODM 1.3 and will be removed in 2.0. Please use "%s::getIterator()" instead.', __METHOD__, __CLASS__), + E_USER_DEPRECATED + ); + + return parent::iterate(); + } } diff --git a/lib/Doctrine/ODM/MongoDB/Types/Type.php b/lib/Doctrine/ODM/MongoDB/Types/Type.php index c7f2ff8991..60cfa8c6e5 100644 --- a/lib/Doctrine/ODM/MongoDB/Types/Type.php +++ b/lib/Doctrine/ODM/MongoDB/Types/Type.php @@ -48,9 +48,11 @@ abstract class Type const BINDATAUUIDRFC4122 = 'bin_uuid_rfc4122'; const BINDATAMD5 = 'bin_md5'; const BINDATACUSTOM = 'bin_custom'; + /** @deprecated This type was deprecated in MongoDB ODM 1.3 and will be removed in 2.0. */ const FILE = 'file'; const HASH = 'hash'; const COLLECTION = 'collection'; + /** @deprecated This type was deprecated in MongoDB ODM 1.3 and will be removed in 2.0. */ const INCREMENT = 'increment'; const OBJECTID = 'object_id'; const RAW = 'raw'; From ab832d20a719ad8cb96117b460f81aee918a0184 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Tue, 16 Apr 2019 08:58:37 +0200 Subject: [PATCH 4/5] Add BC layer for DocumentRepository deprecation --- UPGRADE-1.3.md | 5 + lib/Doctrine/ODM/MongoDB/Configuration.php | 3 +- .../ODM/MongoDB/DocumentRepository.php | 317 +---------------- .../MongoDB/Repository/DocumentRepository.php | 325 ++++++++++++++++++ .../Functional/OrphanRemovalEmbedTest.php | 5 +- .../Tests/Functional/OrphanRemovalTest.php | 5 +- .../Tests/Functional/Ticket/GH1232Test.php | 2 +- .../Tests/Functional/Ticket/GH1572Test.php | 2 +- .../Tests/Mapping/ClassMetadataTest.php | 2 +- tests/Documents/BaseCategoryRepository.php | 6 +- tests/Documents/CommentRepository.php | 2 +- .../Documents/CustomRepository/Repository.php | 6 +- tools/sandbox/Documents/UserRepository.php | 2 +- 13 files changed, 368 insertions(+), 314 deletions(-) create mode 100644 lib/Doctrine/ODM/MongoDB/Repository/DocumentRepository.php diff --git a/UPGRADE-1.3.md b/UPGRADE-1.3.md index 31a94c56f1..2a31645245 100644 --- a/UPGRADE-1.3.md +++ b/UPGRADE-1.3.md @@ -250,6 +250,11 @@ set. * The `Doctrine\ODM\MongoDB\Query\Query::prepareCursor` method will be removed in MongoDB ODM 2.0. You should wrap the returned cursor instead. +## Repositories + * The `Doctrine\ODM\MongoDB\DocumentRepository` class was deprecated in favor + of `Doctrine\ODM\MongoDB\Repository\DocumentRepository` and will be dropped + in 2.0. + ## Schema manager * The `timeout` option in the `odm:schema:create` and `odm:schema:update` diff --git a/lib/Doctrine/ODM/MongoDB/Configuration.php b/lib/Doctrine/ODM/MongoDB/Configuration.php index ca7ff3e134..750f50d043 100644 --- a/lib/Doctrine/ODM/MongoDB/Configuration.php +++ b/lib/Doctrine/ODM/MongoDB/Configuration.php @@ -31,6 +31,7 @@ use Doctrine\ODM\MongoDB\PersistentCollection\PersistentCollectionFactory; use Doctrine\ODM\MongoDB\PersistentCollection\PersistentCollectionGenerator; use Doctrine\ODM\MongoDB\Repository\DefaultRepositoryFactory; +use Doctrine\ODM\MongoDB\Repository\DocumentRepository as NewDocumentRepository; use Doctrine\ODM\MongoDB\Repository\RepositoryFactory; /** @@ -587,7 +588,7 @@ public function getDefaultDocumentRepositoryClassName() { return isset($this->attributes['defaultDocumentRepositoryClassName']) ? $this->attributes['defaultDocumentRepositoryClassName'] - : DocumentRepository::class; + : NewDocumentRepository::class; } /** diff --git a/lib/Doctrine/ODM/MongoDB/DocumentRepository.php b/lib/Doctrine/ODM/MongoDB/DocumentRepository.php index 8f42af6184..c078e7625b 100644 --- a/lib/Doctrine/ODM/MongoDB/DocumentRepository.php +++ b/lib/Doctrine/ODM/MongoDB/DocumentRepository.php @@ -1,313 +1,30 @@ . - */ namespace Doctrine\ODM\MongoDB; -use Doctrine\Common\Collections\ArrayCollection; -use Doctrine\Common\Collections\Collection; -use Doctrine\Common\Collections\Criteria; -use Doctrine\Common\Collections\Selectable; -use Doctrine\Common\Inflector\Inflector; -use Doctrine\Common\Persistence\ObjectRepository; -use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; -use Doctrine\ODM\MongoDB\Query\QueryExpressionVisitor; +use Doctrine\ODM\MongoDB\Repository\DocumentRepository as BaseDocumentRepository; +use const E_USER_DEPRECATED; +use function class_exists; +use function sprintf; +use function trigger_error; -/** - * A DocumentRepository serves as a repository for documents with generic as well as - * business specific methods for retrieving documents. - * - * This class is designed for inheritance and users can subclass this class to - * write their own repositories with business-specific methods to locate documents. - * - * @since 1.0 - */ -class DocumentRepository implements ObjectRepository, Selectable -{ - /** - * @var string - */ - protected $documentName; - - /** - * @var DocumentManager - */ - protected $dm; - - /** - * @var UnitOfWork - */ - protected $uow; - - /** - * @var ClassMetadata - */ - protected $class; - - /** - * Initializes this instance with the specified document manager, unit of work and - * class metadata. - * - * @param DocumentManager $dm The DocumentManager to use. - * @param UnitOfWork $uow The UnitOfWork to use. - * @param ClassMetadata $classMetadata The class metadata. - */ - public function __construct(DocumentManager $dm, UnitOfWork $uow, ClassMetadata $classMetadata) - { - $this->documentName = $classMetadata->name; - $this->dm = $dm; - $this->uow = $uow; - $this->class = $classMetadata; - } - - /** - * Creates a new Query\Builder instance that is preconfigured for this document name. - * - * @return Query\Builder $qb - */ - public function createQueryBuilder() - { - return $this->dm->createQueryBuilder($this->documentName); - } - - /** - * Creates a new Aggregation\Builder instance that is prepopulated for this document name. - * - * @return Aggregation\Builder - */ - public function createAggregationBuilder() - { - return $this->dm->createAggregationBuilder($this->documentName); - } - - /** - * Clears the repository, causing all managed documents to become detached. - */ - public function clear() - { - $this->dm->clear($this->class->rootDocumentName); - } - - /** - * Finds a document matching the specified identifier. Optionally a lock mode and - * expected version may be specified. - * - * @param mixed $id Identifier. - * @param int $lockMode Optional. Lock mode; one of the LockMode constants. - * @param int $lockVersion Optional. Expected version. - * @throws Mapping\MappingException - * @throws LockException - * @return object|null The document, if found, otherwise null. - */ - public function find($id, $lockMode = LockMode::NONE, $lockVersion = null) - { - if ($id === null) { - return null; - } - - /* TODO: What if the ID object has a field with the same name as the - * class' mapped identifier field name? - */ - if (is_array($id)) { - list($identifierFieldName) = $this->class->getIdentifierFieldNames(); - - if (isset($id[$identifierFieldName])) { - $id = $id[$identifierFieldName]; - } - } - - // Check identity map first - if ($document = $this->uow->tryGetById($id, $this->class)) { - if ($lockMode !== LockMode::NONE) { - $this->dm->lock($document, $lockMode, $lockVersion); - } - - return $document; // Hit! - } - - $criteria = array('_id' => $id); - - if ($lockMode === LockMode::NONE) { - return $this->getDocumentPersister()->load($criteria); - } - - if ($lockMode === LockMode::OPTIMISTIC) { - if (!$this->class->isVersioned) { - throw LockException::notVersioned($this->documentName); - } - if ($document = $this->getDocumentPersister()->load($criteria)) { - $this->uow->lock($document, $lockMode, $lockVersion); - } - - return $document; - } - - return $this->getDocumentPersister()->load($criteria, null, array(), $lockMode); - } - - /** - * Finds all documents in the repository. - * - * @return array - */ - public function findAll() - { - return $this->findBy(array()); - } - - /** - * Finds documents by a set of criteria. - * - * @param array $criteria Query criteria - * @param array $sort Sort array for Cursor::sort() - * @param integer|null $limit Limit for Cursor::limit() - * @param integer|null $skip Skip for Cursor::skip() - * - * @return array - */ - public function findBy(array $criteria, array $sort = null, $limit = null, $skip = null) - { - return $this->getDocumentPersister()->loadAll($criteria, $sort, $limit, $skip)->toArray(false); - } - - /** - * Finds a single document by a set of criteria. - * - * @param array $criteria - * @return object - */ - public function findOneBy(array $criteria) - { - return $this->getDocumentPersister()->load($criteria); - } - - /** - * Adds support for magic finders. - * - * @param string $method - * @param array $arguments - * @throws MongoDBException - * @throws \BadMethodCallException If the method called is an invalid find* method - * or no find* method at all and therefore an invalid - * method call. - * @return array|object The found document/documents. - * - * @deprecated method was deprecated in 1.2 and will be removed in 2.0 - */ - public function __call($method, $arguments) - { - @trigger_error( - 'Using magic findBy and findOneBy calls was deprecated in version 1.2 and will be removed altogether in 2.0.', - E_USER_DEPRECATED - ); - if (strpos($method, 'findBy') === 0) { - $by = substr($method, 6, strlen($method)); - $method = 'findBy'; - } elseif (strpos($method, 'findOneBy') === 0) { - $by = substr($method, 9, strlen($method)); - $method = 'findOneBy'; - } else { - throw new \BadMethodCallException( - "Undefined method: '$method'. The method name must start with 'findBy' or 'findOneBy'!" - ); - } - - if (!isset($arguments[0])) { - throw MongoDBException::findByRequiresParameter($method . $by); - } - - $fieldName = Inflector::camelize($by); - - if ($this->class->hasField($fieldName)) { - return $this->$method(array($fieldName => $arguments[0])); - } else { - throw MongoDBException::invalidFindByCall($this->documentName, $fieldName, $method . $by); - } - } - - /** - * @return string - */ - public function getDocumentName() - { - return $this->documentName; - } - - /** - * @return DocumentManager - */ - public function getDocumentManager() - { - return $this->dm; - } - - /** - * @return Mapping\ClassMetadata - */ - public function getClassMetadata() - { - return $this->class; - } +if (! class_exists(BaseDocumentRepository::class, false)) { + @trigger_error(sprintf('The "%s" class is deprecated and will be removed in 2.0. Use "%s" instead.', DocumentRepository::class, BaseDocumentRepository::class), E_USER_DEPRECATED); +} - /** - * @return string - */ - public function getClassName() - { - return $this->getDocumentName(); - } +class_alias(BaseDocumentRepository::class, DocumentRepository::class); +if (false) { /** - * Selects all elements from a selectable that match the expression and - * returns a new collection containing these elements. + * This stub has two purposes: + * - it provides a class for IDEs so they still provide autocompletion for + * this class even when they don't support class_alias + * - it gets composer to think there's a class in here when using the + * --classmap-authoritative autoloader optimization. * - * @see Selectable::matching() - * @param Criteria $criteria - * @return Collection + * @deprecated in favor of \Doctrine\ODM\MongoDB\Repository\DocumentRepository */ - public function matching(Criteria $criteria) - { - $visitor = new QueryExpressionVisitor($this->createQueryBuilder()); - $queryBuilder = $this->createQueryBuilder(); - - if ($criteria->getWhereExpression() !== null) { - $expr = $visitor->dispatch($criteria->getWhereExpression()); - $queryBuilder->setQueryArray($expr->getQuery()); - } - - if ($criteria->getMaxResults() !== null) { - $queryBuilder->limit($criteria->getMaxResults()); - } - - if ($criteria->getFirstResult() !== null) { - $queryBuilder->skip($criteria->getFirstResult()); - } - - if ($criteria->getOrderings() !== null) { - $queryBuilder->sort($criteria->getOrderings()); - } - - // @TODO: wrap around a specialized Collection for efficient count on large collections - return new ArrayCollection($queryBuilder->getQuery()->execute()->toArray(false)); - } - - protected function getDocumentPersister() + class DocumentRepository extends BaseDocumentRepository { - return $this->uow->getDocumentPersister($this->documentName); } } diff --git a/lib/Doctrine/ODM/MongoDB/Repository/DocumentRepository.php b/lib/Doctrine/ODM/MongoDB/Repository/DocumentRepository.php new file mode 100644 index 0000000000..47832867a8 --- /dev/null +++ b/lib/Doctrine/ODM/MongoDB/Repository/DocumentRepository.php @@ -0,0 +1,325 @@ +. + */ + +namespace Doctrine\ODM\MongoDB\Repository; + +use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; +use Doctrine\Common\Collections\Criteria; +use Doctrine\Common\Collections\Selectable; +use Doctrine\Common\Inflector\Inflector; +use Doctrine\Common\Persistence\ObjectRepository; +use Doctrine\ODM\MongoDB\Aggregation\Builder as AggregationBuilder; +use Doctrine\ODM\MongoDB\DocumentManager; +use Doctrine\ODM\MongoDB\DocumentRepository as LegacyDocumentRepository; +use Doctrine\ODM\MongoDB\LockException; +use Doctrine\ODM\MongoDB\LockMode; +use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; +use Doctrine\ODM\MongoDB\Mapping\MappingException; +use Doctrine\ODM\MongoDB\MongoDBException; +use Doctrine\ODM\MongoDB\Query\Builder as QueryBuilder; +use Doctrine\ODM\MongoDB\Query\QueryExpressionVisitor; +use Doctrine\ODM\MongoDB\UnitOfWork; + +/** + * A DocumentRepository serves as a repository for documents with generic as well as + * business specific methods for retrieving documents. + * + * This class is designed for inheritance and users can subclass this class to + * write their own repositories with business-specific methods to locate documents. + * + * @since 1.0 + */ +class DocumentRepository implements ObjectRepository, Selectable +{ + /** + * @var string + */ + protected $documentName; + + /** + * @var DocumentManager + */ + protected $dm; + + /** + * @var UnitOfWork + */ + protected $uow; + + /** + * @var ClassMetadata + */ + protected $class; + + /** + * Initializes this instance with the specified document manager, unit of work and + * class metadata. + * + * @param DocumentManager $dm The DocumentManager to use. + * @param UnitOfWork $uow The UnitOfWork to use. + * @param ClassMetadata $classMetadata The class metadata. + */ + public function __construct(DocumentManager $dm, UnitOfWork $uow, ClassMetadata $classMetadata) + { + $this->documentName = $classMetadata->name; + $this->dm = $dm; + $this->uow = $uow; + $this->class = $classMetadata; + } + + /** + * Creates a new Query\Builder instance that is preconfigured for this document name. + * + * @return QueryBuilder $qb + */ + public function createQueryBuilder() + { + return $this->dm->createQueryBuilder($this->documentName); + } + + /** + * Creates a new Aggregation\Builder instance that is prepopulated for this document name. + * + * @return AggregationBuilder + */ + public function createAggregationBuilder() + { + return $this->dm->createAggregationBuilder($this->documentName); + } + + /** + * Clears the repository, causing all managed documents to become detached. + */ + public function clear() + { + $this->dm->clear($this->class->rootDocumentName); + } + + /** + * Finds a document matching the specified identifier. Optionally a lock mode and + * expected version may be specified. + * + * @param mixed $id Identifier. + * @param int $lockMode Optional. Lock mode; one of the LockMode constants. + * @param int $lockVersion Optional. Expected version. + * @throws MappingException + * @throws LockException + * @return object|null The document, if found, otherwise null. + */ + public function find($id, $lockMode = LockMode::NONE, $lockVersion = null) + { + if ($id === null) { + return null; + } + + /* TODO: What if the ID object has a field with the same name as the + * class' mapped identifier field name? + */ + if (is_array($id)) { + list($identifierFieldName) = $this->class->getIdentifierFieldNames(); + + if (isset($id[$identifierFieldName])) { + $id = $id[$identifierFieldName]; + } + } + + // Check identity map first + if ($document = $this->uow->tryGetById($id, $this->class)) { + if ($lockMode !== LockMode::NONE) { + $this->dm->lock($document, $lockMode, $lockVersion); + } + + return $document; // Hit! + } + + $criteria = array('_id' => $id); + + if ($lockMode === LockMode::NONE) { + return $this->getDocumentPersister()->load($criteria); + } + + if ($lockMode === LockMode::OPTIMISTIC) { + if (!$this->class->isVersioned) { + throw LockException::notVersioned($this->documentName); + } + if ($document = $this->getDocumentPersister()->load($criteria)) { + $this->uow->lock($document, $lockMode, $lockVersion); + } + + return $document; + } + + return $this->getDocumentPersister()->load($criteria, null, array(), $lockMode); + } + + /** + * Finds all documents in the repository. + * + * @return array + */ + public function findAll() + { + return $this->findBy(array()); + } + + /** + * Finds documents by a set of criteria. + * + * @param array $criteria Query criteria + * @param array $sort Sort array for Cursor::sort() + * @param integer|null $limit Limit for Cursor::limit() + * @param integer|null $skip Skip for Cursor::skip() + * + * @return array + */ + public function findBy(array $criteria, array $sort = null, $limit = null, $skip = null) + { + return $this->getDocumentPersister()->loadAll($criteria, $sort, $limit, $skip)->toArray(false); + } + + /** + * Finds a single document by a set of criteria. + * + * @param array $criteria + * @return object + */ + public function findOneBy(array $criteria) + { + return $this->getDocumentPersister()->load($criteria); + } + + /** + * Adds support for magic finders. + * + * @param string $method + * @param array $arguments + * @throws MongoDBException + * @throws \BadMethodCallException If the method called is an invalid find* method + * or no find* method at all and therefore an invalid + * method call. + * @return array|object The found document/documents. + * + * @deprecated method was deprecated in 1.2 and will be removed in 2.0 + */ + public function __call($method, $arguments) + { + @trigger_error( + 'Using magic findBy and findOneBy calls was deprecated in version 1.2 and will be removed altogether in 2.0.', + E_USER_DEPRECATED + ); + if (strpos($method, 'findBy') === 0) { + $by = substr($method, 6, strlen($method)); + $method = 'findBy'; + } elseif (strpos($method, 'findOneBy') === 0) { + $by = substr($method, 9, strlen($method)); + $method = 'findOneBy'; + } else { + throw new \BadMethodCallException( + "Undefined method: '$method'. The method name must start with 'findBy' or 'findOneBy'!" + ); + } + + if (!isset($arguments[0])) { + throw MongoDBException::findByRequiresParameter($method . $by); + } + + $fieldName = Inflector::camelize($by); + + if ($this->class->hasField($fieldName)) { + return $this->$method(array($fieldName => $arguments[0])); + } else { + throw MongoDBException::invalidFindByCall($this->documentName, $fieldName, $method . $by); + } + } + + /** + * @return string + */ + public function getDocumentName() + { + return $this->documentName; + } + + /** + * @return DocumentManager + */ + public function getDocumentManager() + { + return $this->dm; + } + + /** + * @return ClassMetadata + */ + public function getClassMetadata() + { + return $this->class; + } + + /** + * @return string + */ + public function getClassName() + { + return $this->getDocumentName(); + } + + /** + * Selects all elements from a selectable that match the expression and + * returns a new collection containing these elements. + * + * @see Selectable::matching() + * @param Criteria $criteria + * @return Collection + */ + public function matching(Criteria $criteria) + { + $visitor = new QueryExpressionVisitor($this->createQueryBuilder()); + $queryBuilder = $this->createQueryBuilder(); + + if ($criteria->getWhereExpression() !== null) { + $expr = $visitor->dispatch($criteria->getWhereExpression()); + $queryBuilder->setQueryArray($expr->getQuery()); + } + + if ($criteria->getMaxResults() !== null) { + $queryBuilder->limit($criteria->getMaxResults()); + } + + if ($criteria->getFirstResult() !== null) { + $queryBuilder->skip($criteria->getFirstResult()); + } + + if ($criteria->getOrderings() !== null) { + $queryBuilder->sort($criteria->getOrderings()); + } + + // @TODO: wrap around a specialized Collection for efficient count on large collections + return new ArrayCollection($queryBuilder->getQuery()->execute()->toArray(false)); + } + + protected function getDocumentPersister() + { + return $this->uow->getDocumentPersister($this->documentName); + } +} + +// Autoload legacy class to ensure class aliasing works as expected +class_exists(LegacyDocumentRepository::class); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/OrphanRemovalEmbedTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/OrphanRemovalEmbedTest.php index 2da2f47a3d..ce851d2e9a 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/OrphanRemovalEmbedTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/OrphanRemovalEmbedTest.php @@ -3,6 +3,7 @@ namespace Doctrine\ODM\MongoDB\Tests\Functional; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; +use Doctrine\ODM\MongoDB\Repository\DocumentRepository; /** * Test the orphan removal on embedded documents that contain references with cascade operations. @@ -137,7 +138,7 @@ public function testClearAndAddEmbedMany() } /** - * @return \Doctrine\ODM\MongoDB\DocumentRepository + * @return DocumentRepository */ private function getUserRepository() { @@ -145,7 +146,7 @@ private function getUserRepository() } /** - * @return \Doctrine\ODM\MongoDB\DocumentRepository + * @return DocumentRepository */ private function getAddressRepository() { diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/OrphanRemovalTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/OrphanRemovalTest.php index 1943f48db2..421f260ceb 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/OrphanRemovalTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/OrphanRemovalTest.php @@ -3,6 +3,7 @@ namespace Doctrine\ODM\MongoDB\Tests\Functional; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; +use Doctrine\ODM\MongoDB\Repository\DocumentRepository; class OrphanRemovalTest extends \Doctrine\ODM\MongoDB\Tests\BaseTest { @@ -276,7 +277,7 @@ public function testOrphanRemovalReferenceManyOnRemoveWithoutCascade() } /** - * @return \Doctrine\ODM\MongoDB\DocumentRepository + * @return DocumentRepository */ private function getUserRepository() { @@ -284,7 +285,7 @@ private function getUserRepository() } /** - * @return \Doctrine\ODM\MongoDB\DocumentRepository + * @return DocumentRepository */ private function getProfileRepository() { diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1232Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1232Test.php index 16c1e468ea..4d2699c408 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1232Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1232Test.php @@ -3,8 +3,8 @@ namespace Doctrine\ODM\MongoDB\Tests\Functional\Ticket; use Doctrine\Common\Collections\ArrayCollection; -use Doctrine\ODM\MongoDB\DocumentRepository; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; +use Doctrine\ODM\MongoDB\Repository\DocumentRepository; class GH1232Test extends \Doctrine\ODM\MongoDB\Tests\BaseTest { diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1572Test.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1572Test.php index d3854d432a..8b3dc4aee7 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1572Test.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1572Test.php @@ -2,9 +2,9 @@ namespace Doctrine\ODM\MongoDB\Tests\Functional\Ticket; -use Doctrine\ODM\MongoDB\DocumentRepository; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; use Doctrine\ODM\MongoDB\PersistentCollection\PersistentCollectionInterface; +use Doctrine\ODM\MongoDB\Repository\DocumentRepository; use Doctrine\ODM\MongoDB\Tests\BaseTest; class GH1572Test extends BaseTest diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest.php index a0cf628492..5363da4f38 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest.php @@ -2,11 +2,11 @@ namespace Doctrine\ODM\MongoDB\Tests\Mapping; -use Doctrine\ODM\MongoDB\DocumentRepository; use Doctrine\ODM\MongoDB\Events; use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; use Doctrine\ODM\MongoDB\Mapping\MappingException; +use Doctrine\ODM\MongoDB\Repository\DocumentRepository; use Doctrine\ODM\MongoDB\Utility\CollectionHelper; use Documents\Album; use Documents\CmsUser; diff --git a/tests/Documents/BaseCategoryRepository.php b/tests/Documents/BaseCategoryRepository.php index 3522b847ae..af13a34ed4 100644 --- a/tests/Documents/BaseCategoryRepository.php +++ b/tests/Documents/BaseCategoryRepository.php @@ -2,6 +2,8 @@ namespace Documents; -use Doctrine\ODM\MongoDB\DocumentRepository; +use Doctrine\ODM\MongoDB\Repository\DocumentRepository; -class BaseCategoryRepository extends DocumentRepository {} \ No newline at end of file +class BaseCategoryRepository extends DocumentRepository +{ +} diff --git a/tests/Documents/CommentRepository.php b/tests/Documents/CommentRepository.php index 672f22c374..78db2a50fe 100644 --- a/tests/Documents/CommentRepository.php +++ b/tests/Documents/CommentRepository.php @@ -2,7 +2,7 @@ namespace Documents; -use Doctrine\ODM\MongoDB\DocumentRepository; +use Doctrine\ODM\MongoDB\Repository\DocumentRepository; /** FIXME: reflection chokes if this class doesn't have a doc comment */ class CommentRepository extends DocumentRepository diff --git a/tests/Documents/CustomRepository/Repository.php b/tests/Documents/CustomRepository/Repository.php index de22bffa3d..8962973b70 100644 --- a/tests/Documents/CustomRepository/Repository.php +++ b/tests/Documents/CustomRepository/Repository.php @@ -2,6 +2,8 @@ namespace Documents\CustomRepository; -use Doctrine\ODM\MongoDB\DocumentRepository; +use Doctrine\ODM\MongoDB\Repository\DocumentRepository; -class Repository extends DocumentRepository {} +class Repository extends DocumentRepository +{ +} diff --git a/tools/sandbox/Documents/UserRepository.php b/tools/sandbox/Documents/UserRepository.php index 0bd203e357..4b3fa58a80 100644 --- a/tools/sandbox/Documents/UserRepository.php +++ b/tools/sandbox/Documents/UserRepository.php @@ -2,7 +2,7 @@ namespace Documents; -use Doctrine\ODM\MongoDB\DocumentRepository; +use Doctrine\ODM\MongoDB\Repository\DocumentRepository; /** * UserRepository From 151901226f94177a5a5b9cfb09e88d9246c6eaf6 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Tue, 23 Apr 2019 10:30:54 +0200 Subject: [PATCH 5/5] Document more BC breaks --- UPGRADE-1.3.md | 7 +++++++ .../ODM/MongoDB/Aggregation/Stage/Bucket.php | 4 ++++ .../ODM/MongoDB/Aggregation/Stage/BucketAuto.php | 4 ++++ .../ODM/MongoDB/Aggregation/Stage/GraphLookup.php | 8 ++++++++ .../ODM/MongoDB/Aggregation/Stage/Match.php | 14 ++++++++++++++ .../ODM/MongoDB/Aggregation/Stage/ReplaceRoot.php | 4 ++++ lib/Doctrine/ODM/MongoDB/Query/Builder.php | 15 +++++++++++++++ lib/Doctrine/ODM/MongoDB/Query/Expr.php | 15 +++++++++++++++ 8 files changed, 71 insertions(+) diff --git a/UPGRADE-1.3.md b/UPGRADE-1.3.md index 2a31645245..6cd404b230 100644 --- a/UPGRADE-1.3.md +++ b/UPGRADE-1.3.md @@ -15,6 +15,9 @@ will be private in 2.0: `convertExpression`, `convertTargetFieldName`. * The `Doctrine\ODM\MongoDB\Aggregation\Stage\ReplaceRoot::convertExpression` method will be private in 2.0. + * Calling `Doctrine\MongoDB\Aggregation\Stage\Match::geoWithinPolygon` with + fewer than 3 arguments was deprecated and will cause errors in 2.0. A polygon + must have at least 3 edges to be considered valid. ## Configuration @@ -249,6 +252,10 @@ set. `TYPE_GEO_NEAR`. * The `Doctrine\ODM\MongoDB\Query\Query::prepareCursor` method will be removed in MongoDB ODM 2.0. You should wrap the returned cursor instead. + * Calling `Doctrine\MongoDB\Query\Builder::geoWithinPolygon` and + `Doctrine\MongoDB\Query\Expr::geoWithinPolygon` with fewer than 3 arguments + was deprecated and will cause errors in 2.0. A polygon must have at least 3 + edges to be considered valid. ## Repositories * The `Doctrine\ODM\MongoDB\DocumentRepository` class was deprecated in favor diff --git a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Bucket.php b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Bucket.php index 5d20369879..b86c5c2a09 100644 --- a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Bucket.php +++ b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Bucket.php @@ -47,6 +47,10 @@ public function __construct(Builder $builder, DocumentManager $documentManager, protected function convertExpression($expression) { + if (self::class !== static::class) { + @trigger_error(sprintf('The "%s" method will be private in MongoDB ODM 2.0. You should not rely on calling this method.', __METHOD__), E_USER_DEPRECATED); + } + if (is_array($expression)) { return array_map([$this, 'convertExpression'], $expression); } elseif (is_string($expression) && substr($expression, 0, 1) === '$') { diff --git a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/BucketAuto.php b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/BucketAuto.php index eaebbd4ea7..286a66b815 100644 --- a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/BucketAuto.php +++ b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/BucketAuto.php @@ -47,6 +47,10 @@ public function __construct(Builder $builder, DocumentManager $documentManager, protected function convertExpression($expression) { + if (self::class !== static::class) { + @trigger_error(sprintf('The "%s" method will be private in MongoDB ODM 2.0. You should not rely on calling this method.', __METHOD__), E_USER_DEPRECATED); + } + if (is_array($expression)) { return array_map([$this, 'convertExpression'], $expression); } elseif (is_string($expression) && substr($expression, 0, 1) === '$') { diff --git a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/GraphLookup.php b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/GraphLookup.php index 2521576b76..2e7b79d051 100644 --- a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/GraphLookup.php +++ b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/GraphLookup.php @@ -155,6 +155,10 @@ private function fromReference($fieldName) protected function convertExpression($expression) { + if (self::class !== static::class) { + @trigger_error(sprintf('The "%s" method will be private in MongoDB ODM 2.0. You should not rely on calling this method.', __METHOD__), E_USER_DEPRECATED); + } + if (is_array($expression)) { return array_map([$this, 'convertExpression'], $expression); } elseif (is_string($expression) && substr($expression, 0, 1) === '$') { @@ -166,6 +170,10 @@ protected function convertExpression($expression) protected function convertTargetFieldName($fieldName) { + if (self::class !== static::class) { + @trigger_error(sprintf('The "%s" method will be private in MongoDB ODM 2.0. You should not rely on calling this method.', __METHOD__), E_USER_DEPRECATED); + } + if (is_array($fieldName)) { return array_map([$this, 'convertTargetFieldName'], $fieldName); } diff --git a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Match.php b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Match.php index 5051587514..016a84fb47 100644 --- a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Match.php +++ b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Match.php @@ -22,6 +22,8 @@ use Doctrine\MongoDB\Aggregation\Stage as BaseStage; use const E_USER_DEPRECATED; use function sprintf; +use function func_get_args; +use function func_num_args; use function trigger_error; /** @@ -63,6 +65,18 @@ public function debug($name = null) return parent::debug($name); } + /** + * {@inheritdoc} + */ + public function geoWithinPolygon() + { + if (func_num_args() < 3) { + @trigger_error(sprintf('Calling "%s" with fewer than 3 arguments was deprecated in MongoDB ODM 1.3 and will require at least 3 arguments in 2.0.', __METHOD__), E_USER_DEPRECATED); + } + + return parent::geoWithinPolygon(...func_get_args()); + } + /** * {@inheritdoc} * diff --git a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/ReplaceRoot.php b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/ReplaceRoot.php index 4d86730f43..6d7caa60f8 100644 --- a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/ReplaceRoot.php +++ b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/ReplaceRoot.php @@ -47,6 +47,10 @@ public function __construct(Builder $builder, DocumentManager $documentManager, protected function convertExpression($expression) { + if (self::class !== static::class) { + @trigger_error(sprintf('The "%s" method will be private in MongoDB ODM 2.0. You should not rely on calling this method.', __METHOD__), E_USER_DEPRECATED); + } + if (is_array($expression)) { return array_map([$this, 'convertExpression'], $expression); } elseif (is_string($expression) && substr($expression, 0, 1) === '$') { diff --git a/lib/Doctrine/ODM/MongoDB/Query/Builder.php b/lib/Doctrine/ODM/MongoDB/Query/Builder.php index d0435cce34..7fde5b9317 100644 --- a/lib/Doctrine/ODM/MongoDB/Query/Builder.php +++ b/lib/Doctrine/ODM/MongoDB/Query/Builder.php @@ -654,6 +654,21 @@ public function geoNear($x, $y = null) return parent::geoNear($x, $y); } + /** + * {@inheritdoc} + */ + public function geoWithinPolygon() + { + if (func_num_args() < 3) { + @trigger_error( + sprintf('Calling "%s" with fewer than 3 arguments was deprecated in MongoDB ODM 1.3 and will require at least 3 arguments in 2.0.', __METHOD__), + E_USER_DEPRECATED + ); + } + + return parent::geoWithinPolygon(...func_get_args()); + } + /** * @inheritdoc * @deprecated Deprecated in version 1.3 - use Aggregation Pipeline instead diff --git a/lib/Doctrine/ODM/MongoDB/Query/Expr.php b/lib/Doctrine/ODM/MongoDB/Query/Expr.php index 474fc43dd9..6f67f3cd51 100644 --- a/lib/Doctrine/ODM/MongoDB/Query/Expr.php +++ b/lib/Doctrine/ODM/MongoDB/Query/Expr.php @@ -245,6 +245,21 @@ private function getReferenceMapping() return $mapping; } + /** + * {@inheritdoc} + */ + public function geoWithinPolygon() + { + if (func_num_args() < 3) { + @trigger_error( + sprintf('Calling "%s" with fewer than 3 arguments was deprecated in MongoDB ODM 1.3 and will require at least 3 arguments in 2.0.', __METHOD__), + E_USER_DEPRECATED + ); + } + + return parent::geoWithinPolygon(...func_get_args()); + } + /** * @inheritdoc * @deprecated Deprecated in version 1.3 - use Aggregation Pipeline instead