Slimbox
![Software License][ico-license]
![Quality Score][ico-code-quality]
, (*1)
Bringing mindplay/unbox into Slim Framework., (*2)
Install
Via Composer:, (*3)
``` bash
composer require geekish/slimbox, (*4)
## Usage
### Service Provider
The most important class in this package is `Geekish\Slimbox\DefaultServicesProvider`.
It ensures the same services [required by Slim](https://www.slimframework.com/docs/concepts/di.html#required-services) 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:
```php
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)., (*5)
Settings may be provided via the constructor of the DefaultServicesProvider:, (*6)
$factory->add(new DefaultServicesProvider([
"outputBuffering" => "prepend",
]));
Or via the configure() method on ContainerFactory:, (*7)
$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., (*8)
To use the extended ContainerFactory:, (*9)
``` php
use Geekish\Slimbox\ContainerFactory;
use Geekish\Slimbox\DefaultServicesProvider;
use Slim\App;, (*10)
$factory = new ContainerFactory;
$factory->add(new DefaultServicesProvider([
"outputBuffering" => "prepend",
]));, (*11)
$container = $factory->createContainer();, (*12)
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](CHANGELOG.md) for more information what has changed recently.
## Testing
``` bash
$ composer test
Contributing
Please see CONTRIBUTING and CONDUCT for details., (*13)
Security
If you discover any security related issues, please email hannahwarmbier@gmail.com instead of using the issue tracker., (*14)
Credits
License
The MIT License (MIT). Please see License File for more information., (*15)