Make identifier resolution resource aware in the Doctrine and Eloquent links handlers
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 48/100
Direzione di ricerca
Inizia da getIdentifierValue() e dai suoi sei punti di chiamata Doctrine in src/Doctrine/Common/State/LinksHandlerTrait.php, quindi analizza PersistProcessor e il percorso Eloquent buildQuery() in src/Laravel/Eloquent/State/LinksHandler.php. Esegui LinkProviderParameterTest::testLinkSecurityWithSlug e verifica il comportamento dell’identificatore consapevole della risorsa in Doctrine ORM, ODM e Laravel, senza modificare la struttura della query.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Follow-up to #8491.
#8491 lets a uri variable's parameter provider transform the value used to query the resource, and lets ReadLinkParameterProvider opt into writing the resolved resource into the uri variables (constructor flag, or the write_uri_variable extra property per link). Working on the resource rather than the identifier is usually easier when writing a custom provider.
That opt-in currently only works for resources whose provider does not query a persistence layer. On a Doctrine-backed link it fails with:
Object of class App\Entity\Company could not be converted to string
because the links handler compares the identifier column and binds the value with an explicit Doctrine type:
// src/Doctrine/Orm/State/LinksHandlerTrait.php
$queryBuilder->andWhere("$joinAlias.$identifierProperty = :$placeholder");
$queryBuilder->setParameter(
$placeholder,
$this->getIdentifierValue($identifiers, $hasCompositeIdentifiers ? $identifierProperty : null),
$fromClassMetadata->getTypeOfField($identifierProperty)
);
Proposal
Make identifier resolution accept a resolved resource and read the link's identifier off it, keeping the query shape unchanged. Reading the link's identifier (e.g. a name slug) rather than assuming the Doctrine primary key avoids the identifier-divergence problem.
Both backends funnel through a single method, so this is two small changes rather than three parallel ones:
| Backend | Method | Call sites covered |
|---|---|---|
| Doctrine | getIdentifierValue() in src/Doctrine/Common/State/LinksHandlerTrait.php |
ORM (4), ODM (2), PersistProcessor (4) — all share it |
| Eloquent | buildQuery() in src/Laravel/Eloquent/State/LinksHandler.php |
all 5 entry points funnel through it |
symfony/property-access is already a dependency.
Wrinkle
getIdentifierValue(array &$identifiers, ?string $name = null) only receives the property name when the link has composite identifiers; otherwise it is null and the method does array_shift($identifiers). Reading a property off an object requires knowing which property, and only the caller has it — so $identifierProperty needs to be passed unconditionally at the 6 Doctrine call sites. It is a private method on an @internal trait, so there is no BC surface.
Risk
PersistProcessor shares getIdentifierValue() and uses it to build references on write. It needs verifying that a resolved resource cannot reach it, or an explicit guard.
Suggested sequence
- Pass
$identifierPropertyunconditionally at the Doctrine call sites. - Make
getIdentifierValue()resource aware. - Audit
PersistProcessor. - Gate:
LinkProviderParameterTest::testLinkSecurityWithSluggreen withwrite_uri_variableenabled on a Doctrine-backed link. - Eloquent
buildQuery(). - ODM.
The bulk of the effort is verification across the three backends (the Laravel suite runs under testbench, ODM needs the mongodb environment), not the code itself.
Beyond this
Once identifier resolution is resource aware, flipping the default so ReadLinkParameterProvider always writes the resource becomes a separate, explicit BC decision. It is a real break for consumers independent of Doctrine: plain-ApiResource providers that read uri variables assume scalars — the Issue7939BazResource fixture does (string) ($uriVariables['barId'] ?? '') — so it would need an upgrade note. PreservesUriVariableInterface stays meaningful either way, since consumers still need resources kept out of the uri variables.
- Lingua principale
- PHP
- Stelle
- 2.6k
- Fork
- 982
- Merge medio
- 1g 16h
- PR unite (30g)
- 59
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di api-platform/core
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
api-platform/core#8573 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
api-platform/core#8571 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
api-platform/core#8564 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
api-platform/core#8495 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
api-platform/core#8471 ·
Tutte le issue di api-platform/core
Issue simili
-
Bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
Automattic/safe-publish#594 ·
-
HttpClient
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
symfony/symfony-docs#23092 ·
-
sync-en
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
-
sync-en
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 95/100
-
Перевод устарел
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100