[pLog-svn] r3544 - in plog/trunk/class/data/validator: . rules

reto at devel.lifetype.net reto at devel.lifetype.net
Tue Jun 6 21:22:06 GMT 2006


Author: reto
Date: 2006-06-06 21:22:05 +0000 (Tue, 06 Jun 2006)
New Revision: 3544

Added:
   plog/trunk/class/data/validator/rules/intrangerule.class.php
   plog/trunk/class/data/validator/rules/stringrangerule.class.php
Removed:
   plog/trunk/class/data/validator/rules/rangerule.class.php
Modified:
   plog/trunk/class/data/validator/passwordvalidator.class.php
Log:
ok, hope i don't mess anything up with this "commit in a hurry" - please double check, it's about validators!

1. deleted rangerule.class.php and created intrangerule.class.php and stringrangerule.class.php instead

why:
rangerule.class.php was not clear on if it's for ranges on integer or if it's to check string ranges (like with password validation). first it did the latter now oscar changed it to do the first.

solution:
create two classes and let passwordvalidator.class.php use stringrangerule.class.php for now. AFAIK no other Validator used intrangerule.class.php anyway. of course password validation could be much more sofisticated, but I think it all good for now.

Modified: plog/trunk/class/data/validator/passwordvalidator.class.php
===================================================================
--- plog/trunk/class/data/validator/passwordvalidator.class.php	2006-06-06 20:40:37 UTC (rev 3543)
+++ plog/trunk/class/data/validator/passwordvalidator.class.php	2006-06-06 21:22:05 UTC (rev 3544)
@@ -29,7 +29,7 @@
             $config =& Config::getConfig();
             
             $this->addRule( new NonEmptyRule());
-            $this->addRule( new RangeRule( $config->getValue( "minimum_password_length", MIN_PASSWORD_LENGTH_DEFAULT ), 32 ));
+            $this->addRule( new StringRangeRule( $config->getValue( "minimum_password_length", MIN_PASSWORD_LENGTH_DEFAULT ), 32 ));
         }
     }
 ?>

Added: plog/trunk/class/data/validator/rules/intrangerule.class.php
===================================================================
--- plog/trunk/class/data/validator/rules/intrangerule.class.php	2006-06-06 20:40:37 UTC (rev 3543)
+++ plog/trunk/class/data/validator/rules/intrangerule.class.php	2006-06-06 21:22:05 UTC (rev 3544)
@@ -0,0 +1,100 @@
+<?php
+
+    include_once( PLOG_CLASS_PATH."class/data/validator/rules/rule.class.php");
+
+    define( "ERROR_RULE_TOO_SMALL", "error_rule_too_small");
+    define( "ERROR_RULE_TOO_LARGE", "error_rule_too_large");
+
+    /**
+     * \ingroup Validator_Rules
+     *
+     * Given two values that will be used as lower and upper boundaries of the range, 
+     * it will validate whether the given value falls within the range.
+     *
+     * It will set the errors ERROR_RULE_TOO_SMALL or ERROR_RULE_TOO_LARGE in case the
+     * validation is not successful.
+     */
+    class IntRangeRule extends Rule
+    {
+        var $_minValue;
+        var $_maxValue;
+
+        /**
+         * Initializes the rule
+         *
+         * @param minValue the lower boundary of the range
+         * @param maxValue the upper boundary of the range
+         */
+        function RangeRule($minValue, $maxValue)
+        {
+            $this->Rule();
+
+            $this->_minValue = $minValue;
+            $this->_maxValue = $maxValue;
+        }
+
+        /**
+         * @return the lower boundary of the range
+         */
+        function getMinValue()
+        {
+            return $this->_minValue;
+        }
+
+        /**
+         * sets the lower boundary of the range
+         *
+         * @param minValue the minimum value
+         */
+        function setMinValue($minValue)
+        {
+            $this->_minValue = $minValue;
+        }
+
+        /**
+         * @return the upper boundary of the range
+         */
+        function getMaxValue()
+        {
+            return $this->_maxValue;
+        }
+
+        /**
+         * sets the lower boundary of the range
+         *
+         * @param minValue the minimum value
+         */
+        function setMaxValue($maxValue)
+        {
+            $this->_maxValue = $maxValue;
+        }
+
+        /**
+         * validates that the given value is within the two boundaries previously specified
+         *
+         * @param value The value to validate
+         * @return True if successful or false otherwise
+         */
+        function validate($value)
+        {
+            //$len = strlen($value);
+            $intValue = (int)$value;
+
+            if ($intValue < $this->_minValue)
+            {
+                $this->_setError(ERROR_RULE_TOO_SMALL);
+                return false;
+            }
+            else if ($this->_maxValue != 0 && $intValue > $this->_maxValue)
+            {
+                $this->_setError(ERROR_RULE_TOO_LARGE);
+                return false;
+            }
+            else
+            {
+                $this->_setError(false);
+                return true;
+            }
+        }
+    }
+?>
\ No newline at end of file

Deleted: plog/trunk/class/data/validator/rules/rangerule.class.php
===================================================================
--- plog/trunk/class/data/validator/rules/rangerule.class.php	2006-06-06 20:40:37 UTC (rev 3543)
+++ plog/trunk/class/data/validator/rules/rangerule.class.php	2006-06-06 21:22:05 UTC (rev 3544)
@@ -1,100 +0,0 @@
-<?php
-
-    include_once( PLOG_CLASS_PATH."class/data/validator/rules/rule.class.php");
-
-    define( "ERROR_RULE_TOO_SMALL", "error_rule_too_small");
-    define( "ERROR_RULE_TOO_LARGE", "error_rule_too_large");
-
-    /**
-     * \ingroup Validator_Rules
-     *
-     * Given two values that will be used as lower and upper boundaries of the range, 
-     * it will validate whether the given value falls within the range.
-     *
-     * It will set the errors ERROR_RULE_TOO_SMALL or ERROR_RULE_TOO_LARGE in case the
-     * validation is not successful.
-     */
-    class RangeRule extends Rule
-    {
-        var $_minValue;
-        var $_maxValue;
-
-        /**
-         * Initializes the rule
-         *
-         * @param minValue the lower boundary of the range
-         * @param maxValue the upper boundary of the range
-         */
-        function RangeRule($minValue, $maxValue)
-        {
-            $this->Rule();
-
-            $this->_minValue = $minValue;
-            $this->_maxValue = $maxValue;
-        }
-
-        /**
-         * @return the lower boundary of the range
-         */
-        function getMinValue()
-        {
-            return $this->_minValue;
-        }
-
-        /**
-         * sets the lower boundary of the range
-         *
-         * @param minValue the minimum value
-         */
-        function setMinValue($minValue)
-        {
-            $this->_minValue = $minValue;
-        }
-
-        /**
-         * @return the upper boundary of the range
-         */
-        function getMaxValue()
-        {
-            return $this->_maxValue;
-        }
-
-        /**
-         * sets the lower boundary of the range
-         *
-         * @param minValue the minimum value
-         */
-        function setMaxValue($maxValue)
-        {
-            $this->_maxValue = $maxValue;
-        }
-
-        /**
-         * validates that the given value is within the two boundaries previously specified
-         *
-         * @param value The value to validate
-         * @return True if successful or false otherwise
-         */
-        function validate($value)
-        {
-            //$len = strlen($value);
-            $intValue = (int)$value;
-
-            if ($intValue < $this->_minValue)
-            {
-                $this->_setError(ERROR_RULE_TOO_SMALL);
-                return false;
-            }
-            else if ($this->_maxValue != 0 && $intValue > $this->_maxValue)
-            {
-                $this->_setError(ERROR_RULE_TOO_LARGE);
-                return false;
-            }
-            else
-            {
-                $this->_setError(false);
-                return true;
-            }
-        }
-    }
-?>
\ No newline at end of file

Added: plog/trunk/class/data/validator/rules/stringrangerule.class.php
===================================================================
--- plog/trunk/class/data/validator/rules/stringrangerule.class.php	2006-06-06 20:40:37 UTC (rev 3543)
+++ plog/trunk/class/data/validator/rules/stringrangerule.class.php	2006-06-06 21:22:05 UTC (rev 3544)
@@ -0,0 +1,99 @@
+<?php
+
+    include_once( PLOG_CLASS_PATH."class/data/validator/rules/rule.class.php");
+
+    define( "ERROR_RULE_TOO_SMALL", "error_rule_too_small");
+    define( "ERROR_RULE_TOO_LARGE", "error_rule_too_large");
+
+    /**
+     * \ingroup Validator_Rules
+     *
+     * Given two values that will be used as lower and upper boundaries of the range, 
+     * it will validate whether the given value falls within the range.
+     *
+     * It will set the errors ERROR_RULE_TOO_SMALL or ERROR_RULE_TOO_LARGE in case the
+     * validation is not successful.
+     */
+    class StringRangeRule extends Rule
+    {
+        var $_minValue;
+        var $_maxValue;
+
+        /**
+         * Initializes the rule
+         *
+         * @param minValue the lower boundary of the range
+         * @param maxValue the upper boundary of the range
+         */
+        function RangeRule($minValue, $maxValue)
+        {
+            $this->Rule();
+
+            $this->_minValue = $minValue;
+            $this->_maxValue = $maxValue;
+        }
+
+        /**
+         * @return the lower boundary of the range
+         */
+        function getMinValue()
+        {
+            return $this->_minValue;
+        }
+
+        /**
+         * sets the lower boundary of the range
+         *
+         * @param minValue the minimum value
+         */
+        function setMinValue($minValue)
+        {
+            $this->_minValue = $minValue;
+        }
+
+        /**
+         * @return the upper boundary of the range
+         */
+        function getMaxValue()
+        {
+            return $this->_maxValue;
+        }
+
+        /**
+         * sets the lower boundary of the range
+         *
+         * @param minValue the minimum value
+         */
+        function setMaxValue($maxValue)
+        {
+            $this->_maxValue = $maxValue;
+        }
+
+        /**
+         * validates that the given value is within the two boundaries previously specified
+         *
+         * @param value The value to validate
+         * @return True if successful or false otherwise
+         */
+        function validate($value)
+        {
+            $len = strlen($value);
+
+            if ($len < $this->_minValue)
+            {
+                $this->_setError(ERROR_RULE_TOO_SMALL);
+                return false;
+            }
+            else if ($this->_maxValue != 0 && $len > $this->_maxValue)
+            {
+                $this->_setError(ERROR_RULE_TOO_LARGE);
+                return false;
+            }
+            else
+            {
+                $this->_setError(false);
+                return true;
+            }
+        }
+    }
+?>
\ No newline at end of file



More information about the pLog-svn mailing list