mirror of
https://github.com/vlucas/valitron.git
synced 2025-12-31 07:01:54 +00:00
Update docblocks, consistency/missing types, etc
This commit is contained in:
parent
2120bacaf5
commit
57f2476642
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Valitron;
|
namespace Valitron;
|
||||||
|
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
@ -14,22 +15,64 @@ use InvalidArgumentException;
|
|||||||
*/
|
*/
|
||||||
class Validator
|
class Validator
|
||||||
{
|
{
|
||||||
protected $_fields = array();
|
/**
|
||||||
protected $_errors = array();
|
* @var string
|
||||||
protected $_validations = array();
|
*/
|
||||||
protected $_labels = array();
|
|
||||||
|
|
||||||
protected static $_lang;
|
|
||||||
protected static $_langDir;
|
|
||||||
protected static $_rules = array();
|
|
||||||
protected static $_ruleMessages = array();
|
|
||||||
|
|
||||||
const ERROR_DEFAULT = 'Invalid';
|
const ERROR_DEFAULT = 'Invalid';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $_fields = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $_errors = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $_validations = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $_labels = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected static $_lang;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected static $_langDir;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected static $_rules = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected static $_ruleMessages = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
protected $validUrlPrefixes = array('http://', 'https://', 'ftp://');
|
protected $validUrlPrefixes = array('http://', 'https://', 'ftp://');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup validation
|
* Setup validation
|
||||||
|
*
|
||||||
|
* @param array $data
|
||||||
|
* @param array $fields
|
||||||
|
* @param string $lang
|
||||||
|
* @param string $langDir
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function __construct($data, $fields = array(), $lang = null, $langDir = null)
|
public function __construct($data, $fields = array(), $lang = null, $langDir = null)
|
||||||
{
|
{
|
||||||
@ -58,6 +101,9 @@ class Validator
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get/set language to use for validation messages
|
* Get/set language to use for validation messages
|
||||||
|
*
|
||||||
|
* @param string $Lang
|
||||||
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function lang($lang = null)
|
public static function lang($lang = null)
|
||||||
{
|
{
|
||||||
@ -69,6 +115,9 @@ class Validator
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get/set language file path
|
* Get/set language file path
|
||||||
|
*
|
||||||
|
* @param string $dir
|
||||||
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function langDir($dir = null)
|
public static function langDir($dir = null)
|
||||||
{
|
{
|
||||||
@ -81,8 +130,8 @@ class Validator
|
|||||||
/**
|
/**
|
||||||
* Required field validator
|
* Required field validator
|
||||||
*
|
*
|
||||||
* @param $field
|
* @param string $field
|
||||||
* @param $value
|
* @param mixed $value
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function validateRequired($field, $value)
|
protected function validateRequired($field, $value)
|
||||||
@ -169,7 +218,7 @@ class Validator
|
|||||||
*
|
*
|
||||||
* @param string $field
|
* @param string $field
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param $params
|
* @param array $params
|
||||||
* @internal param array $fields
|
* @internal param array $fields
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
@ -190,7 +239,6 @@ class Validator
|
|||||||
* @param string $field
|
* @param string $field
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param array $params
|
* @param array $params
|
||||||
*
|
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
protected function validateLengthBetween($field, $value, $params)
|
protected function validateLengthBetween($field, $value, $params)
|
||||||
@ -246,7 +294,7 @@ class Validator
|
|||||||
*
|
*
|
||||||
* @param string $field
|
* @param string $field
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param $params
|
* @param array $params
|
||||||
* @internal param array $fields
|
* @internal param array $fields
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
@ -260,7 +308,7 @@ class Validator
|
|||||||
*
|
*
|
||||||
* @param string $field
|
* @param string $field
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param $params
|
* @param array $params
|
||||||
* @internal param array $fields
|
* @internal param array $fields
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
@ -274,7 +322,7 @@ class Validator
|
|||||||
*
|
*
|
||||||
* @param string $field
|
* @param string $field
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param $params
|
* @param array $params
|
||||||
* @internal param array $fields
|
* @internal param array $fields
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
@ -292,7 +340,7 @@ class Validator
|
|||||||
*
|
*
|
||||||
* @param string $field
|
* @param string $field
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param $params
|
* @param array $params
|
||||||
* @internal param array $fields
|
* @internal param array $fields
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
@ -421,7 +469,7 @@ class Validator
|
|||||||
*
|
*
|
||||||
* @param string $field
|
* @param string $field
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param $params
|
* @param array $params
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function validateRegex($field, $value, $params)
|
protected function validateRegex($field, $value, $params)
|
||||||
@ -446,7 +494,7 @@ class Validator
|
|||||||
*
|
*
|
||||||
* @param string $field
|
* @param string $field
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param $params
|
* @param array $params
|
||||||
* @internal param array $fields
|
* @internal param array $fields
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
@ -462,7 +510,7 @@ class Validator
|
|||||||
*
|
*
|
||||||
* @param string $field
|
* @param string $field
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param $params
|
* @param array $params
|
||||||
* @internal param array $fields
|
* @internal param array $fields
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
@ -478,7 +526,7 @@ class Validator
|
|||||||
*
|
*
|
||||||
* @param string $field
|
* @param string $field
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
* @param $params
|
* @param array $params
|
||||||
* @internal param array $fields
|
* @internal param array $fields
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
@ -506,7 +554,7 @@ class Validator
|
|||||||
* optionally filtered by an array
|
* optionally filtered by an array
|
||||||
*
|
*
|
||||||
* @param string $field
|
* @param string $field
|
||||||
* @param string $value
|
* @param mixed $value
|
||||||
* @param array $params
|
* @param array $params
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
@ -613,6 +661,8 @@ class Validator
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get array of fields and data
|
* Get array of fields and data
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function data()
|
public function data()
|
||||||
{
|
{
|
||||||
@ -636,8 +686,8 @@ class Validator
|
|||||||
/**
|
/**
|
||||||
* Add an error to error messages array
|
* Add an error to error messages array
|
||||||
*
|
*
|
||||||
* @param $field
|
* @param string $field
|
||||||
* @param $msg
|
* @param string $msg
|
||||||
* @param array $params
|
* @param array $params
|
||||||
*/
|
*/
|
||||||
public function error($field, $msg, array $params = array())
|
public function error($field, $msg, array $params = array())
|
||||||
@ -742,7 +792,7 @@ class Validator
|
|||||||
* Register new validation rule callback
|
* Register new validation rule callback
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param $callback
|
* @param mixed $callback
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @throws \InvalidArgumentException
|
* @throws \InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
@ -758,6 +808,10 @@ class Validator
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience method to add a single validation rule
|
* Convenience method to add a single validation rule
|
||||||
|
*
|
||||||
|
* @param string $fule
|
||||||
|
* @param array $fields
|
||||||
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function rule($rule, $fields)
|
public function rule($rule, $fields)
|
||||||
{
|
{
|
||||||
@ -784,7 +838,7 @@ class Validator
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $value
|
* @param string $value
|
||||||
* @internal param array $labels
|
* @internal param array $labels
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
@ -798,7 +852,7 @@ class Validator
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $labels
|
* @param array $labels
|
||||||
* @return $this
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function labels($labels = array())
|
public function labels($labels = array())
|
||||||
{
|
{
|
||||||
@ -807,9 +861,9 @@ class Validator
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $field
|
* @param string $field
|
||||||
* @param $msg
|
* @param string $msg
|
||||||
* @param $params
|
* @param array $params
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function checkAndSetLabel($field, $msg, $params)
|
private function checkAndSetLabel($field, $msg, $params)
|
||||||
@ -835,6 +889,7 @@ class Validator
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience method to add multiple validation rules with an array
|
* Convenience method to add multiple validation rules with an array
|
||||||
|
*
|
||||||
* @param array $rules
|
* @param array $rules
|
||||||
*/
|
*/
|
||||||
public function rules($rules)
|
public function rules($rules)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user