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

api-platform-state-providers

Skill2 starsChanged 6 months agoMITView on GitHub

Write or evolve an API Platform 4.3 State Provider — transform a data source (Doctrine, external API, cache) into the API representation. Covers the modern Autowire-based decoration of `api_platform.doctrine.orm.state.item_provider` / `collection_provider`, the `CollectionOperationInterface` discriminator, header-versioned providers, and the deprecated interfaces to remove (`SerializerAwareProviderInterface`, `SerializableProvider`). Trigger when adding a Provider to `Get` / `GetCollection`, decorating the Doctrine read pipeline, or shaping an Output DTO at read time.

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 2 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    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. Very specific:

    Do not code role checks inside the Provider — use security: on the operation or a voter.

    line 30
  2. Distinctive:

    Do not persist from a Provider.

    line 31
  3. Very specific:

    Remove any SerializerAwareProviderInterface / SerializableProvider implementation — those interfaces are deprecated since 4.2 and gone in …

    line 32
  4. Distinctive:

    No legacy interfaces remaining.

    line 41

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

Use when

  • A Get / GetCollection operation needs a transformation between the data source and the API representation.
  • You want to decorate the Doctrine read pipeline (e.g. to add audit logging or shape an Output DTO).
  • A response payload depends on a request header (versioning, locale).
  • A Resource is backed by a non-Doctrine source (external API, in-memory store, search engine).

Default workflow

  1. Scaffold with php bin/console make:state-provider.
  2. Inject the Doctrine item / collection providers via #[Autowire(service: '…')] (modern decoration pattern).
  3. Discriminate collection vs item with $operation instanceof CollectionOperationInterface.
  4. Return null for missing items (API Platform emits a 404 automatically).
  5. Wire on the operation: new Get(provider: MyProvider::class).

Guardrails

  • Inject a repository or a service, never EntityManagerInterface directly inside a Provider.
  • Do not code role checks inside the Provider — use security: on the operation or a voter.
  • Do not persist from a Provider; that is the Processor's job.
  • Remove any SerializerAwareProviderInterface / SerializableProvider implementation — those interfaces are deprecated since 4.2 and gone in 5.0.

Progressive disclosure

  • SKILL.md covers the basic pattern and rules.
  • reference.md carries the full decoration recipe, the collection-vs-item discriminator, a header-versioned example, and an N+1-avoidance reminder.

Output contract

  • A new Provider class in src/State/ wired on the operation.
  • Functional tests covering the happy path and the null/404 case.
  • No legacy interfaces remaining; no hardcoded security inside the Provider.

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.