Writing your own checks
To write your own check just create a class with Sunhill\Basic\Checker\Checker
as ancestor.
static variables
string $group = ""
Overwrite this static string to assign the checks to a check group that can be selected by the check command.
Writing a check
Inside your check you can write public methods which names begin with check. These perform a single check. These method take a single boolean parameter $repair. If set to true the method should try to repair a problem if it found one.
The methods should call on of the following methods:
Methods to finish a check
pass()
The check was passed, no problem was found.
fail(string $message)
The check failed, $repair was not set, so just report the failure. Give some details in $message.
repair(string $message)
The check failed, $repair was set and the repair was successful. Give some details in $message.
unrepairable(string $message)
The check failed, $repair was set and the repair failed. Give some details in $message.
Example
<?php use Sunhill\Basic\Checker\Checker; class MyCheck extends Checker { static protected string $group = 'MyGroup'; public function checkSomething(bool $repair) { if ($this->performACheck()) { return $this->pass(); } if ($repair) { if ($this->tryToRepair()) { return $this->repair('Check failed but was repaired'); } else { return $this->unrepairable('Check failed and was not repairable'); } } else { return $this->failed('Check failed and no repair was wanted'); } } }
Registering your check
To make you check known to the checks subsystem you have to register it. This is performed by the checks facade:
Checks::installChecker(MyCheck::class);