I have a class that has 20+ different API function call. Each one is basically similar but there is one funciton I'd like shared between all of the.
For example:
public function first_api_call () {
$response = $client->get($uri, [
'on_stats' => function (TransferStats $stats) use ($logger) {
// do something inside the callable.
$logger->debug('Request' . $stats->getRequest() .
'Response' . $stat->getResponse() .
'Tx Time' . $stat->getTransferTime()
);
},
]);
}
Now, I'd like for this tehnically to be on_stats => run_my_stats_function and have the code in that one place so it will take affect whereever it is called.
How do I go about doing this in a class?
on_statsshould be callable it can be something likearray(__CLASS__, 'method')?