I'm trying to get the return result from a method perform by the call option of service. So My service.xml :
<service id="myService" class="serviceClass">
<argument type="service" id="..."/>
<argument type="service" id="..."/>
<call method="myReturnProblem"/>
</service>
My service method :
function serviceMethod(){
...
$foo = "bar"
var_dump($foo);
return true;
}
My Controller :
function sampleAction(){
...
$this->get('my_Service');
return Response...
}
So, i can see with the var_dump that the method is running like i hope but i don't know how can i get the return true(same problem if i try to get $foo or what else) .
Right now if i make :
if($this->('my_Service))
it doesn't work cause it doesn't contains the result. To get it i have to make something like
if($this->('my_Service')->serviceMethod())
but it runs the serviceMethod twice.
I wanted make something like :
if($this->get('my_Service')){}
Any idea ? thanks.
What you did is called Setter Injection, references available here and here
As the name suggests, it is for injecting a service into another service, not for returning value.
To achieve a result purpose, you should create a regular method inside the service to process values and then return the result.
public function myMethod()
{
...
$foo = "bar";
var_dump($foo);
return true;
}