api-platform-state-processors
Skill2 starsChanged 6 months agoMITView on GitHub
Write or evolve an API Platform 4.3 State Processor — turn a DTO Input into a persistence effect (Doctrine + dispatch). Covers the Autowire-based decoration of `api_platform.doctrine.orm.state.persist_processor` / `remove_processor`, the `DeleteOperationInterface` discriminator, the native Messenger modes (`messenger: 'input'`, `messenger: true`, HTTP 202 / `output: false`), and the CQRS command-bus delegation pattern. Trigger when wiring `Post` / `Put` / `Patch` / `Delete` with custom logic, when bridging API Platform to Messenger, or when persistence must trigger an asynchronous side effect.
In this repository52 other files it gives its agents.
- api-platform-dto-resourcesSkill
- api-platform-errorsSkill
- api-platform-file-uploadSkill
- api-platform-filtersSkill
- api-platform-identifiersSkill
- api-platform-mcpSkill
- api-platform-mutatorsSkill
- api-platform-openapiSkill
- api-platform-paginationSkill
- api-platform-performanceSkill
- api-platform-resilienceSkill
- api-platform-resourcesSkill
- api-platform-securitySkill
- api-platform-serializationSkill
- api-platform-state-providersSkill
- api-platform-testsSkill
- api-platform-upgradeSkill
- api-platform-userSkill
- api-platform-versioningSkill
- bootstrap-checkSkill
- brainstormingSkill
- config-env-parametersSkill
- controller-cleanupSkill
- cqrs-and-handlersSkill
- daily-workflowSkill
- doctrine-batch-processingSkill
- doctrine-fetch-modesSkill
- doctrine-fixtures-foundrySkill
- doctrine-migrationsSkill
- doctrine-relationsSkill
- doctrine-transactionsSkill
- effective-contextSkill
- executing-plansSkill
- functional-testsSkill
- interfaces-and-autowiringSkill
- makefile-disciplineSkill
- messenger-retry-failuresSkill
- ports-and-adaptersSkill
- quality-checksSkill
- rate-limitingSkill
- runner-selectionSkill
- strategy-patternSkill
- symfony-cacheSkill
- symfony-messengerSkill
- symfony-schedulerSkill
- symfony-votersSkill
- tdd-with-pestSkill
- tdd-with-phpunitSkill
- test-doubles-mockingSkill
- using-symfony-superpowersSkill
- value-objects-and-dtosSkill
- writing-plansSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 29
No business logic in the Processor — orchestrate a service or a CQRS handler.
- Very specific: line 32
DELETE returns null (API Platform emits 204).
- Very specific: line 33
If you want Doctrine persist + async dispatch, decorate persist_processor.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
API Platform 4.3 — State Processors
Use when
- A
Post/Put/Patch/Deleteoperation needs custom write logic (transformation, dispatching, side effect). - You want to decorate the Doctrine persist / remove processor while keeping the default behavior.
- The write must be asynchronous (long ERP call, PDF generation) — use the native Messenger mode.
- You apply CQRS and want to dispatch a Command to a bus instead of persisting directly.
Default workflow
- Scaffold with
php bin/console make:state-processor. - Inject
api_platform.doctrine.orm.state.persist_processor(andremove_processorwhen relevant) via#[Autowire(service: ...)]. - Discriminate
Deletewith$operation instanceof DeleteOperationInterfaceif a single Processor covers all writes. - For async-only operations, prefer the native
messenger: 'input'mode +status: 202over a custom Processor. - Wire on the operation:
new Post(processor: MyProcessor::class).
Guardrails
- No business logic in the Processor — orchestrate a service or a CQRS handler.
- Wrap multi-entity writes in a transaction (
wrapInTransactionordoctrine_transactionmiddleware). - POST returns the persisted entity / DTO (API Platform emits 201 + Location).
- DELETE returns
null(API Platform emits 204). - If you want Doctrine persist + async dispatch, decorate
persist_processor. Do not usemessenger: true, which bypasses Doctrine entirely.
Progressive disclosure
SKILL.mdcovers posture and rules.reference.mdcarries the full Autowire decoration recipe, the native Messenger modes, the CQRS pattern, theDeleteOperationInterfacediscriminator, and the 202 /output: falsesemantics.
Output contract
- A new Processor class in
src/State/wired on the operation. - Transactional integrity guaranteed for multi-entity writes.
- Functional tests for the happy path + 422 + 403 + idempotency / retry where async is involved.
References
reference.md
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

