Fixed typos

This commit is contained in:
Pascal Borreli 2013-03-06 01:54:59 +00:00
parent c049a8f380
commit 0ada9f2ad6
3 changed files with 41 additions and 40 deletions

View File

@ -3,7 +3,7 @@
Valitron is a simple, minimal and elegant stand-alone validation library Valitron is a simple, minimal and elegant stand-alone validation library
with NO dependencies. Valitron uses simple, straightforward validation with NO dependencies. Valitron uses simple, straightforward validation
methods with a focus on readable and concise syntax. Valitron is the methods with a focus on readable and concise syntax. Valitron is the
simple and pragmatic validation library you've been loking for. simple and pragmatic validation library you've been looking for.
[![Build [![Build
Status](https://travis-ci.org/vlucas/valitron.png?branch=master)](https://travis-ci.org/vlucas/valitron) Status](https://travis-ci.org/vlucas/valitron.png?branch=master)](https://travis-ci.org/vlucas/valitron)
@ -152,7 +152,7 @@ Putting these techniques together, you can create a complete
rule definition in a relatively compact data structure. rule definition in a relatively compact data structure.
You can continue to add individual rules with the `rule` method You can continue to add individual rules with the `rule` method
even after specifying a rule defnition via an array. This is even after specifying a rule definition via an array. This is
especially useful if you are defining custom validation rules. especially useful if you are defining custom validation rules.
```php ```php

View File

@ -12,12 +12,12 @@ return array(
'in' => "Invalid value", 'in' => "Invalid value",
'notIn' => "Invalid value", 'notIn' => "Invalid value",
'ip' => "Invalid IP address", 'ip' => "Invalid IP address",
'email' => "Inalid email address", 'email' => "Invalid email address",
'url' => "Inalid URL", 'url' => "Invalid URL",
'urlActive' => "Must be active domain", 'urlActive' => "Must be active domain",
'alpha' => "Must contain only leters a-z", 'alpha' => "Must contain only letters a-z",
'alphaNum' => "Must contain only leters a-z and/or numbers 0-9", 'alphaNum' => "Must contain only letters a-z and/or numbers 0-9",
'slug' => "Must contain only leters a-z, numbers 0-9, dashes and underscores", 'slug' => "Must contain only letters a-z, numbers 0-9, dashes and underscores",
'regex' => "Invalid format", 'regex' => "Invalid format",
'date' => "Invalid date", 'date' => "Invalid date",
'dateFormat' => "Must be date with format '%s'", 'dateFormat' => "Must be date with format '%s'",

View File

@ -4,7 +4,7 @@ namespace Valitron;
/** /**
* Validation Class * Validation Class
* *
* Validates input against certian criteria * Validates input against certain criteria
* *
* @package Valitron * @package Valitron
* @author Vance Lucas <vance@vancelucas.com> * @author Vance Lucas <vance@vancelucas.com>
@ -32,16 +32,16 @@ class Validator
{ {
// Allows filtering of used input fields against optional second array of field names allowed // Allows filtering of used input fields against optional second array of field names allowed
// This is useful for limiting raw $_POST or $_GET data to only known fields // This is useful for limiting raw $_POST or $_GET data to only known fields
foreach($data as $field => $value) { foreach ($data as $field => $value) {
if(empty($fields) || (!empty($fields) && in_array($field, $fields))) { if (empty($fields) || (!empty($fields) && in_array($field, $fields))) {
$this->_fields[$field] = $value; $this->_fields[$field] = $value;
} }
} }
// Only load language files if language or directory has changed // Only load language files if language or directory has changed
if($lang !== static::$_lang || $langDir !== static::$_langDir) { if ($lang !== static::$_lang || $langDir !== static::$_langDir) {
// Set language directory for loading language files // Set language directory for loading language files
if($langDir === null) { if ($langDir === null) {
$langDir = dirname(dirname(__DIR__)) . '/lang'; $langDir = dirname(dirname(__DIR__)) . '/lang';
} }
static::langDir($langDir); static::langDir($langDir);
@ -56,7 +56,7 @@ class Validator
*/ */
public static function lang($lang = null) public static function lang($lang = null)
{ {
if($lang !== null) { if ($lang !== null) {
static::$_lang = $lang; static::$_lang = $lang;
// Load language file in directory // Load language file in directory
@ -71,7 +71,7 @@ class Validator
*/ */
public static function langDir($dir = null) public static function langDir($dir = null)
{ {
if($dir !== null) { if ($dir !== null) {
static::$_langDir = $dir; static::$_langDir = $dir;
} }
return static::$_langDir; return static::$_langDir;
@ -82,9 +82,9 @@ class Validator
*/ */
protected function validateRequired($field, $value) protected function validateRequired($field, $value)
{ {
if(is_null($value)) { if (is_null($value)) {
return false; return false;
} elseif(is_string($value) and trim($value) === '') { } elseif (is_string($value) and trim($value) === '') {
return false; return false;
} }
return true; return true;
@ -95,7 +95,7 @@ class Validator
* *
* @param string $field * @param string $field
* @param mixed $value * @param mixed $value
* @param array $fields * @param array $params
* @return void * @return void
*/ */
protected function validateEquals($field, $value, array $params) protected function validateEquals($field, $value, array $params)
@ -109,7 +109,7 @@ class Validator
* *
* @param string $field * @param string $field
* @param mixed $value * @param mixed $value
* @param array $fields * @param array $params
* @return bool * @return bool
*/ */
protected function validateDifferent($field, $value, array $params) protected function validateDifferent($field, $value, array $params)
@ -162,14 +162,14 @@ class Validator
* *
* @param string $field * @param string $field
* @param mixed $value * @param mixed $value
* @param array $fields * @param array $params
* @return bool * @return bool
*/ */
protected function validateLength($field, $value, $params) protected function validateLength($field, $value, $params)
{ {
$length = $this->stringLength($value); $length = $this->stringLength($value);
// Length between // Length between
if(isset($params[1])) { if (isset($params[1])) {
return $length >= $params[0] && $length <= $params[1]; return $length >= $params[0] && $length <= $params[1];
} }
// Length same // Length same
@ -195,7 +195,7 @@ class Validator
* *
* @param string $field * @param string $field
* @param mixed $value * @param mixed $value
* @param array $fields * @param array $params
* @return bool * @return bool
*/ */
protected function validateMin($field, $value, $params) protected function validateMin($field, $value, $params)
@ -208,7 +208,7 @@ class Validator
* *
* @param string $field * @param string $field
* @param mixed $value * @param mixed $value
* @param array $fields * @param array $params
* @return bool * @return bool
*/ */
protected function validateMax($field, $value, $params) protected function validateMax($field, $value, $params)
@ -221,7 +221,7 @@ class Validator
* *
* @param string $field * @param string $field
* @param mixed $value * @param mixed $value
* @param array $fields * @param array $params
* @return bool * @return bool
*/ */
protected function validateIn($field, $value, $params) protected function validateIn($field, $value, $params)
@ -234,7 +234,7 @@ class Validator
* *
* @param string $field * @param string $field
* @param mixed $value * @param mixed $value
* @param array $fields * @param array $params
* @return bool * @return bool
*/ */
protected function validateNotIn($field, $value, $params) protected function validateNotIn($field, $value, $params)
@ -252,7 +252,7 @@ class Validator
*/ */
protected function validateContains($field, $value, $params) protected function validateContains($field, $value, $params)
{ {
if(!isset($params[0])) { if (!isset($params[0])) {
return false; return false;
} }
if (!is_string($params[0]) || !is_string($value)) { if (!is_string($params[0]) || !is_string($value)) {
@ -295,7 +295,7 @@ class Validator
protected function validateUrl($field, $value) protected function validateUrl($field, $value)
{ {
foreach ($this->validUrlPrefixes as $prefix) { foreach ($this->validUrlPrefixes as $prefix) {
if(strpos($value, $prefix) !== false) { if (strpos($value, $prefix) !== false) {
return filter_var($value, FILTER_VALIDATE_URL) !== false; return filter_var($value, FILTER_VALIDATE_URL) !== false;
} }
} }
@ -312,7 +312,7 @@ class Validator
protected function validateUrlActive($field, $value) protected function validateUrlActive($field, $value)
{ {
foreach ($this->validUrlPrefixes as $prefix) { foreach ($this->validUrlPrefixes as $prefix) {
if(strpos($value, $prefix) !== false) { if (strpos($value, $prefix) !== false) {
$url = str_replace($prefix, '', strtolower($value)); $url = str_replace($prefix, '', strtolower($value));
return checkdnsrr($url); return checkdnsrr($url);
@ -362,6 +362,7 @@ class Validator
* *
* @param string $field * @param string $field
* @param mixed $value * @param mixed $value
* @param array $params
* @return bool * @return bool
*/ */
protected function validateRegex($field, $value, $params) protected function validateRegex($field, $value, $params)
@ -386,7 +387,7 @@ class Validator
* *
* @param string $field * @param string $field
* @param mixed $value * @param mixed $value
* @param array $fields * @param array $params
* @return bool * @return bool
*/ */
protected function validateDateFormat($field, $value, $params) protected function validateDateFormat($field, $value, $params)
@ -401,7 +402,7 @@ class Validator
* *
* @param string $field * @param string $field
* @param mixed $value * @param mixed $value
* @param array $fields * @param array $params
* @return bool * @return bool
*/ */
protected function validateDateBefore($field, $value, $params) protected function validateDateBefore($field, $value, $params)
@ -416,7 +417,7 @@ class Validator
* *
* @param string $field * @param string $field
* @param mixed $value * @param mixed $value
* @param array $fields * @param array $params
* @return bool * @return bool
*/ */
protected function validateDateAfter($field, $value, $params) protected function validateDateAfter($field, $value, $params)
@ -439,7 +440,7 @@ class Validator
*/ */
public function errors($field = null) public function errors($field = null)
{ {
if($field !== null) { if ($field !== null) {
return isset($this->_errors[$field]) ? $this->_errors[$field] : false; return isset($this->_errors[$field]) ? $this->_errors[$field] : false;
} }
return $this->_errors; return $this->_errors;
@ -452,11 +453,11 @@ class Validator
{ {
$values = array(); $values = array();
// Printed values need to be in string format // Printed values need to be in string format
foreach($params as $param) { foreach ($params as $param) {
if(is_array($param)) { if (is_array($param)) {
$param = "['" . implode("', '", $param) . "']"; $param = "['" . implode("', '", $param) . "']";
} }
if($param instanceof \DateTime) { if ($param instanceof \DateTime) {
$param = $param->format('Y-m-d'); $param = $param->format('Y-m-d');
} }
$values[] = $param; $values[] = $param;
@ -490,12 +491,12 @@ class Validator
*/ */
public function validate() public function validate()
{ {
foreach($this->_validations as $v) { foreach ($this->_validations as $v) {
foreach($v['fields'] as $field) { foreach ($v['fields'] as $field) {
$value = isset($this->_fields[$field]) ? $this->_fields[$field] : null; $value = isset($this->_fields[$field]) ? $this->_fields[$field] : null;
// Callback is user-specified or assumed method on class // Callback is user-specified or assumed method on class
if(isset(static::$_rules[$v['rule']])) { if (isset(static::$_rules[$v['rule']])) {
$callback = static::$_rules[$v['rule']]; $callback = static::$_rules[$v['rule']];
} else { } else {
$callback = array($this, 'validate' . ucfirst($v['rule'])); $callback = array($this, 'validate' . ucfirst($v['rule']));
@ -515,7 +516,7 @@ class Validator
*/ */
public static function addRule($name, $callback, $message = self::ERROR_DEFAULT) public static function addRule($name, $callback, $message = self::ERROR_DEFAULT)
{ {
if(!is_callable($callback)) { if (!is_callable($callback)) {
throw new \InvalidArgumentException("Second argument must be a valid callback. Given argument was not callable."); throw new \InvalidArgumentException("Second argument must be a valid callback. Given argument was not callable.");
} }
@ -528,9 +529,9 @@ class Validator
*/ */
public function rule($rule, $fields) public function rule($rule, $fields)
{ {
if(!isset(static::$_rules[$rule])) { if (!isset(static::$_rules[$rule])) {
$ruleMethod = 'validate' . ucfirst($rule); $ruleMethod = 'validate' . ucfirst($rule);
if(!method_exists($this, $ruleMethod)) { if (!method_exists($this, $ruleMethod)) {
throw new \InvalidArgumentException("Rule '" . $rule . "' has not been registered with " . __CLASS__ . "::addRule()."); throw new \InvalidArgumentException("Rule '" . $rule . "' has not been registered with " . __CLASS__ . "::addRule().");
} }
} }