PHP code example of aegisora / is-callable-rule-guardian
1. Go to this page and download the library: Download aegisora/is-callable-rule-guardian 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/ */
aegisora / is-callable-rule-guardian example snippets
$guardian->check(
$value,
IsCallableRule::create(),
new ValueIsNotCallableException()
);
$isCallableRuleGuardian->check($value, new ValueIsNotCallableException());
use Aegisora\Guardian\Guardian;
use Aegisora\Guardian\Exceptions\GuardianValidationException;
use Aegisora\RuleGuardians\IsCallableRule\IsCallableRuleGuardian;
$guardian = new Guardian();
$isCallableRuleGuardian = new IsCallableRuleGuardian($guardian);
try {
$isCallableRuleGuardian->check($value);
// $value is callable
} catch (GuardianValidationException $exception) {
// $value is not callable
}
use Aegisora\Guardian\Guardian;
use Aegisora\RuleGuardians\IsCallableRule\IsCallableRuleGuardian;
use App\Exceptions\ValueIsNotCallableException;
$guardian = new Guardian();
$isCallableRuleGuardian = new IsCallableRuleGuardian($guardian);
$isCallableRuleGuardian->check(
$value,
new ValueIsNotCallableException()
);
use Aegisora\RuleGuardians\IsCallableRule\IsCallableRuleGuardian;
use App\Exceptions\InvalidHandlerException;
final class HandlerRegistry
{
private IsCallableRuleGuardian $isCallableRuleGuardian;
public function __construct(
IsCallableRuleGuardian $isCallableRuleGuardian
) {
$this->isCallableRuleGuardian = $isCallableRuleGuardian;
}
/**
* @param mixed $handler
*/
public function register(string $name, $handler): void
{
$this->isCallableRuleGuardian->check(
$handler,
new InvalidHandlerException()
);
// business logic for registering a callable handler
}
}
use App\Exceptions\ValueIsNotCallableException;
try {
$isCallableRuleGuardian->check($value, new ValueIsNotCallableException());
} catch (ValueIsNotCallableException $exception) {
// domain-specific handling
}
use Aegisora\Guardian\Exceptions\GuardianExecutingRuleException;
try {
$isCallableRuleGuardian->check($value);
} catch (GuardianExecutingRuleException $exception) {
// the rule could not be executed
}