PHP code example of oat-sa / lib-health-check
1. Go to this page and download the library: Download oat-sa/lib-health-check library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
oat-sa / lib-health-check example snippets
declare(strict_types=1);
use OAT\Library\HealthCheck\Checker\CheckerInterface;
use OAT\Library\HealthCheck\Result\CheckerResult;
class MySuccessChecker implements CheckerInterface
{
public function getIdentifier() : string
{
return 'MySuccessChecker';
}
public function check() : CheckerResult
{
return new CheckerResult(true, 'my success message');
}
}
class MyFailureChecker implements CheckerInterface
{
public function getIdentifier() : string
{
return 'MyFailureChecker';
}
public function check() : CheckerResult
{
return new CheckerResult(false, 'my failure message');
}
}
declare(strict_types=1);
use OAT\Library\HealthCheck\HealthChecker;
$healthChecker = new HealthChecker();
$results = $healthChecker
->registerChecker(new MySuccessChecker())
->registerChecker(new MyFailureChecker())
->performChecks();
$results->hasErrors(); // true
foreach ($results as $result) {
echo $result->getMessage();
}