-
-
Notifications
You must be signed in to change notification settings - Fork 455
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
Add type declarations where backwards compatible #1122
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,7 @@ public function __construct(ContainerInterface $container = null) | |
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getRepository(EntityManagerInterface $entityManager, $entityName) | ||
public function getRepository(EntityManagerInterface $entityManager, $entityName) : ObjectRepository | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change is in fact a BC break because before repositories were not enforced to be subclass of ObjectRepository. Now they have to be otherwise this will crash on TypeError. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Precisely. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @andrew-demb Yes but in Symfony ContainerRepositoryFactory overrides default RepositoryFactory from Doctrine, making it a BC break. Not a BC break in the contract of this class but a BC break in the bundle itself. It's no longer possible to use custom repositories not extending ObjectRepository and doing so makes the app crash due to this added typehint. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's been documented as supposed to be repositories were not enforced to be subclass of ObjectRepository because type declarations did not exist back then, but even if the contract is not enforced, it's still a contract. Call me heartless, but I can't say I feel sorry for apps experiencing this crash, they kind of had it coming, don't you agree? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't agree, this kind of stuff does not belong to a patch version. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Requirement for the It was also never validated:
There is return annotation for
It's not nice "feature" and I don't like it either but it was working and documented behaviour ("You can overwrite this behaviour by specifying the class name of your own Entity Repository in the Annotation, XML or YAML metadata."). I don't personally need this "feature" but I don't think this should've been merged as is. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
You are, as always, entitled to your opinion. To look at the facts: I don't know where you see the BC break, but if we treat docblocks as a contract (which we always have and always should), this change is perfectly fine. You are always welcome to improve documentation which is clearly wrong in this case, as the code contains the absolute truth, which is that the contract always specified an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The BC break I see is that upgrading doctrine/doctrine-bundle from 2.0.6 to 2.0.7 leads to fatal errors.
The code can actually contain bugs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Please post an example that passes on 2.0.6 and produces a fatal error on 2.0.7 and I'll fix it. Thanks! |
||
{ | ||
$metadata = $entityManager->getClassMetadata($entityName); | ||
$repositoryServiceId = $metadata->customRepositoryClassName; | ||
|
@@ -72,8 +72,10 @@ public function getRepository(EntityManagerInterface $entityManager, $entityName | |
return $this->getOrCreateRepository($entityManager, $metadata); | ||
} | ||
|
||
private function getOrCreateRepository(EntityManagerInterface $entityManager, ClassMetadata $metadata) | ||
{ | ||
private function getOrCreateRepository( | ||
EntityManagerInterface $entityManager, | ||
ClassMetadata $metadata | ||
) : ObjectRepository { | ||
$repositoryHash = $metadata->getName() . spl_object_hash($entityManager); | ||
if (isset($this->managedRepositories[$repositoryHash])) { | ||
return $this->managedRepositories[$repositoryHash]; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look useful