I don't have high hopes for this one:
Given a service that has an action like the foo
in $service->foo->bar( $a, $b )
and a container class that has $service
as a protected property, is there a way to use __get()
on the container to access the service and pass along the ->bar( $a, $b )
?
class Container {
protected $service;
protected $responses = [];
public function __get ($name) {
$this->responses[] = $service->$name-> _???_
return $resp;
}
}
that could be intercepted so that the Container could catch the operation, call $service
with it, save the response, then return the response
Either some way to grab whatever else is being chained on the $name
or if $name
just included all of that. I know this is a little convoluted, but it would help me clean some code up substantially, plus I'm just generally curious now.
This app is running PHP7 if that matters.
And alternately, if there is a way to do this but it isn't __get()
, insight would be appreciated