I have a class that looks a bit like this:
<?php
namespace App\Http\Controllers;
use Exception;
use Illuminate\Http\Request;
class FormatAddressController extends Controller
{
public function __construct()
{
$this->middleware(['api-auth']);
$this->middleware(['api-after']);
}
public function format(Request $request) {
// TODO first, get customer settings to see what functions to run, and how to run them
// but, assume that the settings come as an array where the key is the function name
// and the value is one of NULL, false, or settings to pass through to the function
$settings = ['isoAndCountry' => true, 'testFunc' => ['testSetting' => 'test setting value']];
$address = $request->input('address');
$errors = [];
foreach ($settings as $funcName => $funcSettings) {
try {
$address = $this->$funcName($funcSettings, $address); // every function has to return the modified address
} catch(Exception $e) {
$errors[$funcName] = $e;
}
}
return response()->json([
'address' => $address,
'errors' => $errors
]);
}
public function isoAndCountry($settings, $address) {
// TODO
return $address;
}
}
Now, when I call this function, isoAndCountry, through that settings loop I defined above, it works! It works just fine.
However I tried following this thread and checking is_callable
and... it errors:
if (is_callable($this->$funcName)) {
try {
$address = $this->$funcName($funcSettings, $address); // every function has to return the modified address
} catch(Exception $e) {
$errors[$funcName] = $e;
}
}
How can I check if it's callable? Why doesn't this work?