Skip to content

#278 - Do not fail the container compilation when the serializer or the validator is disabled - #289

Merged
njoubert-cleverage merged 1 commit into
mainfrom
278
Oct 14, 2026
Merged

njoubert-cleverage merged 1 commit into
mainfrom
278

Conversation

@njoubert-cleverage

Copy link
Copy Markdown
Member

Description

Fixes #278: an application that does not enable the Symfony serializer (or validator) can use the bundle; only the tasks / transformers that need it fail, when they are used, with an explicit message.

Before

Checked with a minimal kernel (FrameworkBundle + MonologBundle + this bundle):

  • framework.serializer.enabled: false: the container does not compile (CheckSerializerCompilerPass, Display a more explicit error message when symfony serializer is not enabled #74): The Symfony serializer component do not seem enabled, consider toggling framework.serializer.enable (…);
  • framework.validation.enabled: false (and serializer disabled, see note): Cannot autowire service "CleverAge\ProcessBundle\Task\Validation\ValidatorTask": argument "$validator" of method "__construct()" references interface "Symfony\Component\Validator\Validator\ValidatorInterface" but no such service exists.

Changes

  • New internal UnavailableServicesCompilerPass (registered by the bundle instead of CheckSerializerCompilerPass, runs before autowiring):

    • without serializer (nor DenormalizerInterface alias): NormalizerTask, DenormalizerTask, SerializerTask, DeserializerTask → UnavailableTask; NormalizeTransformer, DenormalizeTransformer → UnavailableTransformer;
    • without validator (nor ValidatorInterface alias): ValidatorTask → UnavailableTask.

    Same service ids, same public / tags (tasks stay non-shared); the transformers keep their code (normalize, denormalize), so that TransformerRegistry still knows them and using them gives the explicit message instead of "transformer not found".

  • UnavailableTask / UnavailableTransformer (final readonly, @internal): throw a LogicException with The "<service>" service requires the Symfony serializer, which does not seem enabled: consider enabling framework.serializer (see …). (or the validator equivalent, framework.validation) when executed / used. A process using them fails as for any task error (ProcessFailedException whose previous exception is this LogicException, with the default stop strategy). Excluded from the Task\ / Transformer\ resources.

  • CheckSerializerCompilerPass: no longer registered, @deprecated (PHPDoc only, removal in v6.0). No runtime deprecation: it would need the version of the next release, not decided yet; to add if you prefer.

  • Docs: quick start (the serializer / validator are only needed by these tasks and transformers).

  • CHANGELOG (Latest).

Checks

  • Minimal kernel, after the change:
serializer / validation Boot ConstantOutputTask process NormalizerTask process normalize transformer ValidatorTask process
on / on OK OK real task real transformer real task
off / on OK OK explicit serializer message explicit serializer message real task
off / off OK OK explicit serializer message explicit serializer message explicit validator message
  • Demo project (serializer enabled, change applied in vendor/ then reverted): lint:container OK, NormalizerTask keeps its class, demo.transformer executed.
  • Tests: UnavailableServicesCompilerPassTest (services kept when available, replaced without serializer / validator, arguments, public / shared / tags, transformer codes), UnavailableTaskTest, UnavailableTransformerTest. After composer update: 914 tests OK, PHPStan, PHP-CS-Fixer, Rector OK.

Note: serializer enabled with validation disabled does not boot either, because of FrameworkBundle itself (argument_resolver.request_payload requires the validator.translation_domain parameter, only defined when the validation is enabled or symfony/validator is not installed), not because of this bundle.

Requirements

  • Documentation updates
    • Reference
    • Cookbooks
    • Changelog
  • Unit tests

Breaking changes

None: the container compiles in more cases; with the serializer / validator enabled nothing changes. CheckSerializerCompilerPass is kept (deprecated), only no longer registered by the bundle. Minor.

🤖 Generated with Claude Code

…he validator is disabled

- New internal UnavailableServicesCompilerPass: without serializer, the
  NormalizerTask, DenormalizerTask, SerializerTask, DeserializerTask services
  and the normalize / denormalize transformers are replaced by UnavailableTask /
  UnavailableTransformer (same id, public / shared / tags, transformer code
  kept), which throw an explicit LogicException when used; same for
  ValidatorTask without validator (its autowiring failed the compilation).
- CheckSerializerCompilerPass is no longer registered, and deprecated.
- Documentation (quick start) and tests.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@njoubert-cleverage
njoubert-cleverage merged commit 47b2990 into main Oct 14, 2026
18 checks passed
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.

CheckSerializerCompilerPass: do not fail the container compilation when the serializer is disabled

1 participant