-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix hook processing for nested objects when
Nested
is used (#748)
Co-authored-by: Sergei Predvoditelev <[email protected]> Co-authored-by: Alexander Makarov <[email protected]> Co-authored-by: Alexey Rogachev <[email protected]>
- Loading branch information
1 parent
3c66920
commit 22d6572
Showing
5 changed files
with
150 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
tests/Support/Data/NestedHookProvider/NestedObjectWithPostValidationHook.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Validator\Tests\Support\Data\NestedHookProvider; | ||
|
||
use Yiisoft\Validator\PostValidationHookInterface; | ||
use Yiisoft\Validator\Result; | ||
use Yiisoft\Validator\Rule\Each; | ||
use Yiisoft\Validator\Rule\Length; | ||
use Yiisoft\Validator\Rule\Nested; | ||
use Yiisoft\Validator\Rule\Required; | ||
use Yiisoft\Validator\Rule\StringValue; | ||
|
||
class NestedObjectWithPostValidationHook implements PostValidationHookInterface | ||
{ | ||
#[Required] | ||
#[StringValue] | ||
#[Length(min: 6)] | ||
public string $firstString = 'short'; | ||
|
||
#[Each( | ||
[ | ||
new StringValue(), | ||
new Length(min: 6), | ||
] | ||
)] | ||
public array $firstArray = [ | ||
'short', | ||
'short', | ||
'long string', | ||
]; | ||
|
||
#[Nested(SecondNestedObjectWithPostValidationHook::class)] | ||
public SecondNestedObjectWithPostValidationHook $secondNested; | ||
|
||
public ?Result $validationResult = null; | ||
|
||
public function __construct() | ||
{ | ||
$this->secondNested = new SecondNestedObjectWithPostValidationHook(); | ||
} | ||
|
||
public function processValidationResult(Result $result): void | ||
{ | ||
$this->validationResult = $result; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
tests/Support/Data/NestedHookProvider/SecondNestedObjectWithPostValidationHook.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Validator\Tests\Support\Data\NestedHookProvider; | ||
|
||
use Yiisoft\Validator\PostValidationHookInterface; | ||
use Yiisoft\Validator\Result; | ||
use Yiisoft\Validator\Rule\Integer; | ||
use Yiisoft\Validator\Rule\Length; | ||
use Yiisoft\Validator\Rule\Required; | ||
use Yiisoft\Validator\Rule\StringValue; | ||
|
||
class SecondNestedObjectWithPostValidationHook implements PostValidationHookInterface | ||
{ | ||
#[Required] | ||
#[Integer(min: 5, max: 10)] | ||
public int $secondInt = 15; | ||
#[StringValue] | ||
#[Length(min: 10)] | ||
public string $secondString = 'short'; | ||
public ?Result $validationResult = null; | ||
|
||
public function __construct() | ||
{ | ||
} | ||
|
||
public function processValidationResult(Result $result): void | ||
{ | ||
$this->validationResult = $result; | ||
} | ||
} |