I am using Symfony 2.8 and I didn't find anything to solve my problem.
To make it simple, I have a Payment entity and I need to have a global variable for the VAT.
My question is: is there any way to have a common variable to all my Payment entities knowing it could be modified later within the web application by the administrator? I don't think the Service parameters (which I am using) will make it. At least, I didn't find anything on how to modify it dynamically.
Here's some part of my service.yml:
Use real global variable (
global $parameter) in Symfony - the vary bad idea, because all systems works in scope (request, console, etc...), and each scope have custom services for this scope (
@request as example).
But, if you want use config parameter in you application, then you can use:
Solution #1 (Use
This solutions vary good, if parameter is not dynamically, and changed rarely.
Solution #2 (Use a factory service for custom parameters)
In my application, I use custom layer for configurations with common service, because many parameters is dynamically, and can changed for each request or user or another condition.
getVatto this service.
Solution #3 (Use a Doctrine events)
So, this a not good idea, but can work in any systems.
If you want calculate prices, or another operation with entity, you can inject custom parameter after complete load entity.
Attention: This method work only after load entity via doctrine!
I would use Solution #2, because this is a vary good variant, and we can store this parameter anywhere (database, redis, parameters.yml, etc..), and we can change this parameter for each condition (request, user, country, timezone, etc...)