1. Go to this page and download the library: Download worlddirect/healthcheck 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/ */
namespace Vendor\YourExtension\Probe;
use WorldDirect\Healthcheck\Probe\ProbeBase;
use WorldDirect\Healthcheck\Probe\ProbeInterface;
class CustomProbe extends ProbeBase implements ProbeInterface
{
/**
* Determine if this probe should run.
* Use this to check prerequisites (e.g., if an extension is loaded).
*
* @return bool
*/
public function useProbe(): bool
{
// Return true if the probe should run
return true;
}
/**
* Get the display title for this probe.
*
* @return string
*/
public function getTitle(): string
{
return 'My Custom Check';
}
/**
* Execute the probe logic.
*
* @return void
*/
public function run(): void
{
// Start timing the probe
parent::start();
// Your custom check logic here
try {
// Perform your checks
$result = $this->performCustomCheck();
if ($result) {
// Add success message
$this->result->addSuccessMessage('Custom check passed successfully');
} else {
// Add error message
$this->result->addErrorMessage('Custom check failed: something went wrong');
}
} catch (\Exception $e) {
// Handle exceptions
$this->result->addErrorMessage('Custom check error: ' . $e->getMessage());
}
// Stop timing the probe
parent::stop();
}
/**
* Your custom check logic.
*
* @return bool
*/
private function performCustomCheck(): bool
{
// Implement your check logic
return true;
}
}
namespace Vendor\YourExtension\Output;
use WorldDirect\Healthcheck\Output\OutputBase;
use WorldDirect\Healthcheck\Output\OutputInterface;
use WorldDirect\Healthcheck\Domain\Model\HealthcheckResult;
class CustomOutput extends OutputBase implements OutputInterface
{
/**
* Generate the output content.
*
* @param HealthcheckResult $result
* @return string
*/
public function getContent(HealthcheckResult $result): string
{
// Generate your custom output
// Access probes via: $result->getProbes()
// Access overall status via: $result->getStatus()
return 'Your custom formatted output';
}
/**
* Return the content type for this output.
*
* @return string
*/
public function getContentType(): string
{
return 'text/plain'; // or 'application/xml', 'text/csv', etc.
}
}