Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.3] Deprecate setDefaultRepositoryClassName and getDefaultRepositoryClassName #1840

Merged
merged 1 commit into from
Sep 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a tiny BC break: people May have extended this class and expect to find the attribute with the old name. Not sure if we want to deal with that, just bringing it up.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is attributes not private because we currently extended from doctrine/mongodb?

Dealing with this would likely require the new method to ensure both keys are set, but that still wouldn't guarantee they don't get out of sync by some outside forces.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is attributes not private because we currently extended from doctrine/mongodb?

Nevermind. attributes is private, so there's no issue here apart from me not being able to read properly 👍

? $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