Skip to content

Commit

Permalink
Deprecate setDefaultRepositoryClassName and getDefaultRepositoryClass…
Browse files Browse the repository at this point in the history
…Name
  • Loading branch information
malarzm committed Aug 4, 2018
1 parent e7c926b commit c37348f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
42 changes: 35 additions & 7 deletions lib/Doctrine/ODM/MongoDB/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -505,27 +505,55 @@ 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;
}

/**
* Get default repository class.
*
* @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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit c37348f

Please sign in to comment.