ronanchilvers/container-bridge-slim

Convenience bridge for using ronanchilvers/container with slim3

1.2 2019-10-01 07:09 UTC

This package is auto-updated.

Last update: 2021-06-02 16:12:18 UTC


README

Build Status codecov Software License

A bridge for using ronanchilvers/container with Slim3. This package allows you to replace the default slim3 container (Pimple) with ronanchilvers/container.

Installation

The easiest way to install is via composer:

composer install ronanchilvers/container-bridge-slim

Usage

To replace the default slim container with ronanchilvers/container all you need to do is pass an instance of the container into the constructor of the slim app object. Here's an example:

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Ronanchilvers\Container\Slim\Container;
use Slim\App;

// Initialise a new container instance
$container = new Container();

// Pass the container instance into the app object's constructor
$app = new App($container);

$app->get('/', function (ServerRequestInterface $request, ResponseInterface $response) {
    return $response->write('hallo');
});
$app->run();

Controlling Slim settings is similar to the usual Slim mechanism:

use Ronanchilvers\Container\Slim\Container;
use Slim\App;

$container = new Container([
    'settings' => [
        'displayErrorDetails' => true,
    ]
]);

// Create the App object
$app = new App($container);

Testing

This is quite simple a simple bridge and has 100% test coverage. You can run the tests by doing:

./vendor/bin/phpunit

The default phpunit.xml.dist file creates coverage information in a build/coverage subdirectory.

Contributing

If anyone has any patches they want to contribute I'd be more than happy to review them. Please raise a PR. You should:

  • Follow PSR2
  • Maintain 100% test coverage or give the reasons why you aren't
  • Follow a one feature per pull request rule

License

This software is licensed under the MIT license. Please see the License File for more information.