ronanchilvers/container-bridge-slim

ronanchilvers/container 与 slim3 使用的便捷桥梁

2.0 2022-11-25 18:46 UTC

This package is auto-updated.

Last update: 2024-09-25 22:36:49 UTC


README

Build Status codecov Software License

这是一个用于在 Slim3 中使用 ronanchilvers/container 的桥梁。此包允许您用 ronanchilvers/container 替换默认的 slim3 容器(Pimple)。

安装

最简单的安装方式是通过 composer

composer install ronanchilvers/container-bridge-slim

使用方法

要替换默认的 slim 容器,您只需要将容器实例传递给 slim 应用对象构造函数。以下是一个示例

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();

控制 Slim 设置的方式与常规 Slim 机制类似

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

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

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

测试

这是一个非常简单的桥梁,并具有 100% 的测试覆盖率。您可以通过以下方式运行测试

./vendor/bin/phpunit

默认的 phpunit.xml.dist 文件会在 build/coverage 子目录中创建覆盖率信息。

贡献

如果有任何补丁想要贡献,我会非常乐意审查。请提交 PR。您应该

  • 遵循 PSR2
  • 保持 100% 的测试覆盖率或给出您不这样做的原因
  • 遵循每 pull request 一个功能的原则

许可证

此软件受 MIT 许可证许可。有关更多信息,请参阅 许可证文件