1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\Validator\Rule; |
6
|
|
|
|
7
|
|
|
use Attribute; |
8
|
|
|
use Closure; |
9
|
|
|
use ReflectionProperty; |
10
|
|
|
use Yiisoft\Validator\BeforeValidationInterface; |
11
|
|
|
use Yiisoft\Validator\Rule\Trait\BeforeValidationTrait; |
12
|
|
|
use Yiisoft\Validator\SerializableRuleInterface; |
13
|
|
|
use Yiisoft\Validator\ValidationContext; |
14
|
|
|
|
15
|
|
|
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)] |
16
|
|
|
final class Embedded implements SerializableRuleInterface, BeforeValidationInterface |
17
|
|
|
{ |
18
|
|
|
use BeforeValidationTrait; |
19
|
|
|
|
20
|
10 |
|
public function __construct( |
21
|
|
|
private int $propertyVisibility = ReflectionProperty::IS_PRIVATE | ReflectionProperty::IS_PROTECTED | ReflectionProperty::IS_PUBLIC, |
22
|
|
|
private bool $skipOnEmpty = false, |
23
|
|
|
/** |
24
|
|
|
* @var callable|null |
25
|
|
|
*/ |
26
|
|
|
private $skipOnEmptyCallback = null, |
27
|
|
|
private bool $skipOnError = false, |
28
|
|
|
/** |
29
|
|
|
* @var Closure(mixed, ValidationContext):bool|null |
30
|
|
|
*/ |
31
|
|
|
private ?Closure $when = null, |
32
|
|
|
) { |
33
|
10 |
|
$this->initSkipOnEmptyProperties($skipOnEmpty, $skipOnEmptyCallback); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function getName(): string |
37
|
|
|
{ |
38
|
|
|
return 'Embedded'; |
39
|
|
|
} |
40
|
|
|
|
41
|
4 |
|
public function getHandlerClassName(): string |
42
|
|
|
{ |
43
|
4 |
|
return EmbeddedHandler::class; |
44
|
|
|
} |
45
|
|
|
|
46
|
6 |
|
public function getPropertyVisibility(): int |
47
|
|
|
{ |
48
|
6 |
|
return $this->propertyVisibility; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function getOptions(): array |
52
|
|
|
{ |
53
|
|
|
return [ |
54
|
|
|
'skipOnEmpty' => $this->skipOnEmpty, |
55
|
|
|
'skipOnError' => $this->skipOnError, |
56
|
|
|
]; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|