Overview

Packages

  • Auth
  • Config
  • Controller
  • Date
  • Db
  • Feed
    • Abstract
    • Writers
  • File
    • Decorator
  • Form
    • Element
  • Image
  • Log
    • Writer
  • Net
    • Exception
  • None
  • PHP
  • PHPMailer
  • Session
  • Util
  • Validate
    • Validator
  • Zend
    • Registry

Classes

  • Validate_Abstract
  • Validate_Validate
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Pry Framework
  4:  *
  5:  * LICENSE
  6:  *
  7:  * This source file is subject to the new BSD license that is bundled
  8:  * with this package in the file LICENSE.txt.
  9:  * 
 10:  * @version $Revision: 276 $
 11:  */
 12: 
 13: /**
 14:  * Factory de validateur
 15:  * @category Pry
 16:  * @package Validate
 17:  * @version 1.1.0 
 18:  * @author Olivier ROGER <oroger.fr>
 19:  */
 20: class Validate_Validate
 21: {
 22:     /**
 23:      * Validateurs instanciés
 24:      *
 25:      * @var array
 26:      * @access private
 27:      */
 28:     private $validators;
 29:     
 30:     /**
 31:      * Constructeur
 32:      *
 33:      */
 34:     public function __construct()
 35:     {
 36:         $this->validators = array();
 37:     }
 38:     
 39:     /**
 40:      * Ajoute un nouveau validateur
 41:      *
 42:      * @param string $nom Nom du validateur
 43:      * @param array $options Option possible pour le validateur
 44:      * @param string $message Message d'erreur personalisé
 45:      * @access public
 46:      * @return Validate_Validate
 47:      */
 48:     public function addValidator($nom,$options=null,$message='')
 49:     {
 50:         if($this->validatorExist($nom))
 51:         {
 52:             $class = 'Validate_Validator_'.$nom;
 53:             if(is_null($options))
 54:                 $objet = new $class();
 55:             else
 56:                 $objet = new $class($options);
 57:                 
 58:             if($message!='')
 59:             {
 60:                 $objet->setMessage($message);
 61:             }
 62:             $this->validators[] = $objet;
 63:             unset($objet);  
 64:         }
 65:         else
 66:             throw new InvalidArgumentException('Validateur inconnu');
 67:         return $this;
 68:     }
 69:     
 70:     /**
 71:      * Validation de la valeur avec les différents validateurs
 72:      *
 73:      * @param string $value
 74:      * @access public
 75:      * @return mixed Retourne true si valide, message d'erreur sinon
 76:      */
 77:     public function isValid($value)
 78:     {
 79:         foreach($this->validators as $validator)
 80:         {
 81:             if(!$validator->isValid($value))
 82:             {
 83:                 return $validator->getError();
 84:             }
 85:                 
 86:         }
 87:         return true;
 88:     }
 89:     
 90:     /**
 91:      * Vérifie l'existance du validateur
 92:      *
 93:      * @param string $nom
 94:      * @return boolean
 95:      */
 96:     private function validatorExist($nom)
 97:     {
 98:         return file_exists(dirname(__FILE__).'/Validator/'.$nom.'.class.php');
 99:     }
100: }
101:  ?>
Pry Framework API documentation generated by ApiGen 2.6.1