Skip to content

Instantly share code, notes, and snippets.

@alganet
Created March 9, 2011 16:05
Show Gist options
  • Save alganet/862460 to your computer and use it in GitHub Desktop.
Save alganet/862460 to your computer and use it in GitHub Desktop.
Exemplo de integração do Respect com Zend 1.x usando closures
<?php
use Respect\Validation\Validator as v;
//Enclosurer
function zv($name, $arguments) {
$name = ucfirst($name);
$validatorName = "Zend_Validate_$name";
$validator = new $validatorName($arguments);
return new v::callback(function($input) use ($validator) {
return $validator->isValid($input);
});
}
//Exemplo. Valida um IP usando o Respect OU um hostname usando Zend 1.x
$result = v::oneOf(
v::ip(),
zv('hostname')
)->validate($value);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment