PHP
Switch branches/tags
Nothing to show
Clone or download
geekish Fix PHPUnit version
6.0 is 7.0+ and we’re allowing 5.6, so we need to allow 5.7…
Latest commit 0621410 May 17, 2017

README.md

Slimbox

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

Bringing mindplay/unbox into Slim Framework.

Install

Via Composer:

composer require geekish/slimbox

Usage

Service Provider

The most important class in this package is Geekish\Slimbox\DefaultServicesProvider. It ensures the same services required by Slim are available through Unbox. Besides the change in container, it differs from Slim\DefaultServicesProvider by registering services under their FQCN first, then registers aliases by their interfaces, and finally the short aliases used by slim (e.g. "router", "foundHandler"). Registering services by their class name enables Unbox to automatically inject them as dependencies as needed by other classes.

The service provider is not automatically registered for you, so you need to do this yourself:

use Geekish\Slimbox\DefaultServicesProvider;
use mindplay\unbox\ContainerFactory;

$factory = new ContainerFactory;
$factory->add(new DefaultServicesProvider);

$container = $factory->createContainer();

Settings

Also included is Geekish\Slimbox\Settings, which extends from Slim\Collection. This class replaces the simple array that Slim registers under "settings" (see: Slim Default Settings).

Settings may be provided via the constructor of the DefaultServicesProvider:

$factory->add(new DefaultServicesProvider([
    "outputBuffering" => "prepend",
]));

Or via the configure() method on ContainerFactory:

$factory->configure(
    Settings::class,
    function (Settings $settings) {
        $settings['displayErrorDetails'] = true;
        return $settings;
    }
);

Container and Container Factory (Optional)

This package contains an extended (final) Container and ContainerFactory from Unbox. Usage is almost exactly the same as using Unbox directly, except the extended Container partially implements ArrayAccess. This allows you to use the Container like an array to access services; however, due to the fact that Unbox uses a factory class to create the container, you cannot use array notation to set/configure services on the Container.

To use the extended ContainerFactory:

use Geekish\Slimbox\ContainerFactory;
use Geekish\Slimbox\DefaultServicesProvider;
use Slim\App;

$factory = new ContainerFactory;
$factory->add(new DefaultServicesProvider([
    "outputBuffering" => "prepend",
]));

$container = $factory->createContainer();

Usage of the packaged Container and ContainerFactory is entirely optional; they are included purely for convenience and consistency with Slim's packaged Container. Simply replace Geekish\Slimbox\ContainerFactory in the snippet above with mindplay\unbox\ContainerFactory.

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Security

If you discover any security related issues, please email hannahwarmbier@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.