Facades are a way to make Phi bindings feel more natural.
Composer is the recommended method of installation for Facade.
$ composer require bapcat/facade
Facade may be downloaded from GitHub.
A common use-case for Phi Facades is logging:
namespace Vendor\Package\Logging;
class Logger {
public function warning($text) {
// ...
}
}
$logger = new Vendor\Package\Logging\Logger;
$phi = BapCat\Phi\Phi::instance();
$phi->bind('core.log', $logger);
use BapCat\Facade\Facade;
class Log extends Facade {
protected static $_binding = 'core.log';
}
Once the facade is set up, the Vendor\Package\Logging
singleton can be accessed like this:
Log::warning('Something bad happened!');
Phi Facades can even be used to create a facade for Phi:
$phi = BapCat\Phi\Phi::instance();
$phi->bind('phi', $phi);
use BapCat\Facade\Facade;
class Phi extends Facade {
protected static $_binding = 'phi';
}
This will allow Phi to be accessed as such:
Phi::bind('Bar', 'Foo');
$foo = Phi::make('Bar');
If you are using Phi 1.2.0 or greater, Phi facades will work seamlessly with custom resolvers.