Facades

Lumberjack uses the Blast Facades library.

Creating a Facade

Facades provide a simple static API to an object that has been registered into the container. For example to setup a facade you would first use a Service Provider to register an instance of your class into the container:

namespace Rareloop\Lumberjack\Providers;

use Monolog\Logger;
use Rareloop\Lumberjack\Application;

class LogServiceProvider extends ServiceProvider
{
    public function register()
    {
        // Create object instance and bind into container
        $this->app->bind('logger', new Logger('app'));
    }
}

Then create a Facade subclass and tell it which key to use to retrieve your class instance:

namespace Rareloop\Lumberjack\Facades;

use Blast\Facades\AbstractFacade;

class Log extends AbstractFacade
{
    protected static function accessor()
    {
        return 'logger';
    }
}

Available Facades

Lumberjack comes with a handful of useful Facades. Below you can see which class the Facade references and what it is bound to the container under.

Example usage

All of Lumberjack's Facades live under the Rareloop\Lumberjack\Facades namespace.

Config

The Config facade allows you to get and set values from your config.

use Rareloop\Lumberjack\Facades\Config;

Config::set('app.debug', false);

$value = Config::get('app.debug');

Config is also available as a Helper

Log

The Log facade allows you to use the PSR-3 Logger Monolog.

use Rareloop\Lumberjack\Facades\Log;

$value = Log::warning('Oops! Something went wrong');

Router

The Router facade allows you to create custom routes or get the URLs for your routes.

use Rareloop\Lumberjack\Facades\Router;

Router::get('posts/all', function () {})->name('posts.index');

$url = Router::url('posts.index');

See Creating Routes for more information.

Session

The Session facade allows you to retrieve and store data in the current session.

use Rareloop\Lumberjack\Facades\Session;

Session::put('name', 'Chris');

$name = Session::get('name');

Session is also available as a Helper

Last updated