Skip to content

Instantly share code, notes, and snippets.

@dimkir
Created January 19, 2017 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dimkir/eb46a7e57a389ac9d2cdbc2762abfdf3 to your computer and use it in GitHub Desktop.
Save dimkir/eb46a7e57a389ac9d2cdbc2762abfdf3 to your computer and use it in GitHub Desktop.
<?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