From an Utils service class, I need to get an argument I defined in the services.yaml.
And when I want instantiate my service class, I want pass a 'non service' parameter.
Currently, I have :
#from my services.yaml
...
services:
...
App\Utils\myCustomService:
arguments:
$foo: 'some value'
//from my custom service
...
private $faa;
private $foo;
public function __construct(ParameterBagInterface $foo)
{
$this->foo = $foo;
}
public setFaa($value){
$this->faa = $value;
}
//from a custom Controller by example
...
public function new(myCustomService $myCustomService){
$myCustomService->setFaa("blabla");
...
}
But I'm looking for a way to use the "new" method in my Controller like this :
//from a custom Controller v2
...
public function new(){
$myCustomService = new myCustomService("blabla");
// and the parameter "faa" in $myCustomService is automatically set to "blabla"
...
}
With this "new" method, I get an error because the constructor of my custom service Class neen only one parameter of type "ParameterBagInterface".
I think I must change things in my custom Service Class, but I don't find what, someone can help me ?