agentleFS
gerard-labsgerard-labs/superpowers-api-platform/skills/api-platform-state-processors/SKILL.md

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.

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
  1. Distinctive:

    No business logic in the Processor — orchestrate a service or a CQRS handler.

    line 29
  2. Very specific:

    DELETE returns null (API Platform emits 204).

    line 32
  3. Very specific:

    If you want Doctrine persist + async dispatch, decorate persist_processor.

    line 33

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

API Platform 4.3 — State Processors

Use when

  • A Post / Put / Patch / Delete operation 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

  1. Scaffold with php bin/console make:state-processor.
  2. Inject api_platform.doctrine.orm.state.persist_processor (and remove_processor when relevant) via #[Autowire(service: ...)].
  3. Discriminate Delete with $operation instanceof DeleteOperationInterface if a single Processor covers all writes.
  4. For async-only operations, prefer the native messenger: 'input' mode + status: 202 over a custom Processor.
  5. 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 (wrapInTransaction or doctrine_transaction middleware).
  • 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 use messenger: true, which bypasses Doctrine entirely.

Progressive disclosure

  • SKILL.md covers posture and rules.
  • reference.md carries the full Autowire decoration recipe, the native Messenger modes, the CQRS pattern, the DeleteOperationInterface discriminator, and the 202 / output: false semantics.

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

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.