I want to under stead something about how Laravel does create the magic functions based on the Facade classes. Now what I want is a central class within the magic functions is created based on class names. For example:
// Example main class
class Facade
{
public function __construct(array $aliases = [])
{
$this->aliases = $aliases;
}
public function load()
{
// Do some magic...
}
}
// Example Facade subclass
class Navigation
{
public function items(string $name)
{
return $name;
}
}
// Array with aliases
$aliases = [
'navigation' => 'App\Facades\Navigation',
];
new Facade($aliases);
// Then I want to call everywhere:
echo navigation()->items('name'); == 'name'
How can I do this, I can't find anything about how Laravel this does.
Define PHP autoloader instead of the Facade class:
And then call your class by (pay attention to the missing brackets):
For more info - PHP autoload doc