postalservice14/php-actuator-slim-provider

php-actuator 的 Slim 提供者

1.0.0 2016-02-19 19:50 UTC

This package is auto-updated.

Last update: 2024-09-15 23:52:58 UTC


README

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

php-actuator 的 Slim 提供者

安装

通过 Composer

$ composer require postalservice14/php-actuator-slim-provider

注册

$container = $app->getContainer();
$container['health.aggregator'] = new OrderedHealthAggregator();
$container['health.indicators'] = array(
    'disk' => new DiskSpaceHealthIndicator()
);
$container['health'] = function ($container) {
    return new HealthServiceProvider(
        $container['health.aggregator'],
        $container['health.indicators']
    );
};

使用

设置你想要的健康检查路由。例如:

$app->get('/health', function ($req, $res) {
    return $this->health->getHealth($res);
});

然后访问你的端点。在这种情况下: /health

入门

以下是一个快速入门的最小示例。它使用 DiskSpaceHealthIndicator

  • 创建一个 composer.json 文件,至少包含以下依赖项
{
    "require": {
        "postalservice14/php-actuator-slim-provider": "^1.0"
    }
}
  • 运行 composer install
  • 创建 /public/index.php
<?php

require_once __DIR__.'/../vendor/autoload.php';

use Slim\App;
use Actuator\Health\OrderedHealthAggregator;
use Actuator\Health\Indicator\DiskSpaceHealthIndicator;
use Actuator\Slim\Provider\HealthServiceProvider;

$indicators = array(
    'disk' => new DiskSpaceHealthIndicator()
);

$app = new App();

$container = $app->getContainer();
$container['health.aggregator'] = new OrderedHealthAggregator();
$container['health.indicators'] = $indicators;
$container['health'] = function ($container) {
    return new HealthServiceProvider(
        $container['health.aggregator'],
        $container['health.indicators']
    );
};

$app->get('/health', function ($req, $res) {
    return $this->health->getHealth($res);
});
$app->run();

示例

可在 /example 中找到

变更日志

请参阅 CHANGELOG 了解最近更改的更多信息。

测试

$ composer test

贡献

请参阅 CONTRIBUTINGCONDUCT 了解详细信息。

鸣谢

许可协议

MIT 许可协议 (MIT)。有关更多信息,请参阅 许可文件