OpenDocumentPHP
[ class tree: OpenDocumentPHP ] [ index: OpenDocumentPHP ] [ all elements ]

Source for file Validator.php

Documentation is available at Validator.php

  1. <?php
  2. /*
  3.  * Created on 10.02.2007 by Norman Markgraf (nmarkgraf(at)user.sourceforge.net)
  4.  *
  5.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16.  *
  17.  * This software consists of voluntary contributions made by many individuals
  18.  * and is licensed under the GPL. For more information please see
  19.  * <http://opendocumentphp.org>.
  20.  * 
  21.  * $Id: Validator.php 161 2007-03-19 09:35:16Z nmarkgraf $
  22.  */
  23. /**
  24.  * Validator class.
  25.  * 
  26.  * This class will have several static methods to check if a input string is of
  27.  * a certain format.
  28.  * 
  29.  * Most of the definition is reight out of the original RelaxNG schemata for
  30.  * OpenDocuments.
  31.  * 
  32.  * @author         Norman Markgraf (nmarkgraf(at)user.sourceforge.net)
  33.  * @copyright     Copyright in 2006, 2007 by OpenDocumentPHP Team
  34.  * @license     http://www.gnu.org/licenses/gpl.html GNU General Public License 2.0.
  35.  * @version        $Revision: 161 $
  36.  * @package        OpenDocumentPHP
  37.  * @subpackage  util
  38.  * @since         0.5.1 - 10.02.2007
  39.  */
  40. class Validator {
  41.     /**
  42.      * Checks if the input is a positive integer (input > 0).
  43.      * 
  44.      * @param         mixed $input Input which is been testet.
  45.      * @return         bool Is true, only if it is a positive integer.
  46.      * @access        public
  47.      * @since        0.5.1 - 10.02.2007
  48.      */
  49.     static public function isPositiveInteger($input{
  50.         return ((int) $input 0);
  51.     }
  52.     /**
  53.      * Checks if the input is a integer.
  54.      * 
  55.      * @param         mixed $input Input which is been testet.
  56.      * @return         bool Is true, only if it is a positive integer.
  57.      * @access        public
  58.      * @since        0.5.1 - 10.02.2007
  59.      */
  60.     static public function isInteger($input{
  61.         $ret false;
  62.         if (isset ($input)) {
  63.             $ret is_int($input);
  64.         }
  65.         return $ret;
  66.     }
  67.     /**
  68.      * Checks if the input string is 'non-colonized name' (NCName).
  69.      * 
  70.      * @param        mixed $input Input which is been tested.
  71.      * @return        bool Is true, only if $input is a non-colonized name.
  72.      * @access        public
  73.      * @since        0.5.1 - 10.02.2007
  74.      * @todo        This should be something like '([a-zA-Z_])(a-zA-Z0-9.-_)*'...?
  75.      */
  76.     static public function checkNCName($input{
  77.         return true;
  78.         /*
  79.         return ereg('([a-zA-z_])(a-zA-Z0-9\.-_)',$input); [\i-[:]][\c-[:]]*
  80.         */
  81.     }
  82.     /**
  83.      * Checks if the input string is of "styleNameRef" type. Which is eigther
  84.      * a NCName string or empty.
  85.      * 
  86.      * @param        mixed $input Input which is been tested.
  87.      * @return        bool Is true, only if $input is of "styleNameRef" type.
  88.      * @access        public
  89.      * @since        0.5.1 - 10.02.2007
  90.      */
  91.     static public function checkStyleNameRef($input{
  92.         if (isset ($input)) {
  93.             return checkNCName($input);
  94.         else {
  95.             // Empty is okay!
  96.             return true;
  97.         }
  98.     }
  99.     /**
  100.      * Checks if the input string represents a color, like #00FF00 is green.
  101.      * 
  102.      * @access        public
  103.      * @since        0.5.1 - 10.02.2007
  104.      */
  105.     static public function isColor($input{
  106.         return ereg('#[0-9a-fA-F]{6}'$input);
  107.     }
  108.     /**
  109.      * Checks if the input is a positiveLength.
  110.      * 
  111.      * @access        public
  112.      * @since        0.5.1 - 10.02.2007
  113.      */
  114.     static public function isPositiveLength($input{
  115.         return ereg('([0-9]*[1-9][0-9]*(\.[0-9]*)?|0+\.[0-9]*[1-9][0-9]*|\.[0-9]*[1-9][0-9]*)((cm)|(mm)|(in)|(pt)|(pc)|(px))'$input);
  116.     }
  117.     /**
  118.      * Checks if the input is a family value.
  119.      * 
  120.      * @access        public
  121.      * @since        0.5.2 - 19.03.2007
  122.      */
  123.     static public function checkFamilyValues($value{
  124.         $ret false;
  125.         switch ($value{
  126.             case 'ruby' :
  127.             case 'control' :
  128.             case 'presentation' :
  129.             case 'drawing-page' :
  130.             case 'default' :
  131.             case 'chart' :
  132.             case 'table-page' :
  133.             case 'table-cell' :
  134.             case 'table-row' :
  135.             case 'table-column' :
  136.             case 'section' :
  137.             case 'text' :
  138.             case 'table' :
  139.             case 'paragraph' :
  140.             case 'graphic' :
  141.                 $ret true;
  142.         }
  143.         return $ret;
  144.     }
  145. }
  146. ?>

Documentation generated on Tue, 12 Jun 2007 10:01:07 +0200 by phpDocumentor 1.3.2