Skip to content

Instantly share code, notes, and snippets.

@filhodanuvem
Created January 31, 2012 00:32
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 filhodanuvem/1707824 to your computer and use it in GitHub Desktop.
Save filhodanuvem/1707824 to your computer and use it in GitHub Desktop.
Testando se uma regra existe no Respect\Validation
<?php
// A ideia é descobrir se a regra existe
// ex: $p['validate'] == 'image'
// Usei a SplClassLoader para carregar o Respect, porém, acho que na hora da biblioteca instanciar uma
// regra via Reflection, o autoload dá require num arquivo que nao existe, gerando um erro fatal
// ou seja, que não é capturado pelo try...catch.
use Respect\Validation as v;
$validator = new v\Validator();
try{
$validator = $validator->buildRule($p['validate']);
}catch(Exception $e){
// ação específica.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment