Extend `#[When]`/Create a new attributes, in order to tell under which environment others attributes need to be applied.
Description
From https://github.com/symfony/symfony/discussions/54231#discussion-6356612, it seems like it's not possible to use attribute like #[AsCronTask('*')] only for specific environment. I would have expect something like
#[AsCronTask('*', env: 'prod')]
but after more thought I think it would be better to have this with another attribute, similar to #[When], like
#[When('prod', new AsCronTask('*'))]
I'm not fully familiar with attributes Would it be doable to provide an attribute to make conditional others attributes based on the environment ?
Example
#[When('prod', new AsCronTask('*'))
@VincentLanglet
i think putting both annotations on top of a class works, e.g.
#[When(env: 'prod')]
#[AsCronTask(...)]
class Foo
or
#[When(env: 'prod'), AsCronTask(...)]
class Foo
@VincentLanglet
i think putting both annotations on top of a class works, e.g.
#[When(env: 'prod')] #[AsCronTask(...)] class Foo
This example "works" if you want the task to run as cron in production but not somewhere else with different config.
#[When(env: 'prod')]
#[AsCronTask('foo')]
#[When(env: 'staging')]
#[AsCronTask('bar')]
class Foo
won't configure a task on prod every "foo", and the same task in staging every "bar".
Same for
#[When(env: 'prod'), AsCronTask(...)]
#[When(env: 'staging'), AsCronTask(...)]
class Foo
When currently works for the service registration, so it's a "All or nothing" attribute.
I'd like
- Either to add option to When in order to make others attributes conditional (and not just the service registration)
- Either introduce another attribute for this.
ah ok, that makes sense
Thank you for this suggestion. There has not been a lot of activity here for a while. Would you still like to see this feature? Every feature is developed by the community. Perhaps someone would like to try? You can read how to contribute to get started.
Yes, still wanted.
Thank you for this suggestion. There has not been a lot of activity here for a while. Would you still like to see this feature? Every feature is developed by the community. Perhaps someone would like to try? You can read how to contribute to get started.
Just a quick reminder to make a comment on this. If I don't hear anything I'll close this.
Hey,
I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen!