Replacing self with static due to PHP5.3+. Following #7040.

This commit is contained in:
Mark Scherer 2015-07-21 10:22:53 +02:00
parent 27e40f084d
commit 52e79987a2
53 changed files with 998 additions and 998 deletions

View file

@ -58,7 +58,7 @@ class Validation {
*/
public static function notEmpty($check) {
trigger_error('Validation::notEmpty() is deprecated. Use Validation::notBlank() instead.', E_USER_DEPRECATED);
return self::notBlank($check);
return static::notBlank($check);
}
/**
@ -74,13 +74,13 @@ class Validation {
*/
public static function notBlank($check) {
if (is_array($check)) {
extract(self::_defaults($check));
extract(static::_defaults($check));
}
if (empty($check) && (string)$check !== '0') {
return false;
}
return self::_check($check, '/[^\s]+/m');
return static::_check($check, '/[^\s]+/m');
}
/**
@ -96,13 +96,13 @@ class Validation {
*/
public static function alphaNumeric($check) {
if (is_array($check)) {
extract(self::_defaults($check));
extract(static::_defaults($check));
}
if (empty($check) && $check != '0') {
return false;
}
return self::_check($check, '/^[\p{Ll}\p{Lm}\p{Lo}\p{Lt}\p{Lu}\p{Nd}]+$/Du');
return static::_check($check, '/^[\p{Ll}\p{Lm}\p{Lo}\p{Lt}\p{Lu}\p{Nd}]+$/Du');
}
/**
@ -131,7 +131,7 @@ class Validation {
* @deprecated Deprecated 2.6. Use Validator::lengthBetween() instead.
*/
public static function between($check, $min, $max) {
return self::lengthBetween($check, $min, $max);
return static::lengthBetween($check, $min, $max);
}
/**
@ -146,9 +146,9 @@ class Validation {
*/
public static function blank($check) {
if (is_array($check)) {
extract(self::_defaults($check));
extract(static::_defaults($check));
}
return !self::_check($check, '/[^\\s]/');
return !static::_check($check, '/[^\\s]/');
}
/**
@ -167,7 +167,7 @@ class Validation {
*/
public static function cc($check, $type = 'fast', $deep = false, $regex = null) {
if (is_array($check)) {
extract(self::_defaults($check));
extract(static::_defaults($check));
}
$check = str_replace(array('-', ' '), '', $check);
@ -176,8 +176,8 @@ class Validation {
}
if ($regex !== null) {
if (self::_check($check, $regex)) {
return self::luhn($check, $deep);
if (static::_check($check, $regex)) {
return static::luhn($check, $deep);
}
}
$cards = array(
@ -205,23 +205,23 @@ class Validation {
foreach ($type as $value) {
$regex = $cards['all'][strtolower($value)];
if (self::_check($check, $regex)) {
return self::luhn($check, $deep);
if (static::_check($check, $regex)) {
return static::luhn($check, $deep);
}
}
} elseif ($type === 'all') {
foreach ($cards['all'] as $value) {
$regex = $value;
if (self::_check($check, $regex)) {
return self::luhn($check, $deep);
if (static::_check($check, $regex)) {
return static::luhn($check, $deep);
}
}
} else {
$regex = $cards['fast'];
if (self::_check($check, $regex)) {
return self::luhn($check, $deep);
if (static::_check($check, $regex)) {
return static::luhn($check, $deep);
}
}
return false;
@ -282,7 +282,7 @@ class Validation {
}
break;
default:
self::$errors[] = __d('cake_dev', 'You must define the $operator parameter for %s', 'Validation::comparison()');
static::$errors[] = __d('cake_dev', 'You must define the $operator parameter for %s', 'Validation::comparison()');
}
return false;
}
@ -297,13 +297,13 @@ class Validation {
*/
public static function custom($check, $regex = null) {
if (is_array($check)) {
extract(self::_defaults($check));
extract(static::_defaults($check));
}
if ($regex === null) {
self::$errors[] = __d('cake_dev', 'You must define a regular expression for %s', 'Validation::custom()');
static::$errors[] = __d('cake_dev', 'You must define a regular expression for %s', 'Validation::custom()');
return false;
}
return self::_check($check, $regex);
return static::_check($check, $regex);
}
/**
@ -332,7 +332,7 @@ class Validation {
*/
public static function date($check, $format = 'ymd', $regex = null) {
if ($regex !== null) {
return self::_check($check, $regex);
return static::_check($check, $regex);
}
$month = '(0[123456789]|10|11|12)';
$separator = '([- /.])';
@ -366,7 +366,7 @@ class Validation {
$format = (is_array($format)) ? array_values($format) : array($format);
foreach ($format as $key) {
if (self::_check($check, $regex[$key]) === true) {
if (static::_check($check, $regex[$key]) === true) {
return true;
}
}
@ -391,7 +391,7 @@ class Validation {
if (!empty($parts) && count($parts) > 1) {
$time = array_pop($parts);
$date = implode(' ', $parts);
$valid = self::date($date, $dateFormat, $regex) && self::time($time);
$valid = static::date($date, $dateFormat, $regex) && static::time($time);
}
return $valid;
}
@ -405,7 +405,7 @@ class Validation {
* @return bool Success
*/
public static function time($check) {
return self::_check($check, '%^((0?[1-9]|1[012])(:[0-5]\d){0,2} ?([AP]M|[ap]m))$|^([01]\d|2[0-3])(:[0-5]\d){0,2}$%');
return static::_check($check, '%^((0?[1-9]|1[012])(:[0-5]\d){0,2} ?([AP]M|[ap]m))$|^([01]\d|2[0-3])(:[0-5]\d){0,2}$%');
}
/**
@ -461,7 +461,7 @@ class Validation {
$check = str_replace($data['thousands_sep'], '', $check);
$check = str_replace($data['decimal_point'], '.', $check);
return self::_check($check, $regex);
return static::_check($check, $regex);
}
/**
@ -477,18 +477,18 @@ class Validation {
*/
public static function email($check, $deep = false, $regex = null) {
if (is_array($check)) {
extract(self::_defaults($check));
extract(static::_defaults($check));
}
if ($regex === null) {
$regex = '/^[\p{L}0-9!#$%&\'*+\/=?^_`{|}~-]+(?:\.[\p{L}0-9!#$%&\'*+\/=?^_`{|}~-]+)*@' . self::$_pattern['hostname'] . '$/ui';
$regex = '/^[\p{L}0-9!#$%&\'*+\/=?^_`{|}~-]+(?:\.[\p{L}0-9!#$%&\'*+\/=?^_`{|}~-]+)*@' . static::$_pattern['hostname'] . '$/ui';
}
$return = self::_check($check, $regex);
$return = static::_check($check, $regex);
if ($deep === false || $deep === null) {
return $return;
}
if ($return === true && preg_match('/@(' . self::$_pattern['hostname'] . ')$/i', $check, $regs)) {
if ($return === true && preg_match('/@(' . static::$_pattern['hostname'] . ')$/i', $check, $regs)) {
if (function_exists('getmxrr') && getmxrr($regs[1], $mxhosts)) {
return true;
}
@ -520,7 +520,7 @@ class Validation {
*/
public static function extension($check, $extensions = array('gif', 'jpeg', 'png', 'jpg')) {
if (is_array($check)) {
return self::extension(array_shift($check), $extensions);
return static::extension(array_shift($check), $extensions);
}
$extension = strtolower(pathinfo($check, PATHINFO_EXTENSION));
foreach ($extensions as $value) {
@ -586,7 +586,7 @@ class Validation {
} else {
$regex = '/^(?!\x{00a2})\p{Sc}?' . $money . '$/u';
}
return self::_check($check, $regex);
return static::_check($check, $regex);
}
/**
@ -654,7 +654,7 @@ class Validation {
*/
public static function naturalNumber($check, $allowZero = false) {
$regex = $allowZero ? '/^(?:0|[1-9][0-9]*)$/' : '/^[1-9][0-9]*$/';
return self::_check($check, $regex);
return static::_check($check, $regex);
}
/**
@ -667,7 +667,7 @@ class Validation {
*/
public static function phone($check, $regex = null, $country = 'all') {
if (is_array($check)) {
extract(self::_defaults($check));
extract(static::_defaults($check));
}
if ($regex === null) {
@ -697,9 +697,9 @@ class Validation {
}
}
if (empty($regex)) {
return self::_pass('phone', $check, $country);
return static::_pass('phone', $check, $country);
}
return self::_check($check, $regex);
return static::_check($check, $regex);
}
/**
@ -712,7 +712,7 @@ class Validation {
*/
public static function postal($check, $regex = null, $country = 'us') {
if (is_array($check)) {
extract(self::_defaults($check));
extract(static::_defaults($check));
}
if ($regex === null) {
@ -738,9 +738,9 @@ class Validation {
}
}
if (empty($regex)) {
return self::_pass('postal', $check, $country);
return static::_pass('postal', $check, $country);
}
return self::_check($check, $regex);
return static::_check($check, $regex);
}
/**
@ -774,7 +774,7 @@ class Validation {
*/
public static function ssn($check, $regex = null, $country = null) {
if (is_array($check)) {
extract(self::_defaults($check));
extract(static::_defaults($check));
}
if ($regex === null) {
@ -791,9 +791,9 @@ class Validation {
}
}
if (empty($regex)) {
return self::_pass('ssn', $check, $country);
return static::_pass('ssn', $check, $country);
}
return self::_check($check, $regex);
return static::_check($check, $regex);
}
/**
@ -814,14 +814,14 @@ class Validation {
* @return bool Success
*/
public static function url($check, $strict = false) {
self::_populateIp();
static::_populateIp();
$validChars = '([' . preg_quote('!"$&\'()*+,-.@_:;=~[]') . '\/0-9\p{L}\p{N}]|(%[0-9a-f]{2}))';
$regex = '/^(?:(?:https?|ftps?|sftp|file|news|gopher):\/\/)' . (!empty($strict) ? '' : '?') .
'(?:' . self::$_pattern['IPv4'] . '|\[' . self::$_pattern['IPv6'] . '\]|' . self::$_pattern['hostname'] . ')(?::[1-9][0-9]{0,4})?' .
'(?:' . static::$_pattern['IPv4'] . '|\[' . static::$_pattern['IPv6'] . '\]|' . static::$_pattern['hostname'] . ')(?::[1-9][0-9]{0,4})?' .
'(?:\/?|\/' . $validChars . '*)?' .
'(?:\?' . $validChars . '*)?' .
'(?:#' . $validChars . '*)?$/iu';
return self::_check($check, $regex);
return static::_check($check, $regex);
}
/**
@ -863,7 +863,7 @@ class Validation {
*/
public static function uuid($check) {
$regex = '/^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[0-5][a-fA-F0-9]{3}-[089aAbB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}$/';
return self::_check($check, $regex);
return static::_check($check, $regex);
}
/**
@ -912,7 +912,7 @@ class Validation {
* @return void
*/
protected static function _defaults($params) {
self::_reset();
static::_reset();
$defaults = array(
'check' => null,
'regex' => null,
@ -937,7 +937,7 @@ class Validation {
*/
public static function luhn($check, $deep = false) {
if (is_array($check)) {
extract(self::_defaults($check));
extract(static::_defaults($check));
}
if ($deep !== true) {
return true;
@ -981,7 +981,7 @@ class Validation {
}
if (is_string($mimeTypes)) {
return self::_check($mime, $mimeTypes);
return static::_check($mime, $mimeTypes);
}
foreach ($mimeTypes as $key => $val) {
@ -1008,7 +1008,7 @@ class Validation {
}
$filesize = filesize($check);
return self::comparison($filesize, $operator, $size);
return static::comparison($filesize, $operator, $size);
}
/**
@ -1032,7 +1032,7 @@ class Validation {
* @return void
*/
protected static function _populateIp() {
if (!isset(self::$_pattern['IPv6'])) {
if (!isset(static::$_pattern['IPv6'])) {
$pattern = '((([0-9A-Fa-f]{1,4}:){7}(([0-9A-Fa-f]{1,4})|:))|(([0-9A-Fa-f]{1,4}:){6}';
$pattern .= '(:|((25[0-5]|2[0-4]\d|[01]?\d{1,2})(\.(25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})';
$pattern .= '|(:[0-9A-Fa-f]{1,4})))|(([0-9A-Fa-f]{1,4}:){5}((:((25[0-5]|2[0-4]\d|[01]?\d{1,2})';
@ -1048,11 +1048,11 @@ class Validation {
$pattern .= '\d|[01]?\d{1,2})(\.(25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})?)|((:[0-9A-Fa-f]{1,4})';
$pattern .= '{1,2})))|(((25[0-5]|2[0-4]\d|[01]?\d{1,2})(\.(25[0-5]|2[0-4]\d|[01]?\d{1,2})){3})))(%.+)?';
self::$_pattern['IPv6'] = $pattern;
static::$_pattern['IPv6'] = $pattern;
}
if (!isset(self::$_pattern['IPv4'])) {
if (!isset(static::$_pattern['IPv4'])) {
$pattern = '(?:(?:25[0-5]|2[0-4][0-9]|(?:(?:1[0-9])?|[1-9]?)[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|(?:(?:1[0-9])?|[1-9]?)[0-9])';
self::$_pattern['IPv4'] = $pattern;
static::$_pattern['IPv4'] = $pattern;
}
}
@ -1062,7 +1062,7 @@ class Validation {
* @return void
*/
protected static function _reset() {
self::$errors = array();
static::$errors = array();
}
}