diff --git a/classes/Collection.class.php b/classes/Collection.class.php index 2612707bc..3d490c510 100644 --- a/classes/Collection.class.php +++ b/classes/Collection.class.php @@ -1,4 +1,5 @@ references[$name] = $value; } } + /** + * __isset + * + * @param string $name + * @return boolean + */ + public function __isset($name) { + if(isset($this->data[$name])) + return true; + + if(isset($this->references[$name])) + return true; + + return false; + } + /** + * @param string $name + * @return void + */ + public function __unset($name) { + if(isset($this->data[$name])) + $this->data[$name] = array(); + + // todo: what to do with references ? + } /** * applies the changes made to this object into database * this method is smart enough to know if any changes are made diff --git a/classes/Sensei/Sensei.class.php b/classes/Sensei/Sensei.class.php index 73fa4c582..e84b70766 100644 --- a/classes/Sensei/Sensei.class.php +++ b/classes/Sensei/Sensei.class.php @@ -94,7 +94,7 @@ class Sensei extends Doctrine_Access { public function __construct() { - if(headers_sent()) + if(headers_sent()) throw new Sensei_Exception("Headers already sent. Couldn't initialize session."); $this->session = Doctrine_Manager::getInstance()->getCurrentSession(); diff --git a/classes/Session/Common.class.php b/classes/Session/Common.class.php index 6225ba8e1..dceb52d43 100644 --- a/classes/Session/Common.class.php +++ b/classes/Session/Common.class.php @@ -1,4 +1,5 @@ $column[1]) { $err[$key] = Doctrine_Validator::ERR_LENGTH; continue; - } + } if(self::gettype($value) !== $column[0]) { $err[$key] = Doctrine_Validator::ERR_TYPE; @@ -84,20 +107,35 @@ class Doctrine_Validator { $e = explode("|",$column[2]); foreach($e as $k => $arg) { - if(empty($arg) || $arg == "primary") + if(empty($arg) || $arg == "primary" || $arg == "protected" || $arg == "autoincrement") continue; - $validator = self::getValidator($arg); - if( ! $validator->validate($record,$key,$value)) { - switch(strtolower($arg)): + $args = explode(":",$arg); + if( ! isset($args[1])) + $args[1] = ''; + + $validator = self::getValidator($args[0]); + if( ! $validator->validate($record, $key, $value, $args[1])) { + switch(strtolower($args[0])): case "unique": $err[$key] = Doctrine_Validator::ERR_UNIQUE; break; + case "notnull": + $err[$key] = Doctrine_Validator::ERR_NULL; + break; + case "notblank": + $err[$key] = Doctrine_Validator::ERR_BLANK; + break; + case "enum": + $err[$key] = Doctrine_Validator::ERR_VALID; + break; default: $err[$key] = Doctrine_Validator::ERR_VALID; break; endswitch; } + + // errors found quit validation looping for this column if(isset($err[$key])) break; } diff --git a/classes/Validator/Country.class.php b/classes/Validator/Country.class.php index 049345900..e3bffa041 100644 --- a/classes/Validator/Country.class.php +++ b/classes/Validator/Country.class.php @@ -254,9 +254,10 @@ class Doctrine_Validator_Country { * @param Doctrine_Record $record * @param string $key * @param mixed $value + * @param string $args * @return boolean */ - public function validate(Doctrine_Record $record, $key, $value) { + public function validate(Doctrine_Record $record, $key, $value, $args) { return isset(self::$countries[$value]); } diff --git a/classes/Validator/Date.class.php b/classes/Validator/Date.class.php index c3bd188a0..8606dbdfc 100644 --- a/classes/Validator/Date.class.php +++ b/classes/Validator/Date.class.php @@ -4,9 +4,10 @@ class Doctrine_Validator_Date { * @param Doctrine_Record $record * @param string $key * @param mixed $value + * @param string $args * @return boolean */ - public function validate(Doctrine_Record $record, $key, $value) { + public function validate(Doctrine_Record $record, $key, $value, $args) { return checkdate($value); } } diff --git a/classes/Validator/Email.class.php b/classes/Validator/Email.class.php index 5ab1e928d..f88756918 100644 --- a/classes/Validator/Email.class.php +++ b/classes/Validator/Email.class.php @@ -4,9 +4,10 @@ class Doctrine_Validator_Email { * @param Doctrine_Record $record * @param string $key * @param mixed $value + * @param string $args * @return boolean */ - public function validate(Doctrine_Record $record, $key, $value) { + public function validate(Doctrine_Record $record, $key, $value, $args) { $parts = explode("@", $value); if(count($parts) != 2) diff --git a/classes/Validator/Htmlcolor.class.php b/classes/Validator/Htmlcolor.class.php index 77bb3cec8..876719545 100644 --- a/classes/Validator/Htmlcolor.class.php +++ b/classes/Validator/Htmlcolor.class.php @@ -4,9 +4,10 @@ class Doctrine_Validator_HtmlColor { * @param Doctrine_Record $record * @param string $key * @param mixed $value + * @param string $args * @return boolean */ - public function validate(Doctrine_Record $record, $key, $value) { + public function validate(Doctrine_Record $record, $key, $value, $args) { if( ! preg_match("/^#{0,1}[0-9]{6}$/",$color)) { return false; } diff --git a/classes/Validator/Ip.class.php b/classes/Validator/Ip.class.php index 2f7add1ce..2f7bc740c 100644 --- a/classes/Validator/Ip.class.php +++ b/classes/Validator/Ip.class.php @@ -4,9 +4,10 @@ class Doctrine_Validator_Ip { * @param Doctrine_Record $record * @param string $key * @param mixed $value + * @param string $args * @return boolean */ - public function validate(Doctrine_Record $record, $key, $value) { + public function validate(Doctrine_Record $record, $key, $value, $args) { $e = explode(".",$request); if(count($e) != 4) return false; diff --git a/classes/Validator/Nospace.class.php b/classes/Validator/Nospace.class.php index 4142a0a41..f7eda274d 100644 --- a/classes/Validator/Nospace.class.php +++ b/classes/Validator/Nospace.class.php @@ -4,9 +4,10 @@ class Doctrine_Validator_NoSpace { * @param Doctrine_Record $record * @param string $key * @param mixed $value + * @param string $args * @return boolean */ - public function validate(Doctrine_Record $record, $key, $value) { + public function validate(Doctrine_Record $record, $key, $value, $args) { if(preg_match("/[\s\r\t\n]/", $value)) return false; diff --git a/classes/Validator/Notblank.class.php b/classes/Validator/Notblank.class.php index e342ee9d7..fd83d8907 100644 --- a/classes/Validator/Notblank.class.php +++ b/classes/Validator/Notblank.class.php @@ -4,15 +4,18 @@ class Doctrine_Validator_Notblank { * @param Doctrine_Record $record * @param string $key * @param mixed $value + * @param string $args * @return boolean */ - public function validate(Doctrine_Record $record, $key, $value) { + public function validate(Doctrine_Record $record, $key, $value, $args) { $string = str_replace("\n","",$value); $string = str_replace("\r","",$string); $string = str_replace("\t","",$string); $string = str_replace("\s","",$string); $string = str_replace(" ","",$string); - if($string == "") return true; + if($string == "") return false; + + return true; } } ?> diff --git a/classes/Validator/Range.class.php b/classes/Validator/Range.class.php index 14669b145..bc00f13fe 100644 --- a/classes/Validator/Range.class.php +++ b/classes/Validator/Range.class.php @@ -16,9 +16,10 @@ class Doctrine_Validator_Range { * @param Doctrine_Record $record * @param string $key * @param mixed $value + * @param string $args * @return boolean */ - public function validate(Doctrine_Record $record, $key, $value) { + public function validate(Doctrine_Record $record, $key, $value, $args) { if($var < $this->min) return false; diff --git a/classes/Validator/Regexp.class.php b/classes/Validator/Regexp.class.php index b2660192d..97f9691bd 100644 --- a/classes/Validator/Regexp.class.php +++ b/classes/Validator/Regexp.class.php @@ -4,9 +4,10 @@ class Doctrine_Validator_Regexp { * @param Doctrine_Record $record * @param string $key * @param mixed $value + * @param string $args * @return boolean */ - public function validate(Doctrine_Record $record, $key, $value) { + public function validate(Doctrine_Record $record, $key, $value, $args) { return $value; } } diff --git a/classes/Validator/Unique.class.php b/classes/Validator/Unique.class.php index 4dfb21402..912fb92a8 100644 --- a/classes/Validator/Unique.class.php +++ b/classes/Validator/Unique.class.php @@ -4,9 +4,10 @@ class Doctrine_Validator_Unique { * @param Doctrine_Record $record * @param string $key * @param mixed $value + * @param string $args * @return boolean */ - public function validate(Doctrine_Record $record, $key, $value) { + public function validate(Doctrine_Record $record, $key, $value, $args) { $table = $record->getTable(); $sql = "SELECT id FROM ".$table->getTableName()." WHERE ".$key." = ?"; $stmt = $table->getSession()->getDBH()->prepare($sql); diff --git a/classes/Validator/Usstate.class.php b/classes/Validator/Usstate.class.php index ba068e85c..5545d32c2 100644 --- a/classes/Validator/Usstate.class.php +++ b/classes/Validator/Usstate.class.php @@ -62,9 +62,10 @@ class ValidatorUSState { * @param Doctrine_Record $record * @param string $key * @param mixed $value + * @param string $args * @return boolean */ - public function validate(Doctrine_Record $record, $key, $value) { + public function validate(Doctrine_Record $record, $key, $value, $args) { return isset(self::$states[$value]); } } diff --git a/tests/ValidatorTestCase.class.php b/tests/ValidatorTestCase.class.php index 1b90edab1..96ae2f58f 100644 --- a/tests/ValidatorTestCase.class.php +++ b/tests/ValidatorTestCase.class.php @@ -39,13 +39,13 @@ class Doctrine_ValidatorTestCase extends Doctrine_UnitTestCase { $validator = new Doctrine_Validator_Email(); $email = $this->session->create("Email"); - $this->assertFalse($validator->validate($email,"address","example@example")); - $this->assertFalse($validator->validate($email,"address","example@@example")); - $this->assertFalse($validator->validate($email,"address","example@example.")); - $this->assertFalse($validator->validate($email,"address","example@e..")); + $this->assertFalse($validator->validate($email,"address","example@example",null)); + $this->assertFalse($validator->validate($email,"address","example@@example",null)); + $this->assertFalse($validator->validate($email,"address","example@example.",null)); + $this->assertFalse($validator->validate($email,"address","example@e..",null)); - $this->assertFalse($validator->validate($email,"address","example@e..")); - $this->assertTrue($validator->validate($email,"address","example@e.e.e.e.e")); + $this->assertFalse($validator->validate($email,"address","example@e..",null)); + $this->assertTrue($validator->validate($email,"address","example@e.e.e.e.e",null)); } public function testSave() {