Page MenuHomePhabricator

No OneTemporary

diff --git a/validation/rules/MaxLengthValidationRule.php b/validation/rules/MaxLengthValidationRule.php
index b57e1fc..265d963 100644
--- a/validation/rules/MaxLengthValidationRule.php
+++ b/validation/rules/MaxLengthValidationRule.php
@@ -1,66 +1,68 @@
<?php namespace spitfire\validation\rules;
+use spitfire\validation\ValidationError;
+
/**
* Validates that the length of a content is smaller than the indicated minimum
* length. This validates only data as strings which may cause unexpected
* behavior if you try to test the length of an array.
*
* @author César de la Cal <cesar@magic3w.com>
*/
class MaxLengthValidationRule implements \spitfire\validation\ValidationRule
{
/**
* The minimum length a string passed to this element must have for the test
* to be passed successfully.
* @var int
*/
private $length;
/**
* A message the validation error generated by this object should carry to give
* the end user information about the reason his input was rejected.
* @var string
*/
private $message;
/**
* Additional information given to the user in case the validation did not
* succeed. This message can hold additional infos on how to solve the error.
* @var string
*/
private $extendedMessage;
/**
* Creates a maximum length validation rule. This will provide a way to test
* whether a string is longer than allowed before using or storing it.
*
* @param int $length
* @param string $message
* @param string $extendedMessage
*/
public function __construct($length, $message, $extendedMessage = '') {
$this->length = $length;
$this->message = $message;
$this->extendedMessage = $extendedMessage;
}
/**
* Tests a value with this validation rule. Returns the errors detected for
* this element or boolean false on no errors.
*
* @param mixed $value
* @return \spitfire\validation\ValidationError|boolean
*/
public function test($value) {
if (function_exists('mb_strlen')) {
return mb_strlen($value) > $this->length? new ValidationError($this->message, $this->extendedMessage) : false;
}
elseif (strlen($value) > $this->length) {
return new ValidationError($this->message, $this->extendedMessage);
}
return false;
}
}
\ No newline at end of file
diff --git a/validation/rules/MinLengthValidationRule.php b/validation/rules/MinLengthValidationRule.php
index 34be7d3..12f296e 100644
--- a/validation/rules/MinLengthValidationRule.php
+++ b/validation/rules/MinLengthValidationRule.php
@@ -1,54 +1,56 @@
<?php namespace spitfire\validation\rules;
+use spitfire\validation\ValidationError;
+
/**
* Validates that the length of a content is bigger than the indicated minimum
* length. This validates only data as strings which may cause unexpected
* behavior if you try to test the length of an array.
*
* @author César de la Cal <cesar@magic3w.com>
*/
class MinLengthValidationRule implements \spitfire\validation\ValidationRule
{
/**
* The minimum length a string passed to this element must have for the test
* to be passed successfully.
* @var int
*/
private $length;
/**
* A message the validation error generated by this object should carry to give
* the end user information about the reason his input was rejected.
* @var string
*/
private $message;
/**
* Additional information given to the user in case the validation did not
* succeed. This message can hold additional infos on how to solve the error.
* @var string
*/
private $extendedMessage;
public function __construct($length, $message, $extendedMessage = '') {
$this->length = $length;
$this->message = $message;
$this->extendedMessage = $extendedMessage;
}
/**
* Tests a value with this validation rule. Returns the errors detected for
* this element or boolean false on no errors.
*
* @param mixed $value
* @param mixed $source
* @return \spitfire\validation\ValidationError|boolean
*/
public function test($value) {
if (strlen($value) < $this->length) {
return new ValidationError($this->message, $this->extendedMessage);
}
return false;
}
}
\ No newline at end of file
diff --git a/validation/rules/PositiveNumberValidationRule.php b/validation/rules/PositiveNumberValidationRule.php
index 28c5efc..e86eea5 100644
--- a/validation/rules/PositiveNumberValidationRule.php
+++ b/validation/rules/PositiveNumberValidationRule.php
@@ -1,51 +1,53 @@
<?php namespace spitfire\validation\rules;
+use spitfire\validation\ValidationError;
+
/**
* This filter ensures that a number provided to it was positive.
*
* @author César de la Cal <cesar@magic3w.com>
*/
class PositiveNumberValidationRule implements \spitfire\validation\ValidationRule
{
/**
* A message the validation error generated by this object should carry to give
* the end user information about the reason his input was rejected.
*
* @var string
*/
private $message;
/**
* Additional information given to the user in case the validation did not
* succeed. This message can hold additional infos on how to solve the error.
*
* @var string
*/
private $extendedMessage;
public function __construct($message, $extendedMessage = '') {
$this->message = $message;
$this->extendedMessage = $extendedMessage;
}
/**
* Tests a value with this validation rule. Returns the errors detected for
* this element or boolean false on no errors.
*
* @param mixed $value
* @param mixed $source
* @return \spitfire\validation\ValidationError|boolean
*/
public function test($value) {
if ($value === null) {
return false;
}
if ($value < 0) {
return new ValidationError($this->message, $this->extendedMessage);
}
return false;
}
}
\ No newline at end of file

File Metadata

Mime Type
text/x-diff
Expires
Apr 14 2021, 1:26 AM (8 w, 6 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1827
Default Alt Text
(5 KB)

Event Timeline