-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4938a0c
commit 5c6ba55
Showing
1 changed file
with
66 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,66 @@ | ||
# facade | ||
[![Build Status](https://travis-ci.org/LordMonoxide/facade.svg?branch=master)](https://travis-ci.org/LordMonoxide/facade) | ||
[![Coverage Status](https://coveralls.io/repos/LordMonoxide/facade/badge.svg?branch=master)](https://coveralls.io/r/LordMonoxide/facade?branch=master) | ||
[![License](https://img.shields.io/packagist/l/LordMonoxide/facade.svg)](https://img.shields.io/packagist/l/LordMonoxide/facade.svg) | ||
|
||
# Phi Facades | ||
|
||
Facades are a way to make Phi bindings feel more natural. | ||
|
||
## Features | ||
|
||
### Pseudo-Static Access To Phi Singletons | ||
|
||
A common use-case for Phi Facades is logging: | ||
|
||
```php | ||
namespace Vendor\Package\Logging; | ||
|
||
class Logger { | ||
public function warning($text) { | ||
// ... | ||
} | ||
} | ||
``` | ||
|
||
```php | ||
$logger = new Vendor\Package\Logging\Logger; | ||
|
||
$phi = LordMonoxide\Phi\Phi::instance(); | ||
$phi->bind('core.log', $logger); | ||
``` | ||
|
||
```php | ||
use LordMonoxide\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: | ||
|
||
```php | ||
Log::warning('Something bad happened!'); | ||
``` | ||
|
||
Phi Facades can even be used to create a facade for Phi: | ||
|
||
```php | ||
$phi = LordMonoxide\Phi\Phi::instance(); | ||
$phi->bind('phi', $phi); | ||
``` | ||
|
||
```php | ||
use LordMonoxide\Facade\Facade; | ||
|
||
class Phi extends Facade { | ||
protected static $_binding = 'phi'; | ||
} | ||
``` | ||
|
||
This will allow Phi to be accessed as such: | ||
|
||
```php | ||
Phi::bind('Bar', 'Foo'); | ||
$foo = Phi::make('Bar'); | ||
``` |