for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Yiisoft\Validator\Rule\Json;
use Attribute;
use Closure;
use Yiisoft\Validator\Rule\RuleNameTrait;
use Yiisoft\Validator\Rule\HandlerClassNameTrait;
use Yiisoft\Validator\RuleInterface;
/**
* Validates that the value is a valid json.
*/
#[Attribute(Attribute::TARGET_PROPERTY)]
final class Json implements RuleInterface
{
use HandlerClassNameTrait;
use RuleNameTrait;
public function __construct(
public string $message = 'The value is not JSON.',
public bool $skipOnEmpty = false,
public bool $skipOnError = false,
public ?Closure $when = null,
) {
}
public function getOptions(): array
return [
'message' => [
'message' => $this->message,
],
'skipOnEmpty' => $this->skipOnEmpty,
'skipOnError' => $this->skipOnError,
];