Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
Open
Description
Description
Hi,
TLDR: General Condition defined in YAML/XML collections overrides specific condition defined in attribute.
I have a trouble with route conditions on a project I'm working on.
Routes are loading via a mix of YAML and Attributes :
api:resource:../../src/Controller/type:annotationcondition:"%general_condition%"
#[Route(path:"my/route", condition:"specific condition")]finalclass MyController { ...}
My trouble is that the specific condition, defined by attribute, is overrided by the general condition, defined via YAML.
Looking into the component, I found out that when the YamlFileLoader sets the condition on the RouteCollection, the RouteCollection overrides any previous condition.
I find it disturbing that a general condition overrides a specific condition.
publicfunctionsetCondition(?string$condition){foreach ($this->routesas$route) {$route->setCondition($condition); }}
Propositions
- Make specific overrides general, but I fear it is a BC since previously enforced general condition would not be any more.
publicfunctionsetCondition(?string$condition){foreach ($this->routesas$route) {if ('' ===$route->getCondition()) {$route->setCondition($condition); } }}
- Combine conditions. I don't think of it as a BC since one cannot expect its attribute condition tonot work.
publicfunctionsetCondition(?string$condition){foreach ($this->routesas$route) {if ('' ===$route->getCondition()) {$route->setCondition($condition); }else {$route->setCondition('(' .$route->getCondition .') and (' .$condition .')'); } }}