Created
January 19, 2017 10:59
-
-
Save dimkir/eb46a7e57a389ac9d2cdbc2762abfdf3 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 | |
use Respect\Validation\Validator as v; | |
/** | |
* | |
* @throws \Respect\Validation\Exceptions\ValidationException (actually superclass of \InvalidArgumentException) | |
*/ | |
function createUserEntity($username, $firstName, $lastName, $age, $heightCm, $married, $email, $comment){ | |
v::alnum()->noWhitespace()->length(1,15)->check($username); | |
v::stringType()->noWhitespace()->length(1,255)->check($firstName); | |
v::stringType()->noWhitespace()->length(1,255)->check($lastName); | |
v::intVal()->between(18, 100)->check($age); | |
v::numericVal()->between(80.5, 249.9)->check($height); | |
v::boolType()->check($married); | |
v::email()->check($email); | |
v::stringType()->length(1)->check($comment); | |
// do some useful stuff with data | |
// ... | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment