I have a interesting situation I have not yet encountered with Symfony...
I have a bundle, which provides dynamic configuration to the entire application. I've registered the service of the bundle and it all works.
MyNamespace\MyBundle\Site\Vars:
arguments:
$path: '%env(APP_PARAM)%'
However, there are templates which rely on the vars, which the service registers with Twig globals. I am getting an "Variable "XTZ" does not exist."
unless I explicitly request the service "Vars" as per each controller::action:
public function someAction(): Response -> FAILS
public function someAction(Vars $vars): Response -> WORKS!?!
I don't want to have every controller::action, commands, etc requires this explicit-ness.
I thought maybe, Symfony supports like an eager-loaded service option or something.
Any thoughts?
EDIT | Method in the class / services Vars
:
public function loadIntoTwigGlobals(): void
{
$items = Yaml::parseFile($this->path);
$this->setArray($items);
$this->twig->addGlobal('site', $items['site']);
}
The Twig\Environment is injected at construction.