Documentation

Facades

Download (pdf)

Overview

Facades serve as "static proxies" to underlying classes in the service container. This provides flexibility over traditional static methods with the benefit of terser syntax.

Use

In the context of a hub, a facade is a class that provides access to an object from the container. For this to work, all facades extend the base Hubzero\Facades\Facade class.

A facade class only needs to implement a single method: getAccessor, which defines what to resolve from the container. The base Facade class makes use of the __callStatic() magic-method to defer calls from the facade to the resolved object.

Below is the facade for the Filesystem wherein the getAccessor() method returns the string 'filesystem', which is the key that the Filesystem service is registered with on the application.

class Filesystem extends Facade
{
    /**
     * Get the registered name.
     *
     * @return  string
     */
    protected static function getAccessor()
    {
        return 'filesystem';
    }
}

In the example below, a call is made to Filesystem to check that a file exists. Looking quickly at the code, one might assume that the static method exists() is being called on the Filesystem class:

<?php

namespace Components\Blog\Site\Controllers;

use Hubzero\Component\Site\Controller;
use Filesystem;
use App;

class Media extends SiteController
{
    public function downloadTask()
    {
        //...

        if ( ! Filesystem::exists($file))
        {
            App::abort(404, 'File not found');
        }

        //...
    }
}

This facade serves as a proxy to accessing the underlying implementation of the Hubzero\Filesystem\Filesystem interface. So, when any static method on the facade is referenced, the application resolves the binding from the service container and runs the requested method against that object. In short, any calls made using the facade will be passed to the underlying instance of the filesystem service.

Class Reference

Below is a list of every facade, its underlying class, and the service container binding key where applicable.

Global (all client types)
Facade Class Service Key Client
App Hubzero\Base\Application app all
Auth Hubzero\Auth\Manager auth admin, site, api
Cache Hubzero\Cache\Manager cache admin, site
Component Hubzero\Component\Loader component admin, site, api
Config Hubzero\Config\Repository config all
Date Hubzero\Utility\Date all
Document Hubzero\Document\Manager document admin, site
Event Hubzero\Events\Dispatcher dispatcher all
Filesystem Hubzero\Filesystem\Filesystem filesystem all
Html Hubzero\Html\Builder html.builder admin, site
Lang Hubzero\Language\Translator language all
Log Hubzero\Log\Writer log.debug all
Module Hubzero\Module\Loader module admin, site
Notify Hubzero\Notification\Handler notification admin, site
Pathway Hubzero\Pathway\Trail pathway site
Plugin Hubzero\Plugin\Loader plugin all
Request Hubzero\Http\Request request all
Response Hubzero\Http\Response response all
Router Hubzero\Routing\Router router all
Session Hubzero\Session\Manager session admin, site
Toolbar Hubzero\Html\Toolbar toolbar admin
Submenu Hubzero\Html\Toolbar submenu admin
User Hubzero\User\Manager user all

Last modified: