Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

use ValidationMessage class for message reporting

  • Loading branch information...
commit d59729ab64e8739242740ce2edc854a9c2a8ae3c 1 parent c9c1dde
@c9s authored
View
5 src/ValidationKit/ValidationMessage.php
@@ -31,6 +31,11 @@ public static function createInvalid($msgId,$msg) {
return $msg;
}
+ public function __toString()
+ {
+ return $this->message;
+ }
+
}
View
33 src/ValidationKit/Validator.php
@@ -1,25 +1,7 @@
<?php
namespace ValidationKit;
use Exception;
-
-/**
- * $validator = new PatternValidator( '#test test test#' );
- * $bool = $validator->validate( $value );
- * $msg = $validator->getMessage();
- *
- * $validator = new StringValidator(array(
- * 'start_with' => '....' ,
- * 'end_with' => ...
- * ));
- * $bool = $validator->validate( $string );
- * $msg = $validator->getMessage();
- *
- * $validator = new IntegerRangeValidator(1, 100);
- * $bool = $validator->validate( 200 );
- *
- * $validator = new RangeValidator(array( '>' => 10 , '<' => 200 ));
- * $bool = $validator->validate( 10.0 );
- */
+use ValidationKit\ValidationMessage;
abstract class Validator
{
@@ -83,9 +65,14 @@ protected function saveResult($result,$msgId = null)
}
}
- public function addMessage($msgId)
+ public function addValidMessage($msgId)
+ {
+ $this->messages[] = ValidationMessage::createValid($msgId,$this->getMsgstr($msgId));
+ }
+
+ public function addInvalidMessage($msgId)
{
- $this->messages[] = $this->getMsgstr($msgId);
+ $this->messages[] = ValidationMessage::createInvalid($msgId,$this->getMsgstr($msgId));
}
public function getMessages()
@@ -101,7 +88,7 @@ public function setMessages($messages)
protected function invalid($msgId = null)
{
$msgId = $msgId ?: 'invalid';
- $this->addMessage($msgId);
+ $this->addInvalidMessage($msgId);
$this->isValid = false;
return false;
}
@@ -109,7 +96,7 @@ protected function invalid($msgId = null)
protected function valid($msgId = null)
{
$msgId = $msgId ?: 'valid';
- $this->addMessage($msgId);
+ $this->addValidMessage($msgId);
return $this->isValid = true;
}
Please sign in to comment.
Something went wrong with that request. Please try again.