Facades
Facades provide a "static" interface to classes that are available in the application's service container. They serve as a proxy for accessing the underlying implementation of the application's services.
Facade Class
The abstract Ecommerce\Core\Facade class is the base class for all facades.
Get Accessor
Define the service binding key.
Description:
The get_accessor() method defines which service container binding the facade proxies to. The method should return the string key used to bind the service in the container.
Method Signature:
abstract public static function get_accessor(): string
Examples:
namespace Ecommerce\Supports\Facades;
use Ecommerce\Core\Facade;
use Ecommerce\Core\Container;
class App extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
public static function get_accessor()
{
return Container::class;
}
}
How Facades Work
Understanding the mechanism behind facades.
Static to Instance Proxying
How static calls are forwarded.
Description:
Facades utilize PHP's __callStatic() magic method to defer calls from your facade to the resolved instance from the service container. When you call a static method on a facade, the base Facade class resolves the object from the container and calls the requested method on that object instance.
Method Signature:
public static function __callStatic($method, $arguments): mixed
Examples:
// Calling a static method on the Facade
Command::register('my:command', MyCommand::class);
// Effectively does this behind the scenes:
$instance = $app->make(CommandManager::class);
$instance->register('my:command', MyCommand::class);
Execution Output:
// Resolves 'command' from container (CommandManager instance)
// Calls register() on that instance