dev-master
9999999-devLaravel-like service providers for slim framework
MIT
The Requires
The Development Requires
by Andrew Alferenkov
Laravel-like service providers for slim framework
This package is made for Slim, to make it's configuration a little bit better, but you can use it in any project. This package is framework agnostic, it relies only on PSR-11 Container interface., (*1)
composer require andrewalf/service_providers
composer run tests
service_providers.php
file in your project's root. This file should return array of
service providers full class names.index.php
file require that file in a variable.index.php
file add in DI container your app instance with the "app" key.ServiceProviderRunner
instance, with psr-11 DI container and providers array as constructor params.
Call it's runProviders methodNow you can add your custom service providers. They have two methods: register and boot. In register method, which called first, you should register dependencies in the container. In boot method feel free to modify and configure your app as you want. For example, you can create EventListenersServiceProvider where keep all your listeners attachments., (*2)
index.php, (*3)
$app = new \Slim\App($settings); $container = $app->getContainer(); // we use RouteServiceProvider $container['app'] = function ($c) use ($app) { return $app; }; $providersArray = require '../service_providers.php'; (new \Andrewalf\ServiceProviderRunner($app->getContainer(), $providersArray))->runProviders();
service_providers.php, (*4)
return [ \Andrewalf\RouteServiceProvider::class, \Andrewalf\AppServiceProvider::class ];
This is made mostly for Slim. This provider loads app routes from separated files: web.php and api.php. Path to these files is hardcoded in provider. Feel free to copy and modify it., (*5)
TODO: composer command for coping package providers to your providers directory., (*6)
Laravel-like service providers for slim framework
MIT