Skip to content

#58 - Load the REST clients lazily from a service locator indexed by code - #59

Merged
njoubert-cleverage merged 1 commit into
mainfrom
58
Oct 15, 2026
Merged

njoubert-cleverage merged 1 commit into
mainfrom
58

Conversation

@njoubert-cleverage

Copy link
Copy Markdown
Member

Description

Fixes #58. Same model as process-bundle#276 (TransformerLocatorCompilerPass / TransformerRegistry).

  • RegisterClientsPass: the services tagged cleverage.rest.client with a code attribute (- { name: cleverage.rest.client, code: my_api }) are registered in a service locator, passed to ClientRegistry (new optional constructor argument): a client is only instantiated when a task uses it. Duplicate or empty codes fail the container compilation, with the service ids.
  • A service tagged without code is still registered with ClientRegistry::addClient() (eager), now deprecated since 3.3: the code will be required in 4.0.
  • ClientRegistry::getClient() checks that the service implements ClientInterface and that its getCode() returns the code of the tag; getClients() instantiates every client; FQCN alias CleverAge\RestProcessBundle\Registry\ClientRegistry (autowiring in custom tasks).
  • New #[AsRestClient(code: '...')] attribute (registerAttributeForAutoconfiguration()), adding the tag with its code. ClientInterface itself is not autoconfigured (BC break for applications loading their classes with a resource and declaring the clients in other services, see the issue).
  • Require symfony/service-contracts (ServiceProviderInterface, already installed through process-bundle).
  • Docs: code attribute in every example, registration section rewritten.

Checked in process-bundle-demo (patch applied to the vendor):

  • current declarations (no code): demo.wiremock.get_json and demo.wiremock.post_json pass, one deprecation per client;
  • with the code attribute on the 4 REST clients: same demos pass, no deprecation, lint:container OK.

The demo declarations will be updated in a demo PR (the code attribute is ignored by the previous versions).

Requirements

  • Documentation updates
    • Reference
    • Changelog
  • Unit tests

Breaking changes

None: the clients tagged without code keep working, with a deprecation (3.3, removal in 4.0). Behaviour change: the clients with a code are no longer instantiated with the registry.

🤖 Generated with Claude Code

…code

- RegisterClientsPass: the services tagged cleverage.rest.client with a
  code attribute are registered in a service locator passed to the
  ClientRegistry (new optional constructor argument): a client is only
  instantiated when a task uses it. Duplicate or empty codes fail the
  container compilation. Without code, the client is still registered with
  addClient(), now deprecated (the code will be required in 4.0).
- ClientRegistry: getClient() checks that the service implements
  ClientInterface and that its getCode() is the code of the tag;
  getClients() instantiates every client; FQCN alias to autowire it.
- New #[AsRestClient(code: '...')] attribute (autoconfiguration), adding
  the tag with its code.
- Require symfony/service-contracts (ServiceProviderInterface).
- Docs: code attribute in every example, registration section.

Same model as process-bundle#276 (TransformerRegistry).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
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.

Load the REST clients lazily from a service locator indexed by code

1 participant