[ Index ]
 

Code source de LifeType 1.2.4

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/class/data/validator/rules/ -> rule.class.php (source)

   1  <?php
   2  
   3      lt_include( PLOG_CLASS_PATH."class/data/validator/validation.class.php");
   4  
   5      /**
   6       * \defgroup Validator_Rules
   7       *
   8       * The main classes that implement the Strategy pattern as described here
   9       * http://www.phppatterns.com/index.php/article/articleview/13/1/1/ are the classes
  10       * that extend the Validator interface. 
  11       *
  12       * But at a deeper level, a Validator class is nothing else than a collection of rules,
  13       * or classes that extend the Rule interface. Implementing Validator classes as a collection
  14       * of Rule classes allows for better code reusability, since sometimes most of the Validator
  15       * classes check for similar things and therefore we can reuse most of the Rule classes.
  16       *
  17       * In order to implement your own rule, simply create your own class extending the Rule 
  18       * class and make sure to implement the Rule::Validate() method with your own validation logic. This
  19       * method should return 'true' if the data complies with the logic of the rule or 'false' if it does
  20       * not. Additionally, since Rule extends the Validation interface it is also possible to set
  21       * certain error flags or messages via the private method Validation::_setError(). These error
  22       * codes can be checked by Validator classes or by users of this class via the Validation::getError()
  23       * method.
  24       *
  25       * See the documentation of the Validator base class on how to use Rule classes in your own validators.
  26       * @see Validator
  27       */
  28       
  29      /**
  30       * \ingroup Validator_Rules
  31       *
  32       * This is the main base class that all custom Rule classes should extend. Please implement the
  33       * Rule::validate() with your own logic and return 'true' if the validation was successful or 
  34       * 'false' otherwise. Please use Validation::_setError() to set additional error codes reporting
  35       * more information.
  36       */
  37      class Rule extends Validation
  38      {
  39          /**
  40           * The constructor does nothing.
  41           */
  42          function Rule()
  43          {
  44              $this->Validation();
  45          }
  46  
  47          /**
  48           * Validates the data. Does nothing here and it must be reimplemented by
  49           * every child class.
  50           *
  51           * @param value The value that we're going to validate
  52           * @return True if successful or false otheriwse
  53           */
  54          function validate($value)
  55          {
  56              throw(new Exception("Rule::validate: This method must be implemented by child classes."));
  57              die();
  58          }
  59      }
  60  ?>


Généré le : Mon Nov 26 21:04:15 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics