Closed tandev closed 3 months ago
Hey @tandev,
This bug comes from how attribute is defined:
Where in your usage, you're using promoted properties, therefore to allow for such usage, it should be done like this to be correct:
Ecotone does do nothing magically here, it just initializes this Attribute, where it's not possible due to incorrect definition.
I am not sure, how does it work on the Symfony side thought. Maybe they do not initialize it at all?
@dgafka , it is because of a promoted property (a parameter that is also a property). I am working on a fix as I think this is valid.
I remember I had this error int he past, and fixed it with a try catch around attribute instanciation in ecotone, but I can't find it anymore. I will see if there is a more elegant way of doing that.
@jlabedo ah I see.
Maybe we intitialize it in context of property (ClassDefinition)? If so, we could check if this Attribute has TARGET_PROPERTY
option, and only then add initialize and add it?
I tried if ($attribute->getTarget() & \Attribute::TARGET_PROPERTY)
but the target is always property (even if not an allowed target)
Maybe we could use reflection on the attribute itself to get its class "\Attribute" attribute... and then get its targets. But seems a bit complicated in comparison with a documented try catch...
Hmm, as long as we can catch this specific error, that should also do a trick, and will be less time consuming process than check of each attribute
Ecotone version(s) affected: 1.224.0
Description
The following issue occurs on warmup, when using an Attribute which should be allowed in this place in CPP
Uncaught Error: Attribute "Symfony\Component\DependencyInjection\Attribute\AutowireLocator" cannot target property (allowed targets: parameter)
This attribute(Symfony\Component\DependencyInjection\Attribute\AutowireLocator) for example is allowed by symfony to be used for properties in a CPP definition
So i think this should be allowed by ecotone too
How to reproduce
I set an example symfony application with ecotone integration where this can reproduced at cache warmup https://github.com/tandev/ecotone-attribute-resolving/tree/main