Skip to content

A bootstrapper/classmapper/dynamic router for Slim Framework 3x. Keeping your Slim bootstrapping clean no matter how many routes, dependencies and middleware you have, allowing you to build really large applications in a structured manner.

License

Notifications You must be signed in to change notification settings

plasid/slim-magic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

slim-magic

A bootstrapper/classmapper/loader for Slim Framework 3x. Keeping your Slim bootstrapping clean no matter how many routes, dependencies and middleware you have, allowing you to build really large applications in a structured manner.

Installation

It's recommended that you use Composer to install SlimMagic.

$ composer require atlantic8-web/slim-magic "^1.0"
// or add to your existing composer.json file

This will install SlimMagic and all required dependencies. SlimMagic requires PHP 5.5.0 or newer.

Configuration

'slim_magic_settings' => [
        'debug'=>false,
        'routes' => [
            //Home
            '/' => [
                'methods' => ['GET'], //Can be an array of methods, or ommit for default GET
                'classmap' => 'app\Home:index', //String resolver app
                'middleware' => [], //Middleware to load for this app
                'arguments' => [],//Arguments to pass to this app
                'name' => 'home' //App name, also used to generate URL's $slim->setName(...)
            ],
            '/admin/dashboard' => [
                'methods' => ['GET'],
                'classmap' => 'app\Admin:dashboard',
                'middleware' => ['AuthValidation', 'GrapPreload'],
                'arguments' => ['isAdmin'],
                'name' => 'admin_dashboard'
            ]
        ],
        //This will be applied to all routes/apps
        'all' => [
            'middleware' => ['Test', 'Session'],//See Slim docs for importance of order               
            'service' => ['SessionHelper', 'Twig', 'notFoundHandler'] //Service dependencies
        ]
    ]
        

Directory structure

In order to keep things clean we can use folders and service bootstrapper classes - See code example

MyNewApp
    -app
    -config
        -slim.php
    -service
        -Dependency
        -Middleware
    -view
    -model
-.htaccess
-index.php

Usage

Create a Slim config.php and add SlimMagic route setup and configuration - See code example

Create an index.php file with the following contents:

<?php

require 'vendor/autoload.php';

$container = new \Slim\Container(require 'config/slim.php');

$service = new \SlimMagic\ServiceContainer(new \Slim\App($container), $container->slim_magic_settings);
new \SlimMagic\Mapper($service);

$service->getSlim()->run();

See code example, configuration and architecture (CLI is no longer supported, instead handle CLI via your bootstrap) Example

License

The SlimMagic is licensed under the MIT license. See License File for more information.

About

A bootstrapper/classmapper/dynamic router for Slim Framework 3x. Keeping your Slim bootstrapping clean no matter how many routes, dependencies and middleware you have, allowing you to build really large applications in a structured manner.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages