PHP code example of aegisora / is-array-rule-guardian
1. Go to this page and download the library: Download aegisora/is-array-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-array-rule-guardian example snippets
$guardian->check(
$value,
IsArrayRule::create(),
new ValueIsNotArrayException()
);
$isArrayRuleGuardian->check($value, new ValueIsNotArrayException());
use Aegisora\Guardian\Guardian;
use Aegisora\Guardian\Exceptions\GuardianValidationException;
use Aegisora\RuleGuardians\IsArrayRule\IsArrayRuleGuardian;
$guardian = new Guardian();
$isArrayRuleGuardian = new IsArrayRuleGuardian($guardian);
try {
$isArrayRuleGuardian->check($value);
// $value is an array
} catch (GuardianValidationException $exception) {
// $value is not an array
}
use Aegisora\Guardian\Guardian;
use Aegisora\RuleGuardians\IsArrayRule\IsArrayRuleGuardian;
use App\Exceptions\ValueIsNotArrayException;
$guardian = new Guardian();
$isArrayRuleGuardian = new IsArrayRuleGuardian($guardian);
$isArrayRuleGuardian->check(
$value,
new ValueIsNotArrayException()
);
use Aegisora\RuleGuardians\IsArrayRule\IsArrayRuleGuardian;
use App\Exceptions\InvalidPayloadException;
final class PayloadProcessor
{
private IsArrayRuleGuardian $isArrayRuleGuardian;
public function __construct(
IsArrayRuleGuardian $isArrayRuleGuardian
) {
$this->isArrayRuleGuardian = $isArrayRuleGuardian;
}
/**
* @param mixed $payload
*/
public function process($payload): void
{
$this->isArrayRuleGuardian->check(
$payload,
new InvalidPayloadException()
);
// business logic for processing an array payload
}
}
use App\Exceptions\ValueIsNotArrayException;
try {
$isArrayRuleGuardian->check($value, new ValueIsNotArrayException());
} catch (ValueIsNotArrayException $exception) {
// domain-specific handling
}
use Aegisora\Guardian\Exceptions\GuardianExecutingRuleException;
try {
$isArrayRuleGuardian->check($value);
} catch (GuardianExecutingRuleException $exception) {
// the rule could not be executed
}