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

Support doctrine/persistence 4.0 #2913

Merged
merged 1 commit into from
Feb 1, 2025
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ a release.
---

## [Unreleased]
### Added
- Support for `doctrine/persistence` ^4.0

### Deprecated
- Sluggable: Annotation-specific mapping parameters (#2837)

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"doctrine/collections": "^1.2 || ^2.0",
"doctrine/deprecations": "^1.0",
"doctrine/event-manager": "^1.2 || ^2.0",
"doctrine/persistence": "^2.2 || ^3.0",
"doctrine/persistence": "^2.2 || ^3.0 || ^4.0",
"psr/cache": "^1 || ^2 || ^3",
"psr/clock": "^1",
"symfony/cache": "^5.4 || ^6.0 || ^7.0"
Expand Down
22 changes: 8 additions & 14 deletions src/References/ReferencesListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,12 @@ public function postLoad(EventArgs $eventArgs)
$property->setValue(
$object,
new LazyCollection(
static function () use ($id, &$manager, $class, $identifier) {
$results = $manager
->getRepository($class)
static fn () => new ArrayCollection(
$manager->getRepository($class)
->findBy([
$identifier => $id,
]);

return new ArrayCollection(is_array($results) ? $results : $results->toArray());
}
])
)
Comment on lines +129 to +134
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Persistence 4.0 adds the array return type to ObjectRepository::findBy(), so the is_array() check isn't needed anymore and I've just simplified this down to an arrow function. Same below.

)
);
}
Expand Down Expand Up @@ -235,15 +232,12 @@ public function updateManyEmbedReferences(EventArgs $eventArgs)
$property->setValue(
$object,
new LazyCollection(
static function () use ($id, &$manager, $class, $identifier) {
$results = $manager
->getRepository($class)
static fn () => new ArrayCollection(
$manager->getRepository($class)
->findBy([
$identifier => $id,
]);

return new ArrayCollection(is_array($results) ? $results : $results->toArray());
}
])
)
)
);
}
Expand Down