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

   1  <?php
   2  //
   3  // Definition of eZInputValidator class
   4  //
   5  // Created on: <08-Jul-2002 16:01:35 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 ezinputvalidator.php
  30  */
  31  
  32  /*!
  33    \class eZInputValidator ezinputvalidator.php
  34    \brief Input text validation and correction
  35  
  36    This is the base class for doing validation of input text and eventually correction.
  37    The general eZRegExpValidator can be used for most validations by supplying it with
  38    a regexp rule set, for more advanced validation you can use the eZIntegerValidator
  39    which can validate integers withing ranges.
  40  
  41    For creating your own validators you can either inherit this class or any of the
  42    advanced classes. The inherited class must implement the validate() function for
  43    validation and fixup() for fixing text to be acceptable.
  44  
  45    A validation will return a state which can either be Accepted, Intermediate or Invalid.
  46    Accepted means that the text can be used without modification, Invalid means that the
  47    text cannot be used at any cost while Intermediate means that the text can be used
  48    if it's fixed with the fixup() function.
  49  
  50    Example of a simple integer validator
  51  \code
  52  class IntegerValidator
  53  {
  54      function IntegerValidator()
  55      {
  56      }
  57  
  58      function validate( $text )
  59      {
  60          return is_numeric( $text ) ? EZ_INPUT_VALIDATOR_STATE_ACCEPTED : EZ_INPUT_VALIDATOR_STATE_INVALID;
  61      }
  62  
  63      function fixup( &$text )
  64      {
  65      }
  66  }
  67  \endcode
  68  
  69    Example of a boolean validator
  70  \code
  71  class BooleanValidator
  72  {
  73      function BooleanValidator()
  74      {
  75      }
  76  
  77      function validate( $text )
  78      {
  79          if ( strtolower( $text ) == "true" or
  80               strtolower( $text ) == "false" )
  81              return EZ_INPUT_VALIDATOR_STATE_ACCEPTED;
  82          if ( is_numeric( $text ) )
  83              return EZ_INPUT_VALIDATOR_STATE_INTERMEDIATE;
  84          return EZ_INPUT_VALIDATOR_STATE_INVALID;
  85      }
  86  
  87      function fixup( &$text )
  88      {
  89          $text = ( $text == 0 ? "false" : "true" );
  90      }
  91  }
  92  \endcode
  93  
  94  
  95  
  96  */
  97  
  98  define( "EZ_INPUT_VALIDATOR_STATE_ACCEPTED", 1 );
  99  define( "EZ_INPUT_VALIDATOR_STATE_INTERMEDIATE", 2 );
 100  define( "EZ_INPUT_VALIDATOR_STATE_INVALID", 3 );
 101  
 102  class eZInputValidator
 103  {
 104      /*!
 105       Default constructor, does nothing.
 106      */
 107      function eZInputValidator()
 108      {
 109      }
 110  
 111      /*!
 112       Tries to validate to the text \a $text and returns one of the validator states
 113       EZ_INPUT_VALIDATOR_STATE_ACCEPTED, EZ_INPUT_VALIDATOR_STATE_INTERMEDIATE or
 114       EZ_INPUT_VALIDATOR_STATE_INVALID.
 115       This returns EZ_INPUT_VALIDATOR_STATE_ACCEPTED as default and must be reimplemented
 116       in real valiators.
 117      */
 118      function validate( $text )
 119      {
 120          return EZ_INPUT_VALIDATOR_STATE_ACCEPTED;
 121      }
 122  
 123      /*!
 124       Tries to fix the text \a $text which was previously marked as EZ_INPUT_VALIDATOR_STATE_INTERMEDIATE
 125       so that it can be seen as EZ_INPUT_VALIDATOR_STATE_ACCEPTED.
 126      */
 127      function fixup( &$text )
 128      {
 129      }
 130  }
 131  
 132  ?>


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