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

Source for file Validator.php

Documentation is available at Validator.php

  1. <?php
  2.  
  3. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  4.  
  5. /*
  6.  * Created on 10. Feb. 2007 by Norman Markgraf (nmarkgraf(at)user.sourceforge.net)
  7.  */
  8.  
  9. /**
  10.  * Validator class file.
  11.  * 
  12.  * This class will have several static methods to check if a input string is of
  13.  * a certain format.
  14.  * 
  15.  * PHP Version 5
  16.  *  
  17.  * LICENSE:
  18.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29.  *
  30.  * This software consists of voluntary contributions made by many individuals
  31.  * and is licensed under the GPL. For more information please see
  32.  * <http://opendocumentphp.org>.
  33.  * 
  34.  * $Id: Validator.php 260 2007-08-03 13:42:29Z nmarkgraf $
  35.  * 
  36.  * @category    File Formats
  37.  * @package        OpenDocumentPHP
  38.  * @subpackage  util
  39.  * @author         Norman Markgraf (nmarkgraf(at)user.sourceforge.net)
  40.  * @copyright     Copyright in 2006, 2007 by The OpenDocumentPHP Team
  41.  * @license     http://www.gnu.org/licenses/gpl.html GNU General Public License 2.0.
  42.  * @version        SVN: $Id: Validator.php 260 2007-08-03 13:42:29Z nmarkgraf $
  43.  * @link           http://opendocumentphp.org
  44.  * @link        http://www.oasis-open.org/committees/download.php/20493/UCR.pdf OpenDocument Metadata Use Cases and Requirements
  45.  * @since         0.5.1 - 10. Feb. 2007
  46.  */
  47.  
  48.  
  49. /**
  50.  * Validator class.
  51.  * 
  52.  * This class will have several static methods to check if a input string is of
  53.  * a certain format.
  54.  * 
  55.  * Most of the definition is reight out of the original RelaxNG schemata for
  56.  * OpenDocuments.
  57.  * 
  58.  * We use Regular Expression Functions (Perl-Compatible) aka <i>PCRE</i> in this Validator
  59.  * class. Beginning with PHP 4.2.0 these functions are enabled by default. You can disable
  60.  * the PCRE functions with --without-pcre-regex. Use  --with-pcre-regex=DIR to specify DIR
  61.  * where PCRE's include and library files are located, if not using bundled library.
  62.  * For older versions you have to configure and compile PHP with --with-pcre-regex[=DIR]
  63.  * in order to use these functions.
  64.  * 
  65.  * The windows version of PHP has built in support for this extension. You do not need to
  66.  * load any additional extension in order to use these functions.
  67.  * 
  68.  * @category    File Formats
  69.  * @package        OpenDocumentPHP
  70.  * @subpackage  util
  71.  * @author         Norman Markgraf (nmarkgraf(at)user.sourceforge.net)
  72.  * @copyright     Copyright in 2006, 2007 by OpenDocumentPHP Team
  73.  * @license     http://www.gnu.org/licenses/gpl.html GNU General Public License 2.0.
  74.  * @version     Release: @package_version@
  75.  * @link           http://opendocumentphp.org
  76.  * @since         0.5.1 - 10. Feb. 2007
  77.  */
  78. class Validator {
  79.     /**
  80.      * Checks if the input is a positive integer (input > 0).
  81.      * 
  82.      * @param         mixed $input Input which is been testet.
  83.      * @return         bool Is true, only if it is a positive integer.
  84.      * @access        public
  85.      * @since        0.5.1 - 10. Feb. 2007
  86.      */
  87.     static public function isPositiveInteger($input
  88.     {
  89.         return ((int) $input 0);
  90.     }
  91.     
  92.     /**
  93.      * Checks if the input is a integer.
  94.      * 
  95.      * @param         mixed $input Input which is been testet.
  96.      * @return         bool Is true, only if it is a positive integer.
  97.      * @access        public
  98.      * @since        0.5.1 - 10. Feb. 2007
  99.      */
  100.     static public function isInteger($input
  101.     {
  102.         $ret false;
  103.         if (isset ($input)) {
  104.             $ret is_int($input);
  105.         }
  106.         return $ret;
  107.     }
  108.     
  109.     /**
  110.      * Checks if the input string is 'non-colonized name' (NCName).
  111.      * 
  112.      * @param        mixed $input Input which is been tested.
  113.      * @return        bool Is true, only if $input is a non-colonized name.
  114.      * @access        public
  115.      * @since        0.5.1 - 10. Feb. 2007
  116.      */
  117.     static public function checkNCName($input
  118.     {
  119.                 
  120.         if (is_string($input&&
  121.             preg_match('/^([a-zA-z_])(([a-zA-Z0-9]|-|_|\.)*)$/'$input)) {
  122.             return true;
  123.         else {
  124.             return false;
  125.         }
  126.     }
  127.     
  128.     /**
  129.      * Checks if the input string is of "styleNameRef" type. Which is eigther
  130.      * a NCName string or empty.
  131.      * 
  132.      * @param        mixed $input Input which is been tested.
  133.      * @return        bool Is true, only if $input is of "styleNameRef" type.
  134.      * @access        public
  135.      * @since        0.5.1 - 10. Feb. 2007
  136.      */
  137.     static public function checkStyleNameRef($input
  138.     {
  139.         if (isset ($input)) {
  140.             return Validator::checkNCName($input);
  141.         else {
  142.             // Empty is okay!
  143.             return true;
  144.         }
  145.     }
  146.     
  147.     /**
  148.      * Checks if the input string represents a color, like #00FF00 is green.
  149.      * 
  150.      * @access        public
  151.      * @since        0.5.1 - 10. Feb. 2007
  152.      */
  153.     static public function isColor($input
  154.     {
  155.         if (is_string($input&&
  156.             preg_match('/^#[0-9a-fA-F]{6}$/'$input)) {
  157.             return true;             
  158.         else {
  159.             return false;                         
  160.         }
  161.     }
  162.     
  163.     /**
  164.      * Checks if the input is a positiveLength.
  165.      * 
  166.      * @access        public
  167.      * @since        0.5.1 - 10. Feb. 2007
  168.      */
  169.     static public function isPositiveLength($input
  170.     {
  171.         if (is_string($input&&
  172.             preg_match('/^([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)) {
  173.             return true;
  174.         else {
  175.             return false;
  176.         }
  177.     }
  178.     
  179.     /**
  180.      * Checks if the input is a family value.
  181.      * 
  182.      * @access        public
  183.      * @since        0.5.2 - 19. Mar. 2007
  184.      */
  185.     static public function checkFamilyValues($value
  186.     {
  187.         $ret false;
  188.         switch ($value{
  189.             case 'ruby' :
  190.             case 'control' :
  191.             case 'presentation' :
  192.             case 'drawing-page' :
  193.             case 'default' :
  194.             case 'chart' :
  195.             case 'table-page' :
  196.             case 'table-cell' :
  197.             case 'table-row' :
  198.             case 'table-column' :
  199.             case 'section' :
  200.             case 'text' :
  201.             case 'table' :
  202.             case 'paragraph' :
  203.             case 'graphic' :
  204.                 $ret true;
  205.         }
  206.         return $ret;
  207.     }
  208. }
  209. ?>

Documentation generated on Wed, 18 Jun 2008 06:34:19 +0200 by phpDocumentor 1.3.2