symfony icon indicating copy to clipboard operation
symfony copied to clipboard

Extend `#[When]`/Create a new attributes, in order to tell under which environment others attributes need to be applied.

Open VincentLanglet opened this issue 2 years ago • 7 comments

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 avatar Mar 12 '24 15:03 VincentLanglet

@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

faizanakram99 avatar Mar 12 '24 16:03 faizanakram99

@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.

VincentLanglet avatar Mar 12 '24 16:03 VincentLanglet

ah ok, that makes sense

faizanakram99 avatar Mar 12 '24 16:03 faizanakram99

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.

carsonbot avatar Sep 13 '24 13:09 carsonbot

Yes, still wanted.

VincentLanglet avatar Sep 13 '24 13:09 VincentLanglet

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.

carsonbot avatar Mar 14 '25 13:03 carsonbot

Just a quick reminder to make a comment on this. If I don't hear anything I'll close this.

carsonbot avatar Mar 28 '25 13:03 carsonbot

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!

carsonbot avatar Apr 11 '25 13:04 carsonbot