From e65f623aeaf973693fcf092e332550a7234e9800 Mon Sep 17 00:00:00 2001 From: cpowers Date: Fri, 16 Mar 2007 19:19:30 +0000 Subject: [PATCH] Added validator for unsigned data types Ticket: 288 --- lib/Doctrine/Compiler.php | 1 + lib/Doctrine/Validator/Unsigned.php | 54 +++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 lib/Doctrine/Validator/Unsigned.php diff --git a/lib/Doctrine/Compiler.php b/lib/Doctrine/Compiler.php index d5a3e667f..7f34a7c77 100644 --- a/lib/Doctrine/Compiler.php +++ b/lib/Doctrine/Compiler.php @@ -221,6 +221,7 @@ class Doctrine_Compiler 'Validator_Range', 'Validator_Regexp', 'Validator_Unique', + 'Validator_Unsigned', 'Validator_Usstate', 'ValueHolder', 'View_Exception', diff --git a/lib/Doctrine/Validator/Unsigned.php b/lib/Doctrine/Validator/Unsigned.php new file mode 100644 index 000000000..038586298 --- /dev/null +++ b/lib/Doctrine/Validator/Unsigned.php @@ -0,0 +1,54 @@ +. + */ + +/** + * Doctrine_Validator_Enum + * + * @package Doctrine + * @category Object Relational Mapping + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @link www.phpdoctrine.com + * @since 1.0 + * @version $Revision: 1080 $ + * @author Konsta Vesterinen + */ +class Doctrine_Validator_Unsigned +{ + /** + * @param Doctrine_Record $record + * @param string $key + * @param mixed $value + * @param string $args + * @return boolean + */ + public function validate(Doctrine_Record $record, $key, $value, $args) + { + $int = (int) $value; + + if ($int != $value || $int < 0) { + return false; + } + if ($int < 0) { + return false; + } + return true; + } +}