From 34fddd36c3f832810ea52966f2e05a13613fd0d5 Mon Sep 17 00:00:00 2001 From: Maciej Malarz Date: Sat, 4 Aug 2018 20:44:54 +0200 Subject: [PATCH] Deprecate setDefaultRepositoryClassName and getDefaultRepositoryClassName --- lib/Doctrine/ODM/MongoDB/Configuration.php | 42 +++++++++++++++---- .../Repository/AbstractRepositoryFactory.php | 2 +- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/lib/Doctrine/ODM/MongoDB/Configuration.php b/lib/Doctrine/ODM/MongoDB/Configuration.php index b1f6a35afc..1076ba2e97 100644 --- a/lib/Doctrine/ODM/MongoDB/Configuration.php +++ b/lib/Doctrine/ODM/MongoDB/Configuration.php @@ -505,16 +505,44 @@ public function getFilterParameters($name) * @return void * * @throws MongoDBException If not is a ObjectRepository + * + * @deprecated in version 1.2 and will be removed in 2.0. Please use setDefaultDocumentRepositoryClassName instead. */ public function setDefaultRepositoryClassName($className) { - $reflectionClass = new \ReflectionClass($className); + @trigger_error( + sprintf('%s was deprecated in version 1.2 and will be removed in 2.0. Please use setDefaultDocumentRepositoryClassName instead.', __METHOD__), + E_USER_DEPRECATED + ); + $this->setDefaultDocumentRepositoryClassName($className); + } - if ( ! $reflectionClass->implementsInterface(ObjectRepository::class)) { + /** + * Get default repository class. + * + * @return string + * + * @deprecated in version 1.2 and will be removed in 2.0. Please use getDefaultDocumentRepositoryClassName instead. + */ + 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__), + E_USER_DEPRECATED + ); + return $this->getDefaultDocumentRepositoryClassName(); + } + + /** + * @throws MongoDBException If not is a ObjectRepository. + */ + public function setDefaultDocumentRepositoryClassName($className) + { + $reflectionClass = new \ReflectionClass($className); + if (! $reflectionClass->implementsInterface(ObjectRepository::class)) { throw MongoDBException::invalidDocumentRepository($className); } - - $this->attributes['defaultRepositoryClassName'] = $className; + $this->attributes['defaultDocumentRepositoryClassName'] = $className; } /** @@ -522,10 +550,10 @@ public function setDefaultRepositoryClassName($className) * * @return string */ - public function getDefaultRepositoryClassName() + public function getDefaultDocumentRepositoryClassName() { - return isset($this->attributes['defaultRepositoryClassName']) - ? $this->attributes['defaultRepositoryClassName'] + return isset($this->attributes['defaultDocumentRepositoryClassName']) + ? $this->attributes['defaultDocumentRepositoryClassName'] : DocumentRepository::class; } diff --git a/lib/Doctrine/ODM/MongoDB/Repository/AbstractRepositoryFactory.php b/lib/Doctrine/ODM/MongoDB/Repository/AbstractRepositoryFactory.php index 4201966495..f760e25a50 100644 --- a/lib/Doctrine/ODM/MongoDB/Repository/AbstractRepositoryFactory.php +++ b/lib/Doctrine/ODM/MongoDB/Repository/AbstractRepositoryFactory.php @@ -67,7 +67,7 @@ public function getRepository(DocumentManager $documentManager, $documentName) protected function createRepository(DocumentManager $documentManager, $documentName) { $metadata = $documentManager->getClassMetadata($documentName); - $repositoryClassName = $metadata->customRepositoryClassName ?: $documentManager->getConfiguration()->getDefaultRepositoryClassName(); + $repositoryClassName = $metadata->customRepositoryClassName ?: $documentManager->getConfiguration()->getDefaultDocumentRepositoryClassName(); return $this->instantiateRepository($repositoryClassName, $documentManager, $metadata); }