lekoala/silverstripe-micro-framework

A micro framework for SilverStripe

Installs: 4

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 4

Forks: 0

Open Issues: 0

Type:silverstripe-vendormodule

dev-master 2021-11-10 13:42 UTC

This package is auto-updated.

Last update: 2024-03-10 18:44:45 UTC


README

Build Status scrutinizer Code coverage

Intro

This module makes it easier to use standalone SilverStripe framework without the Cms module.

It can also run a website without any database configured.

WARNING : this is highly experimental :-)

Replace your index.php

In order to use this, you need to replace the default index.php with this

// Force specific constants
define('BASE_PATH', dirname(__DIR__));
define('PUBLIC_DIR', 'public');
define('PUBLIC_PATH', BASE_PATH . DIRECTORY_SEPARATOR . PUBLIC_DIR);
define('RESOURCES_DIR', 'resources');

require dirname(__DIR__) . '/vendor/autoload.php';

// Build request and detect flush
$request = \SilverStripe\Control\HTTPRequestBuilder::createFromEnvironment();
// Default application
$kernel = new \LeKoala\MicroFramework\MicroKernel(BASE_PATH);
$app = new \SilverStripe\Control\HTTPApplication($kernel);
$response = $app->handle($request);
$response->output();

New base controller

Please use MicroController as the base controller for your applications. It is recommended to create a base controller (like a PageController) as a base for your application instead of extending MicroController each time.

class AppController extends MicroController
{
}

Setting base controller

This is really handy for Security screen.

SilverStripe\Security\Security:
  page_class: 'App\AppController'

Note: this is working thanks to our custom MicroSecurity extension.

Auto routing

If you define url_segment on your controllers, the will be added to available routes automatically

class HomeController extends AppController
{
    private static $url_segment = 'home';
    private static $is_home = true;
    ...

You can also set a is_home variable for the default controller. In this case, the default segment /home will redirect to / to avoid duplicated urls.

Simple action declaration

If it bothers you to declare two times your action (once as a function, and once as a function), fear not!

You can now simply make sure your first argument accepts an HTTPRequest and it will be considered as a valid action.

Page compat

Most SilverStripe projects have a "Page" template. Even if you are not using Page class, the Page.ss will be seen as the base class.

Login as admin without db

There are some convenience function allowing you to use the login screen without db

Compatibility

Tested with 4.6 and higher

Maintainer

LeKoala - thomas@lekoala.be