bnf/slim-interop-service-provider
Composer 安装命令:
composer require bnf/slim-interop-service-provider
包简介
container-interop/service-provider compatible service provider for Slim
README 文档
README
Provides container-interop/service-provider support for Slim.
Installation
$ composer require bnf/slim-interop-service-provider:^4.0
Usage
Add Bnf\SlimInterop\ServiceProvider to the list of service providers to register the default Slim services.
Specify it as first service provider to be able to overwrite or extend default services.
new Container([ new \Bnf\SlimInterop\ServiceProvider, new YouServiceProvider, ]);
Example
Example usage with a container-interop/service-provider compatible container bnf/di.
$ composer require bnf/slim-interop-service-provider:^4.0 bnf/di:~0.1.0 slim/slim:^4.0 slim/psr7:~0.4.0
<?php declare(strict_types = 1); require 'vendor/autoload.php'; use Bnf\Di\Container; use Bnf\SlimInterop\ServiceProvider as SlimServiceProvider; use Psr\Container\ContainerInterface; use Interop\Container\ServiceProviderInterface; use Slim\App; class Index { public function __invoke($request, $response) { $response->getBody()->write('Hello World.'); return $response; } } $container = new Container([ // Register default slim services new SlimServiceProvider, // Register own services and configuration new class implements ServiceProviderInterface { public function getFactories(): array { return [ 'slim.display_error_details' => function(): bool { return true; }, Index::class => function (ContainerInterface $container): Index { return new Index; } ]; } public function getExtensions(): array { return [ // configure app route and middlewares as extension to the App class App::class => function (ContainerInterface $container, App $app): App { $app->add(\Slim\Middleware\ErrorMiddleware::class); $app->get('/', Index::class); return $app; }, ]; } } ]); $app = $container->get(App::class); $app->run();
统计信息
- 总下载量: 71
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0
- 更新时间: 2019-02-22