Repository navigation
TransformerRegistry: require the code tag attribute and remove eager transformer registration (v6 step of #276) #280
Description
Description
v6 step of #276. In v5, #276 loads transformers lazily through a service locator indexed by the code attribute of the cleverage.transformer tag (or #[AsTransformer(code: '...')]). Transformers tagged without code keep being instantiated eagerly through TransformerRegistry::addTransformer(), with a deprecation.
Proposed fix
-
The
codeattribute becomes required on thecleverage.transformertag: a tagged service withoutcodefails the container compilation with an explicit message (add the attribute or use#[AsTransformer]). -
Remove the eager path:
TransformerRegistry::addTransformer()and the method calls added by the compiler pass. -
Remove
RegistryCompilerPassif it was deprecated by TransformerRegistry: lazy-load transformers through a service locator indexed by code #276 and is not used elsewhere. -
TransformerRegistryonly wraps the locator (getTransformer(),hasTransformer()). Decide whethergetTransformers()is kept (it instantiates every transformer and is not used by the bundles) or replaced by a method returning the codes. -
Remove
TransformerInterface::getCode()(decided): since TransformerRegistry: lazy-load transformers through a service locator indexed by code #276 (PR #276 - TransformerRegistry: lazy-load transformers through a service locator indexed by code #293) the code of a transformer is given by the tagcodeattribute /#[AsTransformer],getCode()only duplicates it. Its remaining uses, all removed or replaceable:TransformerRegistry::addTransformer()(eager path, removed above);- the check "code of the locator ===
getCode()" inTransformerRegistry::getTransformer()(removed with the method: there is a single declaration of the code); UnavailableServicesCompilerPass(CheckSerializerCompilerPass: do not fail the container compilation when the serializer is disabled #278) reads it by reflection to keep the code of the replaced transformer: read thecodeof the tag instead (can be done in v5 already).
GenericTransformer/UnavailableTransformer(which store their code) can keep agetCode()of their own if useful, outside of the interface.BC: harmless for the classes implementing the interface (an extra method), breaking for code calling
getCode()on a transformer.Deprecate it first, in v5 (5.4, with TransformerRegistry: lazy-load transformers through a service locator indexed by code #276):
@deprecatedPHPDoc onTransformerInterface::getCode()("since 5.4, the code is given by thecodeattribute of thecleverage.transformertag or by#[AsTransformer], it will be removed from the interface in v6.0"), mention in the CHANGELOG / UPGRADE notes, and stop calling it in the bundle where it is not needed (UnavailableServicesCompilerPass). Note: neithertrigger_deprecation()(interface method) nor Symfony'sDebugClassLoader(it does not report the methods of an interface marked@deprecated) can give a runtime notice; the deprecation is visible to static analysis (PHPStanphpstan-deprecation-rules) and IDEs only. -
Update the bridge bundles if some transformers still lack the attribute.
Requirements
- Documentation updates
- Reference
- Cookbooks
- Changelog
- Unit tests
Breaking changes
- Major: transformers tagged
cleverage.transformerwithout acodeattribute (deprecated since TransformerRegistry: lazy-load transformers through a service locator indexed by code #276) no longer work. - Major:
TransformerRegistry::addTransformer()is removed (andgetTransformers()/RegistryCompilerPassdepending on the decisions above).
Activity
#276 - Deprecate TransformerInterface::getCode()