Revision: Wed, 27 Nov 2024 11:25:20 GMT
v3.13 – outdated
This version of the documentation is outdated. Consider upgrading your project to Spiral Framework 3.14
Edit this page

Keeper — Bootloaders

Keeper contains the next bootloaders:

  • Spiral\Keeper\Bootloader\KeeperBootloader is the entrypoint for all other bootloaders
  • Spiral\Keeper\Bootloader\GuestBootloader grants full access to guest users (use it only for tests)
  • Spiral\Keeper\Bootloader\AnnotatedBootloader reads Controller and Action annotations ( see Routing)
  • Spiral\Keeper\Bootloader\SitemapBootloader reads the sitemap annotations, can also be used for Sitemap definition via code (see Sitemap)
  • Spiral\Keeper\Bootloader\UIBootloader registers keeper views - layout, sidebar, breadcrumbs, grids, etc. ( see Sitemap and Views)

Usage

Spiral\Keeper\Bootloader\KeeperBootloader is abstract. First of all create your own inherited bootloader. If needed, all the rest of keeper bootloaders should be registered in LOAD const.

php
use App\Bootloader\Keeper;
use Spiral\DataGrid\Interceptor\GridInterceptor;
use Spiral\Domain\CycleInterceptor;
use Spiral\Domain\FilterInterceptor;
use Spiral\Domain\GuardInterceptor;
use Spiral\Keeper\Bootloader;
use Spiral\Keeper\Middleware;

class KeeperBootloader extends Bootloader\KeeperBootloader
{
    protected const NAMESPACE          = 'keeper';
    protected const PREFIX             = 'keeper/';
    protected const DEFAULT_CONTROLLER = 'dashboard';
    protected const CONFIG_NAME        = '';

    protected const LOAD = [
        Bootloader\SitemapBootloader::class,
        Bootloader\AnnotatedBootloader::class,
    ];

    protected const MIDDLEWARE = [
        Middleware\LoginMiddleware::class
    ];

    protected const INTERCEPTORS = [
        CycleInterceptor::class,
        GuardInterceptor::class,
        FilterInterceptor::class,
        GridInterceptor::class,
    ];
}

Namespace

You can define the current keeper namespace using NAMESPACE const. keeper is by default.

Prefix

You can define the current route prefix using PREFIX const. keeper/ is by default.

Default Controller

You can define the default route controller using DEFAULT_CONTROLLER const. Default action can be declared only via config file (or, if set, defaultAction annotation property or index method).

Config name

You can define the config name for the current keeper namespace using CONFIG_NAME const. If omitted, NAMESPACE const value will be used.

Middlewares

You can list custom middlewares in the MIDDLEWARE const. Additional middlewares can be applied in the routes separately for each route, both sets will be applied.

Interceptors

You can list custom interceptors in the INTERCEPTORS const.

Config

Keeper config can be fully declared in the config file.

Config file should be stored in the app config directory.

php
return [
   'routePrefix'   => '',
   'routeDefaults' => ['controller' => '', 'action' => ''],
   'loginView'     => 'keeper:login',
   'middleware'    => [],
   'modules'       => [],
   'interceptors'  => [],
];

Prefix, default controller, list of middlewares, modules' bootloaders and interceptors from the constants are used as config defaults.