[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/ezutils/classes/ -> ezintegervalidator.php (source)

   1  <?php
   2  //
   3  // Definition of eZIntegerValidator class
   4  //
   5  // Created on: <08-Jul-2002 17:15:51 amos>
   6  //
   7  // SOFTWARE NAME: eZ publish
   8  // SOFTWARE RELEASE: 3.9.0
   9  // BUILD VERSION: 17785
  10  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
  11  // SOFTWARE LICENSE: GNU General Public License v2.0
  12  // NOTICE: >
  13  //   This program is free software; you can redistribute it and/or
  14  //   modify it under the terms of version 2.0  of the GNU General
  15  //   Public License as published by the Free Software Foundation.
  16  //
  17  //   This program is distributed in the hope that it will be useful,
  18  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  19  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20  //   GNU General Public License for more details.
  21  //
  22  //   You should have received a copy of version 2.0 of the GNU General
  23  //   Public License along with this program; if not, write to the Free
  24  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  25  //   MA 02110-1301, USA.
  26  //
  27  //
  28  
  29  /*! \file ezintegervalidator.php
  30  */
  31  
  32  /*!
  33    \class eZIntegerValidator ezintegervalidator.php
  34    \brief The class eZIntegerValidator does
  35  
  36  */
  37  
  38  include_once ( "lib/ezutils/classes/ezregexpvalidator.php" );
  39  
  40  class eZIntegerValidator extends eZRegExpValidator
  41  {
  42      /*!
  43       Constructor
  44      */
  45      function eZIntegerValidator( $min = false, $max = false )
  46      {
  47          $rule = array( "accepted" => "/^-?[0-9]+$/",
  48                         "intermediate" => "/(-?[0-9]+)/",
  49                         "fixup" => "" );
  50          $this->eZRegExpValidator( $rule );
  51          $this->MinValue = $min;
  52          $this->MaxValue = $max;
  53          if ( $max !== false and $min !== false )
  54              $this->MaxValue = max( $min, $max );
  55      }
  56  
  57      function setRange( $min, $max )
  58      {
  59          $this->MinValue = $min;
  60          $this->MaxValue = $max;
  61          if ( $max !== false and $min !== false )
  62              $this->MaxValue = max( $min, $max );
  63      }
  64  
  65      function validate( $text )
  66      {
  67          $state = eZRegExpValidator::validate( $text );
  68          if ( $state == EZ_INPUT_VALIDATOR_STATE_ACCEPTED )
  69          {
  70              if ( ( $this->MinValue !== false and $text < $this->MinValue ) or
  71                   ( $this->MaxValue !== false and $text > $this->MaxValue ) )
  72                  $state = EZ_INPUT_VALIDATOR_STATE_INTERMEDIATE;
  73          }
  74          return $state;
  75      }
  76  
  77      function &fixup( $text )
  78      {
  79          if ( preg_match( $this->RegExpRule["intermediate"], $text, $regs ) )
  80              $text = $regs[1];
  81          if ( $this->MinValue !== false and $text < $this->MinValue )
  82              $text = $this->MinValue;
  83          else if ( $this->MaxValue !== false and $text > $this->MaxValue )
  84              $text = $this->MaxValue;
  85          return $text;
  86      }
  87  
  88      /// \privatesection
  89      var $MinValue;
  90      var $MaxValue;
  91  }
  92  
  93  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7