[9.x] Helper - Set tag on object based on instanceof #45910
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose
Allow tagging an object based on its parent(s), interface(s) or its own FQCN.
This enables a developer to tag multiple objects dynamically at once without having to manually add new objects when they are added and extend a certain interface or parent.
Dynamically tagging can be an useful addition when you use a strategy pattern in your code and want, for example, register a new handler.
How is it used
Its usage would result in line with the following sample code.
Configuration options
The developer can influence certain parts by configuration:
app.instance_of.cache (bool)
- Wether or not to cache the result of the tagging. This can be used in non-development environments to speed-up the proces.app.instance_of.namespaces.include (string[])
- The class namespaces that should be considered to be tagged. By default this is only done forApp\
.app.instance_of.namespaces.exclude (string[])
- The class namespaces that should be ignored to be tagged. By default this one is empty.app.instance_of.classmap (array<string, string[]>
- A custom created classmap. By default a classmap and the classes and interfaces it implements/extends are created based on the Composer classmap.Based on
This MR is a rework of #44164. In this MR the functionality has been moved to a user land function and the codebase has been updated to boost its performance (the result of running it in production environments).
This update has been inspired by the Symfony methology to tag services through an instanceof provided value. @see https://symfony.com/doc/current/service_container/tags.html#autoconfiguring-tags
Resolves #42499