Source for file Valid.class.php

Documentation is available at Valid.class.php

  1. <?php
  2. /**
  3.  * Gumbo Library Framework
  4.  *
  5.  * LICENSE
  6.  * This library is being released under the terms of the New BSD License.  A
  7.  * copy of the license is packaged with the software (LICENSE.txt).  If no
  8.  * copy is found, a copy of the license template can be found at:
  9.  * http://www.opensource.org/licenses/bsd-license.php
  10.  * 
  11.  * @category Gumbo
  12.  * @package Valid
  13.  * @copyright Copyright (c) 2007, iBayou, Michael Luster
  14.  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  15.  * @author Michael Luster <mluster79@yahoo.com>
  16.  * @link http://sourceforge.net/projects/phpgumbo
  17.  * @version 0.0.1
  18.  */
  19.  
  20. /**
  21.  * Validation Class
  22.  * 
  23.  * The Validation class is responsible for performing basic Validation on
  24.  * data.  The methods supplied are generic and commonly used.  The class
  25.  * defines a default implementation for the Interface.  It also provides an
  26.  * additional feature for turning Exceptions On, temporarily.  This is
  27.  * performed by child Validation classes.
  28.  * 
  29.  * All Validation Exceptions are not caught internally.  Any class or code
  30.  * that is performing Validation should catch any Exceptions.  To check if
  31.  * the parent is throwing Exceptions, simply implement a Validation method
  32.  * as follows.
  33.  * 
  34.  * 1. Define a boolean variable as false: 'passed'
  35.  * 2. Perform any checks against the data, setting 'passed' to true on success
  36.  * 3. Check if parent is throwing Exceptions, throw Exception
  37.  * 4. Return 'passed'
  38.  * 
  39.  * <pre>
  40.  * $passed = false;
  41.  * // perform check on data
  42.  * ...
  43.  * if (!$passed && $this->isThrowing ()) {
  44.  *     throw new Gumbo_Exception ("Validation Failed: <some message>", $this->getLevel());
  45.  * }
  46.  * return $passed;
  47.  * </pre>
  48.  * 
  49.  * A Validation class should extend this class.  It already has the defined
  50.  * implementation for Validation features, and provides easy access to generic
  51.  * methods.  The child Validation class would define the type of data it will
  52.  * validate.  For example, Valid_Address will validate address information.
  53.  * The methods it defined narrow down parts of the Address.
  54.  * 
  55.  * The On/Off feature comes in handy for child classes.  This assists the class
  56.  * for ensuring that Exceptions are thrown based on the parent setting.  To
  57.  * implement, simply turn on Exceptions, catch any failures, and turn off
  58.  * Exceptions.  The next step determines if the primary Exception should be
  59.  * thrown.
  60.  * <pre>
  61.  * public function isName ($val) {
  62.  *     $passed = false;
  63.  * 
  64.  *     $this->turnOn ();
  65.  *     try {
  66.  *         // verify precondition
  67.  *         $this->isString ($val);
  68.  *         $this->isLessThanEqualTo ($val, 150);
  69.  *         $this->isMatch ($val, "^([A-Za-z0-9[:space:]\.,_-]){0,}$");
  70.  *         $passed = true;
  71.  *     } catch (Exception $e) {
  72.  *         unset ($e);
  73.  *     }
  74.  *     $this->turnOff ();
  75.  *     
  76.  *     if (!$passed && $this->isThrowing ()) {
  77.  *         throw new Gumbo_Exception ("Validation Failed: Name", $this->getLevel ());
  78.  *     }
  79.  *     return $passed;
  80.  * }
  81.  * </pre>
  82.  * 
  83.  * Here's how it works.  First, turn on Exceptions.  This means that any Exceptions
  84.  * thrown will be caught inside the 'try...catch' block.  The block will perform
  85.  * various Validation methods on the data, setting 'passed' to true if no Exceptions
  86.  * were thrown.  Any caught Exception will be discarded.  Turn off Exceptions, and
  87.  * check if the Validator object is throwing Exceptions.
  88.  *
  89.  * @category Gumbo
  90.  * @package Valid
  91.  * @copyright Copyright (c) 2007, iBayou, Michael Luster
  92.  * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
  93.  * @author Michael Luster <mluster79@yahoo.com>
  94.  * @link http://sourceforge.net/projects/phpgumbo
  95.  * @desc Validation Class
  96.  * @version 0.0.1
  97.  */
  98.  
  99. gumbo_load ("Interface_Valid");
  100.  
  101. class Gumbo_Valid implements Gumbo_Interface_Valid {
  102.     
  103.     /** @var bool $_throw indicates if the class should throw Exceptions */
  104.     private $_throw = false;
  105.     /** @var bool $_on if throwing Exceptions is temporarily on */
  106.     private $_on = false;
  107.     /** @var int $_level Error Level for any thrown Exceptions */
  108.     private $_level = ERROR_DEBUG;
  109.     
  110.     
  111.     
  112.     /**
  113.      * Constructor
  114.      * @param bool $throw throw Exceptions
  115.      * @param int $level Error Level thrown
  116.      */
  117.     public function __construct ($throw=false$level=null{
  118.         $this->setThrow ($throw);
  119.         if (!is_null ($level)) $this->setLevel ($level)}
  120.     }
  121.     
  122.     
  123.     
  124.     /** ACTION METHODS **/
  125.     /**
  126.      * Turns throwing Exceptions ON (temporarily)
  127.      * @postcondition isOn()
  128.      */
  129.     protected function turnOn ({
  130.         $this->_on = true;
  131.     }
  132.     
  133.     /**
  134.      * Turns throwing Exception OFF
  135.      * @postcondition !isOn()
  136.      */
  137.     protected function turnOff ({
  138.         $this->_on = false;
  139.     }
  140.     
  141.     
  142.     
  143.     /** MUTATOR METHODS **/
  144.     /**
  145.      * Sets if the class should throw Exceptions
  146.      * @param bool $yes 
  147.      * @throws Gumbo_Exception
  148.      */
  149.     public function setThrow ($yes{
  150.         try {
  151.             if (!is_bool ($yes)) {
  152.                 throw new Gumbo_Exception ("Invalid Argument 'yes:bool' => {$yes}:gettype ($yes));
  153.             }
  154.             
  155.             $this->_throw = $yes;
  156.         catch (Gumbo_Exception $e{
  157.             $e->setFunction (__METHOD__);
  158.             gumbo_trigger ($e);
  159.         }
  160.     }
  161.     
  162.     /**
  163.      * Sets the Error Level
  164.      * @param int $level 
  165.      * @throws Gumbo_Exception
  166.      */
  167.     public function setLevel ($level{
  168.         try {
  169.             // verify precondition
  170.             if (!is_numeric ($level)) {
  171.                 throw new Gumbo_Exception ("Invalid Argument 'level:int' => {$level}:gettype ($level));
  172.             }
  173.             $level = (int) $level;
  174.             
  175.             switch ($level{
  176.                 case ERROR_DEBUG break;
  177.                 case ERROR_NOTICE break;
  178.                 case ERROR_WARNING break;
  179.                 case ERROR_ERROR break;
  180.                 case ERROR_CRITICAL break;
  181.                 case ERROR_ALERT break;
  182.                 case ERROR_EMERGENCY break;
  183.                 default : throw new Gumbo_Exception ("Invalid ERROR_Level: {$level}");
  184.             }
  185.             
  186.             $this->_level = $level;
  187.         catch (Gumbo_Exception $e{
  188.             $e->setFunction (__METHOD__);
  189.             gumbo_trigger ($e);
  190.         }
  191.     }
  192.     
  193.     
  194.     
  195.     /** ACCESSOR METHODS **/
  196.     /**
  197.      * Returns if Exceptions should be thrown from this class
  198.      * @return bool 
  199.      */
  200.     public function isThrowing ({
  201.         if (!$this->_throw{
  202.             return $this->isOn ();
  203.         }
  204.         return true;
  205.     }
  206.     
  207.     /**
  208.      * Returns if Exceptions was turned on (temporarily)
  209.      * @return bool 
  210.      */
  211.     protected function isOn ({
  212.         return $this->_on;
  213.     }
  214.     
  215.     /**
  216.      * Returns the Error Level for Exceptions thrown by the class
  217.      * @return int 
  218.      */
  219.     public function getLevel ({
  220.         return $this->_level;
  221.     }
  222.     
  223.     
  224.     
  225.     
  226.     
  227.     /**
  228.      * Returns if the value is one of the preconditions
  229.      * 
  230.      * The method will require additional arguments, each with a different
  231.      * data type (as strings).  The method will then check to see if the
  232.      * value is either of the types.  For example, if a value can be a string
  233.      * or an array, simply:
  234.      * Gumbo_Valid::precondition ($val, "str", "arr");
  235.      * 
  236.      * The following are the strings to reference types:
  237.      * - 'bool' => boolean
  238.      * - 'int' => integer
  239.      * - 'num' => numeric, float, double
  240.      * - 'str' => string
  241.      * - 'arr' => array
  242.      * - 'obj' => object (any type of object)
  243.      * - 'res' => resource
  244.      * - 'null' => null
  245.      * 
  246.      * @param mixed $val 
  247.      * @return bool 
  248.      * @throws Gumbo_Exception
  249.      */
  250.     public function precondition ($val{
  251.         // if no arguments are given
  252.         if (func_num_args (<= 1return true}
  253.         
  254.         // search
  255.         $passed false;
  256.         $types "";
  257.         foreach (func_get_args (as $key=>$value{
  258.             if ($key == 0continue}
  259.             switch ($value{
  260.                 case "bool" :
  261.                     if (is_bool ($val)) $passed true}
  262.                     $types .= "bool|";
  263.                     break;
  264.                 case "int" :
  265.                     if (is_int ($val)) $passed true}
  266.                     $types .= "int|";
  267.                     break;
  268.                 case "num" :
  269.                     if (is_numeric ($val)) $passed true}
  270.                     $types .= "num|";
  271.                     break;
  272.                 case "str" :
  273.                     if (is_string ($val)) $passed true}
  274.                     $types .= "str|";
  275.                     break;
  276.                 case "arr" :
  277.                     if (is_array ($val)) $passed true}
  278.                     $types .= "arr|";
  279.                     break;
  280.                 case "obj" :
  281.                     if (is_object ($val)) $passed true}
  282.                     $types .= "obj|";
  283.                     break;
  284.                 case "res" :
  285.                     if (is_resource ($val)) $passed true}
  286.                     $types .= "res|";
  287.                     break;
  288.                 case "null" :
  289.                     if (is_null ($val)) $passed true}
  290.                     $types .= "null|";
  291.                     break;
  292.             }
  293.         }
  294.         $types substr ($types0strlen ($types1);
  295.         
  296.         if (!$passed && $this->isThrowing ()) {
  297.             throw new Gumbo_Exception ("Validation FailedPrecondition [{$types}]"$this->getLevel ());
  298.         }
  299.         return $passed;
  300.     }
  301.     
  302.     /**
  303.      * Returns if the given value is a primitive data type
  304.      * @precondition is a boolean, number, string, null
  305.      * @param mixed $val 
  306.      * @return bool 
  307.      * @throws Gumbo_Exception
  308.      */
  309.     public function isPrimitive ($val{
  310.         $passed (is_null ($val|| is_numeric ($val|| is_string ($val|| is_bool ($val));
  311.         
  312.         if (!$passed && $this->isThrowing ()) {
  313.             throw new Gumbo_Exception ("Validation Failed: Primitive Type"$this->getLevel ());
  314.         }
  315.         return $passed;
  316.     }
  317.     
  318.     /**
  319.      * Returns if the given value is an array
  320.      * @param array $val 
  321.      * @return bool 
  322.      * @throws Gumbo_Exception
  323.      */
  324.     public function isArray ($val{
  325.         $passed is_array ($val);
  326.         
  327.         if (!$passed && $this->isThrowing ()) {
  328.             throw new Gumbo_Exception ("Validation Failed: Array"$this->getLevel ());
  329.         }
  330.         return $passed;
  331.     }
  332.     
  333.     /**
  334.      * Returns if the value is a boolean
  335.      * @param bool $val 
  336.      * @return bool 
  337.      * @throws Gumbo_Exception
  338.      */
  339.     public function isBool ($val{
  340.         $passed is_bool ($val);
  341.         
  342.         if (!$passed && $this->isThrowing ()) {
  343.             throw new Gumbo_Exception ("Validation Failed: Boolean"$this->getLevel ());
  344.         }
  345.         return $passed;
  346.     }
  347.     
  348.     /**
  349.      * Returns if the value is a Float
  350.      * @param num $val 
  351.      * @return bool 
  352.      * @throws Gumbo_Exception
  353.      */
  354.     public function isFloat ($val{
  355.         $passed is_float ($val);
  356.         
  357.         if (!$passed && $this->isThrowing ()) {
  358.             throw new Gumbo_Exception ("Validation Failed: Float"$this->getLevel ());
  359.         }
  360.         return $passed;
  361.     }
  362.     
  363.     /**
  364.      * Returns if the value is a Long
  365.      * @param num $val 
  366.      * @return bool 
  367.      * @throws Gumbo_Exception
  368.      */
  369.     public function isLong ($val{
  370.         $passed is_long ($val);
  371.         
  372.         if (!$passed && $this->isThrowing ()) {
  373.             throw new Gumbo_Exception ("Validation Failed: Long"$this->getLevel ());
  374.         }
  375.         return $passed;
  376.     }
  377.     
  378.     /**
  379.      * Returns if the value is Null
  380.      * @param null $val 
  381.      * @return bool 
  382.      * @throws Gumbo_Exception
  383.      */
  384.     public function isNull ($val{
  385.         $passed is_null ($val);
  386.         
  387.         if (!$passed && $this->isThrowing ()) {
  388.             throw new Gumbo_Exception ("Validation Failed: Null"$this->getLevel ());
  389.         }
  390.         return $passed;
  391.     }
  392.     
  393.     /**
  394.      * Returns if the value is Numeric
  395.      * @param num $val 
  396.      * @return bool 
  397.      * @throws Gumbo_Exception
  398.      */
  399.     public function isNumeric ($val{
  400.         $passed is_numeric ($val);
  401.         
  402.         if (!$passed && $this->isThrowing ()) {
  403.             throw new Gumbo_Exception ("Validation Failed: Numeric"$this->getLevel ());
  404.         }
  405.         return $passed;
  406.     }
  407.     
  408.     /**
  409.      * Returns if the value is a Resource
  410.      * @param res $val 
  411.      * @return bool 
  412.      * @throws Gumbo_Exception
  413.      */
  414.     public function isResource ($val{
  415.         $passed is_resource ($val);
  416.         
  417.         if (!$passed && $this->isThrowing ()) {
  418.             throw new Gumbo_Exception ("Validation Failed: Resource"$this->getLevel ());
  419.         }
  420.         return $passed;
  421.     }
  422.     
  423.     /**
  424.      * Returns if the value is an Object
  425.      * @param StdClass $val 
  426.      * @param string $cls instance of class
  427.      * @return bool 
  428.      * @throws Gumbo_Exception
  429.      */
  430.     public function isObject ($val$cls=null{
  431.         $passed is_object ($val);
  432.         if (!is_null ($cls)) {
  433.             $passed ($val instanceof $cls);
  434.         }
  435.         
  436.         if (!$passed && $this->isThrowing ()) {
  437.             if (is_object ($cls)) $cls get_class ($cls)}
  438.             throw new Gumbo_Exception ("Validation FailedObject {$cls}"$this->getLevel ());
  439.         }
  440.         return $passed;
  441.     }
  442.     
  443.     /**
  444.      * Returns if the value is a String
  445.      * @param string $val 
  446.      * @return bool 
  447.      * @throws Gumbo_Exception
  448.      */
  449.     public function isString ($val{
  450.         $passed is_string ($val);
  451.         
  452.         if (!$passed && $this->isThrowing ()) {
  453.             throw new Gumbo_Exception ("Validation Failed: String"$this->getLevel ());
  454.         }
  455.         return $passed;
  456.     }
  457.     
  458.     /**
  459.      * Returns if the value is an Integer
  460.      * @param int $val 
  461.      * @return bool 
  462.      * @throws Gumbo_Exception
  463.      */
  464.     public function isInt ($val{
  465.         $passed is_int ($val);
  466.         
  467.         if (!$passed && $this->isThrowing ()) {
  468.             throw new Gumbo_Exception ("Validation Failed: Int"$this->getLevel ());
  469.         }
  470.         return $passed;
  471.     }
  472.     
  473.     /**
  474.      * Returns if the value is a Match to the pattern
  475.      * @param string $val 
  476.      * @param string $pattern 
  477.      * @return bool 
  478.      * @throws Gumbo_Exception
  479.      */
  480.     public function isMatch ($val$pattern="[]"{
  481.         $passed preg_match ($pattern$val);
  482.         
  483.         if (!$passed && $this->isThrowing ()) {
  484.             throw new Gumbo_Exception ("Validation Failed: Pattern Match"$this->getLevel ());
  485.         }
  486.         return $passed;
  487.     }
  488.     
  489.     
  490.     
  491.     /**
  492.      * Returns if the value is True
  493.      * 
  494.      * This method will check if the value is identical to the 'true'
  495.      * value.  The method will also check if the value is equal to
  496.      * the values of "yes" and "y".  These values are common affirmative
  497.      * values used in many programs.
  498.      * 
  499.      * @param bool $val 
  500.      * @return bool 
  501.      * @throws Gumbo_Exception
  502.      */
  503.     public function isTrue ($val{
  504.         $passed false;
  505.         if ($val === true{
  506.             $passed true;
  507.         }
  508.         if (strtolower ($val=== "yes" || strtolower ($val=== "y"{
  509.             $passed true;
  510.         }
  511.         
  512.         if (!$passed && $this->isThrowing ()) {
  513.             throw new Gumbo_Exception ("Validation Failed: Not True"$this->getLevel ());
  514.         }
  515.         return $passed;
  516.     }
  517.     
  518.     /**
  519.      * Returns if the value is False
  520.      * 
  521.      * This method will check if the value is identical to the 'false'
  522.      * value.  The method will also check if the value is equal to
  523.      * the values of "no" and "n".  These values are common negative
  524.      * values used in many programs.
  525.      * 
  526.      * @param bool $val 
  527.      * @return bool 
  528.      * @throws Gumbo_Exception
  529.      */
  530.     public function isFalse ($val{
  531.         $passed false;
  532.         if ($val === false{
  533.             $passed true;
  534.         }
  535.         if (strtolower ($val=== "no" || strtolower ($val=== "n"{
  536.             $passed true;
  537.         }
  538.         
  539.         if (!$passed && $this->isThrowing ()) {
  540.             throw new Gumbo_Exception ("Validation Failed: Not False"$this->getLevel ());
  541.         }
  542.         return $passed;
  543.     }
  544.     
  545.     
  546.     
  547.     /**
  548.      * Returns if the value is Less Than the test case
  549.      * 
  550.      * The value will check against the case value.  The value can be
  551.      * three different value types:
  552.      * 
  553.      * numeric (int,float)
  554.      * - case (numeric) : will compare values
  555.      * 
  556.      * string
  557.      * - case (int) : compare value string length to case value
  558.      * - case (string) : compare value string length to case string length
  559.      * 
  560.      * array
  561.      * - case (int) : compare value count of elements to case value
  562.      * - case (array) : compare value count of elements to case count of elements
  563.      * 
  564.      * @param mix $val 
  565.      * @param mix $case 
  566.      * @return bool 
  567.      * @throws Gumbo_Exception
  568.      */
  569.     public function isLessThan ($val$case{
  570.         $passed false;
  571.         $type null;
  572.         
  573.         // Number check
  574.         if (is_numeric ($val)) {
  575.             $type "Number";
  576.             if (is_numeric ($case)) if ($val $case$passed true} }
  577.         }
  578.         
  579.         // String length check
  580.         if (is_string ($val)) {
  581.             $type "String";
  582.             if (is_numeric ($case)) if (strlen ($val$case$passed true} }
  583.             if (is_string ($case)) if (strlen ($valstrlen ($case)) $passed true} }
  584.         }
  585.         
  586.         // Array length check
  587.         if (is_array ($val)) {
  588.             $type "Array";
  589.             if (is_numeric ($case)) if (count ($val$case$passed true} }
  590.             if (is_array ($case)) if (count ($valcount ($case)) $passed true} }
  591.         }
  592.         
  593.         if (!$passed && $this->isThrowing ()) {
  594.             throw new Gumbo_Exception ("Validation FailedNot Less Than [{$type}]"$this->getLevel ());
  595.         }
  596.         return $passed;
  597.     }
  598.     
  599.     /**
  600.      * Returns if the value is Less Than, or Equal to, the test case
  601.      * 
  602.      * The value will check against the case value.  The value can be
  603.      * three different value types:
  604.      * 
  605.      * numeric (int,float)
  606.      * - case (numeric) : will compare values
  607.      * 
  608.      * string
  609.      * - case (numeric) : compare value string length to case value
  610.      * - case (string) : compare value string length to case string length
  611.      * 
  612.      * array
  613.      * - case (numeric) : compare value count of elements to case value
  614.      * - case (array) : compare value count of elements to case count of elements
  615.      * 
  616.      * @param mix $val 
  617.      * @param mix $case 
  618.      * @return bool 
  619.      * @throws Gumbo_Exception
  620.      */
  621.     public function isLessThanEqualTo ($val$case{
  622.         $passed false;
  623.         $type null;
  624.         
  625.         // Number check
  626.         if (is_numeric ($val)) {
  627.             $type "Number";
  628.             if (is_numeric ($case)) if ($val <= $case$passed true} }
  629.         }
  630.         
  631.         // String length check
  632.         if (is_string ($val)) {
  633.             $type "String";
  634.             if (is_numeric ($case)) if (strlen ($val<= $case$passed true} }
  635.             if (is_string ($case)) if (strlen ($val<= strlen ($case)) $passed true} }
  636.         }
  637.         
  638.         // Array length check
  639.         if (is_array ($val)) {
  640.             $type "Array";
  641.             if (is_numeric ($case)) if (count ($val<= $case$passed true} }
  642.             if (is_array ($case)) if (count ($val<= count ($case)) $passed true} }
  643.         }
  644.         
  645.         if (!$passed && $this->isThrowing ()) {
  646.             throw new Gumbo_Exception ("Validation FailedNot Less Than Equal To [{$type}]"$this->getLevel ());
  647.         }
  648.         return $passed;
  649.     }
  650.     
  651.     /**
  652.      * Returns if the value is Greater Than the test case
  653.      * 
  654.      * The value will check against the case value.  The value can be
  655.      * three different value types:
  656.      * 
  657.      * numeric (int,float)
  658.      * - case (numeric) : will compare values
  659.      * 
  660.      * string
  661.      * - case (numeric) : compare value string length to case value
  662.      * - case (string) : compare value string length to case string length
  663.      * 
  664.      * array
  665.      * - case (numeric) : compare value count of elements to case value
  666.      * - case (array) : compare value count of elements to case count of elements
  667.      * 
  668.      * @param mix $val 
  669.      * @param mix $case 
  670.      * @return bool 
  671.      * @throws Gumbo_Exception
  672.      */
  673.     public function isGreaterThan ($val$case{
  674.         $passed false;
  675.         $type null;
  676.         
  677.         // Number check
  678.         if (is_numeric ($val)) {
  679.             $type "Number";
  680.             if (is_numeric ($case)) if ($val $case$passed true} }
  681.         }
  682.         
  683.         // String length check
  684.         if (is_string ($val)) {
  685.             $type "String";
  686.             if (is_numeric ($case)) if (strlen ($val$case$passed true} }
  687.             if (is_string ($case)) if (strlen ($valstrlen ($case)) $passed true} }
  688.         }
  689.         
  690.         // Array length check
  691.         if (is_array ($val)) {
  692.             $type "Array";
  693.             if (is_numeric ($case)) if (count ($val$case$passed true} }
  694.             if (is_array ($case)) if (count ($valcount ($case)) $passed true} }
  695.         }
  696.         
  697.         if (!$passed && $this->isThrowing ()) {
  698.             throw new Gumbo_Exception ("Validation FailedNot Greater Than [{$type}]"$this->getLevel ());
  699.         }
  700.         return $passed;
  701.     }
  702.     
  703.     /**
  704.      * Returns if the value is Greater Than/Equal To the test case
  705.      * 
  706.      * The value will check against the case value.  The value can be
  707.      * three different value types:
  708.      * 
  709.      * numeric (int,float)
  710.      * - case (numeric) : will compare values
  711.      * 
  712.      * string
  713.      * - case (numeric) : compare value string length to case value
  714.      * - case (string) : compare value string length to case string length
  715.      * 
  716.      * array
  717.      * - case (numeric) : compare value count of elements to case value
  718.      * - case (array) : compare value count of elements to case count of elements
  719.      * 
  720.      * @param mix $val 
  721.      * @param mix $case 
  722.      * @return bool 
  723.      * @throws Gumbo_Exception
  724.      */
  725.     public function isGreaterThanEqualTo ($val$case{
  726.         $passed false;
  727.         $type null;
  728.         
  729.         // Number check
  730.         if (is_numeric ($val)) {
  731.             $type "Number";
  732.             if (is_numeric ($case)) if ($val >= $case$passed true} }
  733.         }
  734.         
  735.         // String length check
  736.         if (is_string ($val)) {
  737.             $type "String";
  738.             if (is_numeric ($case)) if (strlen ($val>= $case$passed true} }
  739.             if (is_string ($case)) if (strlen ($val>= strlen ($case)) $passed true} }
  740.         }
  741.         
  742.         // Array length check
  743.         if (is_array ($val)) {
  744.             $type "Array";
  745.             if (is_numeric ($case)) if (count ($val>= $case$passed true} }
  746.             if (is_array ($case)) if (count ($val>= count ($case)) $passed true} }
  747.         }
  748.         
  749.         if (!$passed && $this->isThrowing ()) {
  750.             throw new Gumbo_Exception ("Validation FailedNot Greater Than Equal To [{$type}]"$this->getLevel ());
  751.         }
  752.         return $passed;
  753.     }
  754.     
  755.     /**
  756.      * Returns if the value is Equal To the test case
  757.      * @param mix $val 
  758.      * @param mix $case 
  759.      * @return bool 
  760.      * @throws Gumbo_Exception
  761.      */
  762.     public function isEqualTo ($val$case{
  763.         $passed ($val == $case);
  764.         
  765.         if (!$passed && $this->isThrowing ()) {
  766.             throw new Gumbo_Exception ("Validation Failed: Not Equal To"$this->getLevel ());
  767.         }
  768.         return $passed;
  769.     }
  770.     
  771.     /**
  772.      * Returns if the value is Identical To the test case
  773.      * @param mix $val 
  774.      * @param mix $case 
  775.      * @return bool 
  776.      * @throws Gumbo_Exception
  777.      */
  778.     public function isIdenticalTo ($val$case{
  779.         $passed ($val === $case);
  780.         
  781.         if (!$passed && $this->isThrowing ()) {
  782.             throw new Gumbo_Exception ("Validation Failed: Not Identical To"$this->getLevel ());
  783.         }
  784.         return $passed;
  785.     }
  786.     
  787.     
  788.     
  789.     /**
  790.      * Returns if the value is Alpha characters only
  791.      * @param string $val 
  792.      * @return bool 
  793.      * @throws Gumbo_Exception
  794.      */
  795.     public function isAlpha ($val{
  796.         $passed false;
  797.         
  798.         // verify precondition
  799.         if (is_string ($val)) {
  800.             $passed ctype_alpha ($val);
  801.         }
  802.         
  803.         if (!$passed && $this->isThrowing ()) {
  804.             throw new Gumbo_Exception ("Validation Failed: Not Alpha"$this->getLevel ());
  805.         }
  806.         return $passed;
  807.     }
  808.     
  809.     /**
  810.      * Returns if the value is AlphaNumeric characters only
  811.      * @param string $val 
  812.      * @return bool 
  813.      * @throws Gumbo_Exception
  814.      */
  815.     public function isAlphaNumeric ($val{
  816.         $passed false;
  817.         
  818.         // verify precondition
  819.         if (!is_string ($val&& !is_numeric ($val)) {
  820.             $passed ctype_alnum ($val);
  821.         }
  822.         
  823.         if (!$passed && $this->isThrowing ()) {
  824.             throw new Gumbo_Exception ("Validation Failed: Not Alpha-Numeric"$this->getLevel ());
  825.         }
  826.         return $passed;
  827.     }
  828.     
  829.     /**
  830.      * Returns if the value is Digits only
  831.      * @param mix $val 
  832.      * @return bool 
  833.      * @throws Gumbo_Exception
  834.      */
  835.     public function isDigit ($val{
  836.         $passed false;
  837.         
  838.         // verify precondition
  839.         if (!is_string ($val&& !is_numeric ($val)) {
  840.             $passed ctype_digit ($val);
  841.         }
  842.         
  843.         if (!$passed && $this->isThrowing ()) {
  844.             throw new Gumbo_Exception ("Validation Failed: Not Digits"$this->getLevel ());
  845.         }
  846.         return $passed;
  847.     }
  848.     
  849.     /**
  850.      * Returns if the value is Hex characters only
  851.      * @param string $val 
  852.      * @return bool 
  853.      * @throws Gumbo_Exception
  854.      */
  855.     public function isHex ($val{
  856.         $passed false;
  857.         
  858.         // verify precondition
  859.         if (!is_string ($val)) {
  860.             $passed ctype_xdigit ($val);
  861.         }
  862.         
  863.         if (!$passed && $this->isThrowing ()) {
  864.             throw new Gumbo_Exception ("Validation Failed: Not Hex"$this->getLevel ());
  865.         }
  866.         return $passed;
  867.     }
  868.     
  869.     /**
  870.      * Returns if the value is Lowercase
  871.      * @param string $val 
  872.      * @return bool 
  873.      * @throws Gumbo_Exception
  874.      */
  875.     public function isLowercase ($val{
  876.         $passed false;
  877.         
  878.         // verify precondition
  879.         if (!is_string ($val)) {
  880.             $passed ctype_lower ($val);
  881.         }
  882.         
  883.         if (!$passed && $this->isThrowing ()) {
  884.             throw new Gumbo_Exception ("Validation Failed: Not Lowercase"$this->getLevel ());
  885.         }
  886.         return $passed;
  887.     }
  888.     
  889.     /**
  890.      * Returns if the value is Uppercase
  891.      * @param string $val 
  892.      * @return bool 
  893.      * @throws Gumbo_Exception
  894.      */
  895.     public function isUppercase ($val{
  896.         $passed false;
  897.         
  898.         // verify precondition
  899.         if (!is_string ($val)) {
  900.             $passed ctype_upper ($val);
  901.         }
  902.         
  903.         if (!$passed && $this->isThrowing ()) {
  904.             throw new Gumbo_Exception ("Validation Failed: Uppercase"$this->getLevel ());
  905.         }
  906.         return $passed;
  907.     }
  908.     
  909.     /**
  910.      * Returns if the value is Printable
  911.      * @param string $val 
  912.      * @return bool 
  913.      * @throws Gumbo_Exception
  914.      */
  915.     public function isPrintable ($val{
  916.         $passed false;
  917.         
  918.         // verify precondition
  919.         if (!is_string ($val)) {
  920.             $passed ctype_print ($val);
  921.         }
  922.         
  923.         if (!$passed && $this->isThrowing ()) {
  924.             throw new Gumbo_Exception ("Validation Failed: Not Printable"$this->getLevel ());
  925.         }
  926.         return $passed;
  927.     }
  928.     
  929.     /**
  930.      * Returns if the string value Begins With the test case
  931.      * @param string $val 
  932.      * @param string $case 
  933.      * @return bool 
  934.      * @throws Gumbo_Exception
  935.      */
  936.     public function beginsWith ($val$case{
  937.         $passed false;
  938.         
  939.         // verify precondition
  940.         if ((is_string ($val|| is_numeric ($val)) && (is_string ($case|| is_numeric ($case))) {
  941.             if (strlen ($valstrlen ($case)) {
  942.                 if (substr ($val0strlen ($case)) == $case{
  943.                     $passed true;
  944.                 }
  945.             }
  946.         }
  947.         
  948.         if (!$passed && $this->isThrowing ()) {
  949.             throw new Gumbo_Exception ("Validation FailedDoes Not Begin With {$case}"$this->getLevel ());
  950.         }
  951.         return $passed;
  952.     }
  953.     
  954.     /**
  955.      * Returns if the string value Ends With the test case
  956.      * @param string $val 
  957.      * @param string $case 
  958.      * @return bool 
  959.      * @throws Gumbo_Exception
  960.      */
  961.     public function endsWith ($val$case{
  962.         $passed false;
  963.         
  964.         // verify precondition
  965.         if ((is_string ($val|| is_numeric ($val)) && (is_string ($case|| is_numeric ($case))) {
  966.             if (strlen ($valstrlen ($case)) {
  967.                 if (substr ($valstrlen ($valstrlen ($case)) == $case{
  968.                     $passed true;
  969.                 }
  970.             }
  971.         }
  972.         
  973.         if (!$passed && $this->isThrowing ()) {
  974.             throw new Gumbo_Exception ("Validation FailedDoes Not End With {$case}"$this->getLevel ());
  975.         }
  976.         return $passed;
  977.     }
  978.     
  979.     /**
  980.      * Returns if the string value Contains the test case
  981.      * @param string $val 
  982.      * @param string $case 
  983.      * @return bool 
  984.      * @throws Gumbo_Exception
  985.      */
  986.     public function contains ($val$case{
  987.         $passed false;
  988.         
  989.         // verify precondition
  990.         if ((is_string ($val|| !is_numeric ($val)) && (is_string ($case|| is_numeric ($case))) {
  991.             $passed strstr ($val$case);
  992.         }
  993.         
  994.         if (!$passed && $this->isThrowing ()) {
  995.             throw new Gumbo_Exception ("Validation FailedDoes Not Contain {$case}"$this->getLevel ());
  996.         }
  997.         return $passed;
  998.     }
  999.     
  1000. }
  1001.  
  1002. ?>