Last active
February 12, 2020 12:01
-
-
Save PJZ9n/42cdcc722883b4be04f23ca7b60e2428 to your computer and use it in GitHub Desktop.
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); | |
| require_once __DIR__ . "/vendor/autoload.php"; | |
| use Particle\Filter\Filter; | |
| use Particle\Validator\Validator; | |
| $post = [ | |
| "name" => "PJZ9n", | |
| "age" => "64", | |
| "birthday" => "2020/02/12", | |
| "url" => "ha", | |
| ]; | |
| $f = new Filter(); | |
| $f->value("name")->trim()->string(); | |
| $f->value("age")->trim()->int(); | |
| $f->value("birthday")->trim()->string(); | |
| $f->value("url")->trim(); | |
| $result = $f->filter($post); | |
| echo "Filter Result: "; | |
| print_r($result); | |
| $v = new Validator(); | |
| $v->required("name")->string()->lengthBetween(1, 10); | |
| $v->required("age")->integer()->between(18, PHP_INT_MAX); | |
| $v->required("birthday")->string()->datetime("Y/m/d"); | |
| $v->required("url")->string()->url(); | |
| $result = $v->validate($post); | |
| echo "Validator Result: "; | |
| var_dump($result->isValid()); | |
| echo "Final Value: "; | |
| print_r($result->getValues()); | |
| $failureFormats = []; | |
| foreach ($result->getFailures() as $failure) { | |
| $failureFormats[] = $failure->format(); | |
| } | |
| echo "Errors: " . implode(" | ", $failureFormats); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment