Skip to content

Commit

Permalink
Add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
LordMonoxide committed May 9, 2015
1 parent 4938a0c commit 5c6ba55
Showing 1 changed file with 66 additions and 1 deletion.
67 changes: 66 additions & 1 deletion README.md
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');
```

0 comments on commit 5c6ba55

Please sign in to comment.