PHP code example of openconext / monitor-bundle

1. Go to this page and download the library: Download openconext/monitor-bundle 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/ */

    

openconext / monitor-bundle example snippets


    // config/bundles.php
    // in older Symfony apps, enable the bundle in config/bundles.php
    return [
    // ...
     OpenConext\MonitorBundle\OpenConextMonitorBundle::class => ['all' => true],
    ];
     

use OpenConext\MonitorBundle\HealthCheck\HealthCheckInterface;
use OpenConext\MonitorBundle\HealthCheck\HealthReportInterface;
use OpenConext\MonitorBundle\Value\HealthReport;

class ApiHealthCheck implements HealthCheckInterface
{
    public function __construct(private readonly MyService $service)
    {
    }

    public function check(HealthReportInterface $report): HealthReportInterface
    {
        if (!$this->service->everythingOk()) {
            // Return a HealthReport with a DOWN status when there are indications the application is not functioning as
            // intended. You can provide an optional message that is displayed alongside the DOWN status.
            return HealthReport::buildStatusDown('Not everything is allright.');
        }
        // By default, return the report that was passed along as a parameter to the check method
        return $report;
    }
}