-
-
Notifications
You must be signed in to change notification settings - Fork 4
Attribute support #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
very good! 👏 I'm not very experienced with attributes, wouldn't it make sense to use a separate class for attributes? |
Both would work I guess. There was also a similar discussion in symfony/symfony#37474 for the I like that you can easily refactor your code (not even a new import needed) and the behavior stays identical. On the downside there is less type safety in the constructor. But IMHO this could/should be tweaked in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Only a minor nitpick about file naming :)
Did you consider using named arguments instead of the array? #[ServiceTag('target_service', priority: 123, bar: 'baz')] Should work fine using the constructor signature: __construct($name, ...$data) |
Switched to named arguments in 19c6bf0. I also renamed the first argument to |
Very nice! I also didn't know about that 🙃
I would actually go with |
IMHO the downside to But I'm fine with both. |
That's true. But |
@Toflar just pointed me to https://symfony.com/blog/new-in-symfony-5-3-service-autoconfiguration-and-attributes |
Not sure about this. If I get this correctly, you could get rid of the $container->registerAttributeForAutoconfiguration(
ServiceTag::class,
static function (ChildDefinition $definition, ServiceTag $attribute): void {
$definition->addTag($attribute->getName(), $attribute->getAttributes());
}
); I guess Contao (or any consumer) could implement their special attributes without this bundle but would then on the other hand need to require the Sf DI component in >= 5.3. Hmm. (Speaking of Contao: We should consider following the |
yes that's what I mean. Instead of adding attributes trough this bundle, we could add support for attributes when Contao requires Symfony 5.3 (like in 4.12 or 4.13). If we agree we MUST have attribute support e.g. in 4.9, then we need to implement it in this bundle. |
Description ----------- Replaces terminal42/service-annotation-bundle#6 The new naming follows the [Symfony convention](https://symfony.com/blog/new-in-symfony-5-3-service-autoconfiguration-and-attributes#autoconfigurable-attributes) > These attribute names follow the pattern #[As...]. Symfony 5.3 provides #[AsCommand] to define a PHP class as a Symfony console command, #[AsEventListener] to define a PHP class as a Symfony event listener, etc. Commits ------- a5ea9c1 Added PHP8 attributes for our existing service annotations 44c5d82 Added missing page attribute 6bb9d1a Merge branch '4.x' into feature/php8-attributes b9201cd Run the CS fixer afd1d20 Update AsPage attribute to match Route attribute 2da4277 Fix the CS check 5e3e22a Fix the CS check
Description ----------- Replaces terminal42/service-annotation-bundle#6 The new naming follows the [Symfony convention](https://symfony.com/blog/new-in-symfony-5-3-service-autoconfiguration-and-attributes#autoconfigurable-attributes) > These attribute names follow the pattern #[As...]. Symfony 5.3 provides #[AsCommand] to define a PHP class as a Symfony console command, #[AsEventListener] to define a PHP class as a Symfony event listener, etc. Commits ------- a5ea9c15 Added PHP8 attributes for our existing service annotations 44c5d82c Added missing page attribute 6bb9d1ac Merge branch '4.x' into feature/php8-attributes b9201cd2 Run the CS fixer afd1d206 Update AsPage attribute to match Route attribute 2da42777 Fix the CS check 5e3e22a3 Fix the CS check
Attributes are supported natively by Symfony and Contao, therefore I'm closing this PR. |
This PR adds attribute support which basically allows doing this on PHP>=8:
(This also adds phpunit for testing - not sure about your preferences herewith for this bundle. 🙂 )