/** * Validates object data * * @return boolean */ public function validate() { $validators = $this->getValidators(); foreach ($validators as $field => $validator) { $value = isset($this->_data[$field]) ? $this->_data[$field] : null; list($valid, $message) = Validator::validate($value, $validator); if (!$valid) { throw new InvalidFieldException($field, $message); } } return self::STATUS_VALID; }
public function testMessages() { $this->assertEquals('The value 1 is empty', Validator::getMessage(1, Validator::CONSTRAINT_REQUIRED)); $this->assertEquals('The value 1 is empty', Validator::getMessage(1, Validator::CONSTRAINT_NUMERIC_REQUIRED)); $this->assertEquals('The value 1 is not a positive number', Validator::getMessage(1, Validator::MODIFIER_POSITIVE)); $this->assertEquals('The value 1 is not a negative number', Validator::getMessage(1, Validator::MODIFIER_NEGATIVE)); $this->assertEquals('The value 1 is not a valid Ip', Validator::getMessage(1, Validator::MODIFIER_IP)); $this->assertEquals('The value 1 is not a valid Url', Validator::getMessage(1, Validator::MODIFIER_URL)); $this->assertEquals('The value 1 contains invalid values', Validator::getMessage(1, Validator::MODIFIER_NESTED)); }