[ 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/ -> stringrangerule.class.php (source)

   1  <?php
   2  
   3      lt_include( PLOG_CLASS_PATH."class/data/validator/rules/rule.class.php");
   4  
   5      define( "ERROR_RULE_STRING_TOO_SMALL", "error_rule_string_too_small");
   6      define( "ERROR_RULE_STRING_TOO_LARGE", "error_rule_string_too_large");
   7  
   8      /**
   9       * \ingroup Validator_Rules
  10       *
  11       * Given two values that will be used as lower and upper boundaries of the string length, 
  12       * validates if the length of the given string is between the limits.
  13       *
  14       * It will set the errors ERROR_RULE_STRING_TOO_SMALL or ERROR_RULE_STRING_TOO_LARGE in case the
  15       * validation is not successful.
  16       */
  17      class StringRangeRule extends Rule
  18      {
  19          var $_minValue;
  20          var $_maxValue;
  21  
  22          /**
  23           * Initializes the rule
  24           *
  25           * @param minValue the lower boundary of the range
  26           * @param maxValue the upper boundary of the range
  27           */
  28          function StringRangeRule($minValue, $maxValue)
  29          {
  30              $this->Rule();
  31  
  32              $this->_minValue = $minValue;
  33              $this->_maxValue = $maxValue;
  34          }
  35  
  36          /**
  37           * @return the lower boundary of the range
  38           */
  39          function getMinValue()
  40          {
  41              return $this->_minValue;
  42          }
  43  
  44          /**
  45           * sets the lower boundary of the range
  46           *
  47           * @param minValue the minimum value
  48           */
  49          function setMinValue($minValue)
  50          {
  51              $this->_minValue = $minValue;
  52          }
  53  
  54          /**
  55           * @return the upper boundary of the range
  56           */
  57          function getMaxValue()
  58          {
  59              return $this->_maxValue;
  60          }
  61  
  62          /**
  63           * sets the lower boundary of the range
  64           *
  65           * @param minValue the minimum value
  66           */
  67          function setMaxValue($maxValue)
  68          {
  69              $this->_maxValue = $maxValue;
  70          }
  71  
  72          /**
  73           * validates that the given value is within the two boundaries previously specified
  74           *
  75           * @param value The value to validate
  76           * @return True if successful or false otherwise
  77           */
  78          function validate($value)
  79          {
  80              $len = strlen($value);
  81  
  82              if ($len < $this->_minValue)
  83              {
  84                  $this->_setError(ERROR_RULE_STRING_TOO_SMALL);
  85                  return false;
  86              }
  87              else if ($this->_maxValue != 0 && $len > $this->_maxValue)
  88              {
  89                  $this->_setError(ERROR_RULE_STRING_TOO_LARGE);
  90                  return false;
  91              }
  92              else
  93              {
  94                  $this->_setError(false);
  95                  return true;
  96              }
  97          }
  98      }
  99  ?>


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