public function __call($method, $args)
{
// Setup key
$key = static::class . ':' . $method;
// Call callable helper structure (function or class)
if (isset($this->helpers[$key]) && is_callable($this->helpers[$key])) {
return $this->helpers[$key](...$args);
}
// Try to find helper file
foreach ($this->helpersPath as $helperPath) {
$helperPath = realpath($helperPath . '/' . ucfirst($method) . '.php');
if ($helperPath) {
$helperInclude = (include $helperPath);
if (is_callable($helperInclude)) {
$this->helpers[$key] = $helperInclude;
return $this->helpers[$key](...$args);
} else {
throw new CommonException("Helper '{$method}' not found in file '{$helperPath}'");
}
}
}
throw new CommonException("Helper '{$method}' not found for '" . __CLASS__ . "'");
}