cms-health-project / serializable-reference-implementation
Reference implementation of the CMS HealthCheck RFC using the \JsonSerializable interface.
Package info
github.com/cms-health-project/serializable-reference-implementation
pkg:composer/cms-health-project/serializable-reference-implementation
Requires
- php: ^8.1
- cms-health-project/health-check-rfc: ^0.0.5
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.51
- phpstan/phpstan: ^1.10.62
- phpstan/phpstan-phpunit: ^1.3.16
- phpunit/phpunit: ^10.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Introduction
This library provides an example reference implementation of the
CMS HealthCheck RFC
using the \JsonSerializable interface to avoid the usage of a
dedicated formatter or builder as it is integrated into the classes
directly.
Maintainer
This package has been created and is maintained by Stefan Bürk stefan@buerk.tech.
Installation
To use this library in your project or library, require it with:
conmposer require "cms-health-project/serializable-reference-implementation"
Usage
Build up the result structure:
$time = \DateTimeImmutable::createFromFormat('Y-m-d\TH:i:sP', '2024-03-19T01:23:45+00:00'); $check1 = new Check('package:check-one'); $check1->addCheckResults( new CheckResult( 'check1-component1', 'system', CheckResultStatus::Pass, $time, ), ); $check2 = new Check('package:check-two'); $check2->addCheckResults( new CheckResult( 'check2-component1', 'system', CheckResultStatus::Fail, $time, 'observed-value', 'with-unit', 'and-output' ), ); $checks = new CheckCollection(); $checks->addCheck($check1, $check2); $healthCheck = new HealthCheck( HealthCheckStatus::Fail, '1', 'service-id', 'description', $checks, );
and than simply use json_encode() to create the json:
$json = \json_encode($healthCheck, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT);
and you get the json, for example:
{
"status": "fail",
"version": "1",
"serviceId": "service-id",
"description": "description",
"checks": {
"package:check-one": [
{
"componentId": "check1-component1",
"componentType": "system",
"status": "pass",
"time": "2024-03-19T01:23:45+00:00"
}
],
"package:check-two": [
{
"componentId": "check2-component1",
"componentType": "system",
"status": "fail",
"time": "2024-03-19T01:23:45+00:00",
"output": "and-output",
"observedValue": "observed-value",
"observedUnit": "with-unit"
}
]
}
}
Contribution
This package contains for now only a cgl check based on php-cs-fixer.
composer install
composer cgl:fix