PHPackages                             atlantic8-web/slim-magic - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. atlantic8-web/slim-magic

ActiveLibrary[Framework](/categories/framework)

atlantic8-web/slim-magic
========================

An auto router, auto discovery class mapper/loader for Slim Framework 3. Keeping your Slim bootstrapping clean no matter how many routes, dependencies and middleware you have.

2.0(8y ago)468[1 issues](https://github.com/atlantic8-web/slim-magic/issues)MITPHPPHP ~7.1

Since Aug 3Pushed 8y ago1 watchersCompare

[ Source](https://github.com/atlantic8-web/slim-magic)[ Packagist](https://packagist.org/packages/atlantic8-web/slim-magic)[ Docs](https://github.com/atlantic8-web/slim-magic)[ RSS](/packages/atlantic8-web-slim-magic/feed)WikiDiscussions 1.0.2 Synced 4w ago

READMEChangelog (5)DependenciesVersions (9)Used By (0)

slim-magic
==========

[](#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
------------

[](#installation)

It's recommended that you use [Composer](https://getcomposer.org/) 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
-------------

[](#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
-------------------

[](#directory-structure)

In order to keep things clean we can use folders and service bootstrapper classes - [See code example](https://github.com/atlantic8-web/slim-magic-example-simple)

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

Usage
-----

[](#usage)

Create a Slim config.php and add SlimMagic route setup and configuration - [See code example](https://github.com/atlantic8-web/slim-magic-example-simple)

Create an index.php file with the following contents:

```
