Facades

Introduction

Throughout the Kiaan documentation, you will see examples of code that interacts with Kiaan's features via "facades". Facades provide a "static" interface to classes that are available in the application's service container. Kiaan ships with many facades which provide access to almost all of Kiaan's features.

Kiaan facades serve as "static proxies" to underlying classes in the service container, providing the benefit of a terse, expressive syntax while maintaining more testability and flexibility than traditional static methods. It's perfectly fine if you don't totally understand how facades work under the hood - just go with the flow and continue learning about Kiaan.

Helper Functions

To complement facades, Kiaan offers a variety of global "helper functions" that make it even easier to interact with common Kiaan features. Some of the common helper functions you may interact with are page, config, trans and more.

Each helper function offered by Kiaan is documented with their corresponding feature.

use Kiaan\Config;
 
Route::get('/users', function () {
    return Config::get("app", "name");
});
 
Route::get('/users', function () {
    return config("app", "name")
});

When To Use Facades

Facades have many benefits. They provide a terse, memorable syntax that allows you to use Kiaan's features without remembering long class names that must be injected or configured manually.

Furthermore, because of their unique usage of PHP's dynamic methods, they are easy to test.

How Facades Work

In a Kiaan application, a facade is a class that provides access to an object from the container. The machinery that makes this work is in the Facade class.

Kiaan's facades, and any custom facades you create, will use trait the base Kiaan\Facade.

/*
|---------------------------------------------------
| Uses
|---------------------------------------------------
*/
use Kiaan\Facade;
use Kiaan\Application\App as Base;

/*
|---------------------------------------------------
| App
|---------------------------------------------------
*/
class App {
    
    /*
    * Facade
    *
    */
    use Facade;

    protected function __facade() {
        return Base::class;
    }

}

Last updated