Skip to content

doc: describe the types listed by Symfony's debug:autowiring command - #8633

Merged
soyuka merged 1 commit into
api-platform:5.0from
nicolas-grekas:debug-autowiring-hints
Oct 5, 2026
Merged

soyuka merged 1 commit into
api-platform:5.0from
nicolas-grekas:debug-autowiring-hints

Conversation

@nicolas-grekas

Copy link
Copy Markdown
Contributor

Symfony's debug:autowiring command displays the first line of the docblock of each autowirable type, as a hint about what the service is for. This PR adds or improves that line for the types this package registers for autowiring.

Same as symfony/symfony#66566, which does it for Symfony's own types.

@nicolas-grekas
nicolas-grekas force-pushed the debug-autowiring-hints branch from 861829a to 3b77002 Compare October 3, 2026 07:35
@nicolas-grekas nicolas-grekas changed the title docs: describe the types listed by Symfony's debug:autowiring command doc: describe the types listed by Symfony's debug:autowiring command Oct 3, 2026
@nicolas-grekas

nicolas-grekas commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor Author

I dropped the hints I had added on PersistProcessor, RemoveProcessor and the UUID/ULID filters: these final classes are aliased by their FQCN, so debug:autowiring lists them as types to autowire. Type-hinting one breaks as soon as the service is decorated (TypeError, only lint:container catches it).

WDYT of deprecating the FQCN aliases of final classes that implement an interface, in favor of named aliases on the interface? Eg $container->registerAliasForArgument('api_platform.doctrine.orm.state.persist_processor', ProcessorInterface::class, 'persist') in the extension would let apps write:

public function __construct(
    #[Target('persist')] private ProcessorInterface $processor,
) {
}

debug:autowiring would then list the processors as variants of ProcessorInterface. That's what symfony/symfony#66568 does for Symfony's webhook parsers. The filter aliases point to abstract definitions and can't be autowired at all; symfony/symfony#66569 hides them from the listing.

@soyuka
soyuka merged commit 5cd0a87 into api-platform:5.0 Oct 5, 2026
117 checks passed
@soyuka

soyuka commented Oct 5, 2026

Copy link
Copy Markdown
Member

Indeed, let's do this! One catch though: ApiPlatform\Doctrine\Common\State\PersistProcessor (and RemoveProcessor) is the same class for ORM and ODM, both configs alias the FQCN so with both enabled it points to whichever is loaded last. A plain persist name has the same issue, and so does #[Target(PersistProcessor::class)] (it works, but it can't tell ORM from ODM).

I see two options:

  1. short names per backend:
#[Target('ormPersist')] private ProcessorInterface $processor,
#[Target('odmItem')] private ProviderInterface $provider,
  1. the service id as target name, via registerAliasForArgument($id, ProcessorInterface::class):
#[Target('api_platform.doctrine.orm.state.persist_processor')] private ProcessorInterface $processor,

I prefer 1, 2 is basically #[Autowire(service: ...)] spelled differently. In both cases we'd deprecate the FQCN aliases of the Doctrine processors and of the Doctrine/Elasticsearch item/collection providers, processor: PersistProcessor::class on operations keeps working through the locator key. WDYT?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants