Skip to content
そら edited this page Nov 29, 2017 · 3 revisions

Facade

What is a facade?

Facades provide a "static" interface to classes that are available in the application's service container.

How to use

All of Kotori's facades are defined in the Kotori\Facade namespace. So, we can easily access a facade like so:

use Kotori\Facade\Cache;
use Kotori\Facade\Request;
use Kotori\Facade\Response;

if (Request::get('hello') == 'world') {
    Cache::set('name', 'niconiconi');
} else {
    Response::setStatus(400);
}

Facade class reference

Below you will find every facade and its underlying class. The service container binding key is also included where applicable.

Facade Class Service Container Binding
Cache Kotori\Core\Cache cache
Config Kotori\Core\Config config
Request Kotori\Http\Request request
Response Kotori\Http\Response response
Route Kotori\Http\Route route

Dependency Injection

You can use DI in controllers.

namespace app\controllers;

use Kotori\Core\Controller;
use Kotori\Http\Request;

class Blog extends Controller {

    public function index(Request $request)
    {
        echo $request->get('var');
    }
}
Clone this wiki locally