Good morning,
I'm starting to learn symfony. I would like to create a class to manage the settings that are in parameters - Services.yml.
parameters:
config:
global:
db.host: xxx
db.port: ''
db.user: yyy ...
I created a class Config in singleton and would like to call it anywhere in my application.
The problem is that the only way I found is to pass the ContainerBagInterface service in __construct to load a variable with all the information I need.
private function __construct(ContainerBagInterface $params)
{
$this->config = $this->params->get('config');
}
public static function getInstance(ContainerBagInterface $params): Config
{
if (self::$instance === null) {
self::$instance = new self($params);
}
return self::$instance;
}
I always need to pass $params I wish I didn't have to do that.
Can someone help me? Thanks