Add LookupStrategy to DoctrineWriter (port of #11 for 2.x) - #31
Merged
Conversation
Rebase/port of #11 onto the 2.0 line (PHP ^8.2, doctrine/persistence, typed writer APIs). Adds: - Port\Doctrine\LookupStrategy interface - Port\Doctrine\LookupStrategy\FieldsLookupStrategy (default) - DoctrineWriter::withLookupStrategy() factory - Optional 5th constructor arg for a custom strategy BC preserved for 2.x: - Constructor ($objectManager, $objectName, $index, $lookupMethod) unchanged - Default truncate=true still creates new instances without looking up - disableTruncate + empty index still uses repository find(current($item)) - disableTruncate + $index still uses findOneBy (or custom method) criteria - Null lookup results still create a new entity (original #11 regressed this) Fixes in the port vs original #11: - withLookupFields mutates the clone (was mutating $this) - withIndex implemented (original called a missing method) - Factory arg order matches constructor (ObjectManager first) - Factory no longer passes LookupStrategy as the $lookupMethod string - lookupMethod stays a method name string (not a mixed callable) - Doctrine\Persistence namespaces; PHP 8.2 types - No deprecation of $index/$lookupMethod in 2.x (additive API) Closes #3 (custom strategies can use QueryBuilder). Supersedes #11.
Contributor
Author
|
@copilot please review this PR when quota allows. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Port of stale #11 (“Add lookup strategy to writer”, ddeboer, 2017) onto current 2.0 master (PHP ^8.2, portphp ^2, doctrine/common ^3 /
Doctrine\Persistence).Related: #3 (custom QueryBuilder lookups), discussion in #9.
What lands
Port\Doctrine\LookupStrategylookup(array $item): ?objectLookupStrategy\FieldsLookupStrategyDoctrineWriter::withLookupStrategy()?LookupStrategyDefault / BC behavior (2.x)
No intentional BC break for existing 2.x call sites:
new DoctrineWriter($om, $class)— unchangednew DoctrineWriter($om, $class, $index, $lookupMethod)— unchangedtruncate = true(default) still always creates a new instance (no lookup)disableTruncate()+ no index →ObjectRepository::find(current($item))disableTruncate()+ index → repository method (defaultfindOneBy) with field criterianull) → create new instance (upsert-friendly)$index/$lookupMethodare not deprecated in 2.x; LookupStrategy is additive. Deprecating those args can wait for a 3.0 discussion.Fixes vs original #11
The 2017 branch was incomplete and could not be cleanly rebased (CONFLICTING). Notable bugs fixed in this port:
withLookupFieldsmutated$thisinstead of the clonewithIndex()onFieldsLookupStrategyLookupStrategyas the 4th ctor arg ($lookupMethodstring) — type error / broken API($objectName, $om, $strategy); now($om, $objectName, $strategy)to match the constructorfindOrCreateItemreturnednullfrom strategy without creating a new entity (regression)find(current($item))behaviorDoctrine\Persistence), PHP 8.2 types, PHPUnit 9Usage
Tests
$indexpath, FieldsLookupStrategy immutability, invalid methodOriginal #11
Please close #11 as superseded once this merges (do not merge #11).
Checklist