Created
June 2, 2020 17:30
-
-
Save PJZ9n/0d5761c6e078834bededefd6de3035af to your computer and use it in GitHub Desktop.
Particle/Validatorを使用したバリデーションのサンプル
This file contains hidden or 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
| <?php | |
| declare(strict_types=1); | |
| use Particle\Validator\Validator; | |
| $input = [ | |
| "enabled" => true, | |
| "items" => [ | |
| [ | |
| "id" => 400, | |
| "meta" => 50, | |
| "count" => 15, | |
| ], | |
| ], | |
| ]; | |
| $validator = new Validator(); | |
| $validator->required("enabled")->bool(); | |
| $validator->required("items")->each(function (Validator $itemValidator): void { | |
| $itemValidator->required("id")->integer(); | |
| $itemValidator->required("meta")->integer(); | |
| $itemValidator->required("count")->integer(); | |
| }); | |
| $result = $validator->validate($input); | |
| var_dump($result->isValid()); | |
| var_dump($result->getValues()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment