Upgrade CakePHP from 2.2.5 to 2.9.5

This commit is contained in:
Brm Ko 2017-02-26 15:29:44 +01:00
parent 5a580df460
commit 235a541597
793 changed files with 60746 additions and 23753 deletions

View file

@ -2,277 +2,20 @@
/**
* Multibyte handling methods.
*
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.I18n
* @since CakePHP(tm) v 1.2.0.6833
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
if (!function_exists('mb_stripos')) {
/**
* Find position of first occurrence of a case-insensitive string.
*
* @param string $haystack The string from which to get the position of the first occurrence of $needle.
* @param string $needle The string to find in $haystack.
* @param integer $offset The position in $haystack to start searching.
* @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
* @return integer|boolean The numeric position of the first occurrence of $needle in the $haystack string, or false
* if $needle is not found.
*/
function mb_stripos($haystack, $needle, $offset = 0, $encoding = null) {
return Multibyte::stripos($haystack, $needle, $offset);
}
}
if (!function_exists('mb_stristr')) {
/**
* Finds first occurrence of a string within another, case insensitive.
*
* @param string $haystack The string from which to get the first occurrence of $needle.
* @param string $needle The string to find in $haystack.
* @param boolean $part Determines which portion of $haystack this function returns.
* If set to true, it returns all of $haystack from the beginning to the first occurrence of $needle.
* If set to false, it returns all of $haystack from the first occurrence of $needle to the end,
* Default value is false.
* @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
* @return string|boolean The portion of $haystack, or false if $needle is not found.
*/
function mb_stristr($haystack, $needle, $part = false, $encoding = null) {
return Multibyte::stristr($haystack, $needle, $part);
}
}
if (!function_exists('mb_strlen')) {
/**
* Get string length.
*
* @param string $string The string being checked for length.
* @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
* @return integer The number of characters in string $string having character encoding encoding.
* A multi-byte character is counted as 1.
*/
function mb_strlen($string, $encoding = null) {
return Multibyte::strlen($string);
}
}
if (!function_exists('mb_strpos')) {
/**
* Find position of first occurrence of a string.
*
* @param string $haystack The string being checked.
* @param string $needle The position counted from the beginning of haystack.
* @param integer $offset The search offset. If it is not specified, 0 is used.
* @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
* @return integer|boolean The numeric position of the first occurrence of $needle in the $haystack string.
* If $needle is not found, it returns false.
*/
function mb_strpos($haystack, $needle, $offset = 0, $encoding = null) {
return Multibyte::strpos($haystack, $needle, $offset);
}
}
if (!function_exists('mb_strrchr')) {
/**
* Finds the last occurrence of a character in a string within another.
*
* @param string $haystack The string from which to get the last occurrence of $needle.
* @param string $needle The string to find in $haystack.
* @param boolean $part Determines which portion of $haystack this function returns.
* If set to true, it returns all of $haystack from the beginning to the last occurrence of $needle.
* If set to false, it returns all of $haystack from the last occurrence of $needle to the end,
* Default value is false.
* @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
* @return string|boolean The portion of $haystack. or false if $needle is not found.
*/
function mb_strrchr($haystack, $needle, $part = false, $encoding = null) {
return Multibyte::strrchr($haystack, $needle, $part);
}
}
if (!function_exists('mb_strrichr')) {
/**
* Finds the last occurrence of a character in a string within another, case insensitive.
*
* @param string $haystack The string from which to get the last occurrence of $needle.
* @param string $needle The string to find in $haystack.
* @param boolean $part Determines which portion of $haystack this function returns.
* If set to true, it returns all of $haystack from the beginning to the last occurrence of $needle.
* If set to false, it returns all of $haystack from the last occurrence of $needle to the end,
* Default value is false.
* @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
* @return string|boolean The portion of $haystack. or false if $needle is not found.
*/
function mb_strrichr($haystack, $needle, $part = false, $encoding = null) {
return Multibyte::strrichr($haystack, $needle, $part);
}
}
if (!function_exists('mb_strripos')) {
/**
* Finds position of last occurrence of a string within another, case insensitive
*
* @param string $haystack The string from which to get the position of the last occurrence of $needle.
* @param string $needle The string to find in $haystack.
* @param integer $offset The position in $haystack to start searching.
* @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
* @return integer|boolean The numeric position of the last occurrence of $needle in the $haystack string,
* or false if $needle is not found.
*/
function mb_strripos($haystack, $needle, $offset = 0, $encoding = null) {
return Multibyte::strripos($haystack, $needle, $offset);
}
}
if (!function_exists('mb_strrpos')) {
/**
* Find position of last occurrence of a string in a string.
*
* @param string $haystack The string being checked, for the last occurrence of $needle.
* @param string $needle The string to find in $haystack.
* @param integer $offset May be specified to begin searching an arbitrary number of characters into the string.
* Negative values will stop searching at an arbitrary point prior to the end of the string.
* @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
* @return integer|boolean The numeric position of the last occurrence of $needle in the $haystack string.
* If $needle is not found, it returns false.
*/
function mb_strrpos($haystack, $needle, $offset = 0, $encoding = null) {
return Multibyte::strrpos($haystack, $needle, $offset);
}
}
if (!function_exists('mb_strstr')) {
/**
* Finds first occurrence of a string within another
*
* @param string $haystack The string from which to get the first occurrence of $needle.
* @param string $needle The string to find in $haystack
* @param boolean $part Determines which portion of $haystack this function returns.
* If set to true, it returns all of $haystack from the beginning to the first occurrence of $needle.
* If set to false, it returns all of $haystack from the first occurrence of $needle to the end,
* Default value is FALSE.
* @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
* @return string|boolean The portion of $haystack, or true if $needle is not found.
*/
function mb_strstr($haystack, $needle, $part = false, $encoding = null) {
return Multibyte::strstr($haystack, $needle, $part);
}
}
if (!function_exists('mb_strtolower')) {
/**
* Make a string lowercase
*
* @param string $string The string being lowercased.
* @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
* @return string with all alphabetic characters converted to lowercase.
*/
function mb_strtolower($string, $encoding = null) {
return Multibyte::strtolower($string);
}
}
if (!function_exists('mb_strtoupper')) {
/**
* Make a string uppercase
*
* @param string $string The string being uppercased.
* @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
* @return string with all alphabetic characters converted to uppercase.
*/
function mb_strtoupper($string, $encoding = null) {
return Multibyte::strtoupper($string);
}
}
if (!function_exists('mb_substr_count')) {
/**
* Count the number of substring occurrences
*
* @param string $haystack The string being checked.
* @param string $needle The string being found.
* @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
* @return integer The number of times the $needle substring occurs in the $haystack string.
*/
function mb_substr_count($haystack, $needle, $encoding = null) {
return Multibyte::substrCount($haystack, $needle);
}
}
if (!function_exists('mb_substr')) {
/**
* Get part of string
*
* @param string $string The string being checked.
* @param integer $start The first position used in $string.
* @param integer $length The maximum length of the returned string.
* @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
* @return string The portion of $string specified by the $string and $length parameters.
*/
function mb_substr($string, $start, $length = null, $encoding = null) {
return Multibyte::substr($string, $start, $length);
}
}
if (!function_exists('mb_encode_mimeheader')) {
/**
* Encode string for MIME header
*
* @param string $str The string being encoded
* @param string $charset specifies the name of the character set in which str is represented in.
* The default value is determined by the current NLS setting (mbstring.language).
* @param string $transfer_encoding specifies the scheme of MIME encoding.
* It should be either "B" (Base64) or "Q" (Quoted-Printable). Falls back to "B" if not given.
* @param string $linefeed specifies the EOL (end-of-line) marker with which
* mb_encode_mimeheader() performs line-folding
* (a » RFC term, the act of breaking a line longer than a certain length into multiple lines.
* The length is currently hard-coded to 74 characters). Falls back to "\r\n" (CRLF) if not given.
* @param integer $indent [definition unknown and appears to have no affect]
* @return string A converted version of the string represented in ASCII.
*/
function mb_encode_mimeheader($str, $charset = 'UTF-8', $transferEncoding = 'B', $linefeed = "\r\n", $indent = 1) {
return Multibyte::mimeEncode($str, $charset, $linefeed);
}
}
/**
* Multibyte handling methods.
*
@ -305,7 +48,7 @@ class Multibyte {
* Converts a multibyte character string
* to the decimal value of the character
*
* @param string $string
* @param string $string String to convert.
* @return array
*/
public static function utf8($string) {
@ -344,7 +87,7 @@ class Multibyte {
* Converts the decimal value of a multibyte character string
* to a string
*
* @param array $array
* @param array $array Values array.
* @return string
*/
public static function ascii($array) {
@ -370,8 +113,8 @@ class Multibyte {
*
* @param string $haystack The string from which to get the position of the first occurrence of $needle.
* @param string $needle The string to find in $haystack.
* @param integer $offset The position in $haystack to start searching.
* @return integer|boolean The numeric position of the first occurrence of $needle in the $haystack string,
* @param int $offset The position in $haystack to start searching.
* @return int|bool The numeric position of the first occurrence of $needle in the $haystack string,
* or false if $needle is not found.
*/
public static function stripos($haystack, $needle, $offset = 0) {
@ -388,11 +131,11 @@ class Multibyte {
*
* @param string $haystack The string from which to get the first occurrence of $needle.
* @param string $needle The string to find in $haystack.
* @param boolean $part Determines which portion of $haystack this function returns.
* @param bool $part Determines which portion of $haystack this function returns.
* If set to true, it returns all of $haystack from the beginning to the first occurrence of $needle.
* If set to false, it returns all of $haystack from the first occurrence of $needle to the end,
* Default value is false.
* @return integer|boolean The portion of $haystack, or false if $needle is not found.
* @return int|bool The portion of $haystack, or false if $needle is not found.
*/
public static function stristr($haystack, $needle, $part = false) {
$php = (PHP_VERSION < 5.3);
@ -448,7 +191,7 @@ class Multibyte {
* Get string length.
*
* @param string $string The string being checked for length.
* @return integer The number of characters in string $string
* @return int The number of characters in string $string
*/
public static function strlen($string) {
if (Multibyte::checkMultibyte($string)) {
@ -463,8 +206,8 @@ class Multibyte {
*
* @param string $haystack The string being checked.
* @param string $needle The position counted from the beginning of haystack.
* @param integer $offset The search offset. If it is not specified, 0 is used.
* @return integer|boolean The numeric position of the first occurrence of $needle in the $haystack string.
* @param int $offset The search offset. If it is not specified, 0 is used.
* @return int|bool The numeric position of the first occurrence of $needle in the $haystack string.
* If $needle is not found, it returns false.
*/
public static function strpos($haystack, $needle, $offset = 0) {
@ -506,11 +249,11 @@ class Multibyte {
*
* @param string $haystack The string from which to get the last occurrence of $needle.
* @param string $needle The string to find in $haystack.
* @param boolean $part Determines which portion of $haystack this function returns.
* @param bool $part Determines which portion of $haystack this function returns.
* If set to true, it returns all of $haystack from the beginning to the last occurrence of $needle.
* If set to false, it returns all of $haystack from the last occurrence of $needle to the end,
* Default value is false.
* @return string|boolean The portion of $haystack. or false if $needle is not found.
* @return string|bool The portion of $haystack. or false if $needle is not found.
*/
public static function strrchr($haystack, $needle, $part = false) {
$check = Multibyte::utf8($haystack);
@ -566,11 +309,11 @@ class Multibyte {
*
* @param string $haystack The string from which to get the last occurrence of $needle.
* @param string $needle The string to find in $haystack.
* @param boolean $part Determines which portion of $haystack this function returns.
* @param bool $part Determines which portion of $haystack this function returns.
* If set to true, it returns all of $haystack from the beginning to the last occurrence of $needle.
* If set to false, it returns all of $haystack from the last occurrence of $needle to the end,
* Default value is false.
* @return string|boolean The portion of $haystack. or false if $needle is not found.
* @return string|bool The portion of $haystack. or false if $needle is not found.
*/
public static function strrichr($haystack, $needle, $part = false) {
$check = Multibyte::strtoupper($haystack);
@ -628,8 +371,8 @@ class Multibyte {
*
* @param string $haystack The string from which to get the position of the last occurrence of $needle.
* @param string $needle The string to find in $haystack.
* @param integer $offset The position in $haystack to start searching.
* @return integer|boolean The numeric position of the last occurrence of $needle in the $haystack string,
* @param int $offset The position in $haystack to start searching.
* @return int|bool The numeric position of the last occurrence of $needle in the $haystack string,
* or false if $needle is not found.
*/
public static function strripos($haystack, $needle, $offset = 0) {
@ -678,9 +421,9 @@ class Multibyte {
*
* @param string $haystack The string being checked, for the last occurrence of $needle.
* @param string $needle The string to find in $haystack.
* @param integer $offset May be specified to begin searching an arbitrary number of characters into the string.
* @param int $offset May be specified to begin searching an arbitrary number of characters into the string.
* Negative values will stop searching at an arbitrary point prior to the end of the string.
* @return integer|boolean The numeric position of the last occurrence of $needle in the $haystack string.
* @return int|bool The numeric position of the last occurrence of $needle in the $haystack string.
* If $needle is not found, it returns false.
*/
public static function strrpos($haystack, $needle, $offset = 0) {
@ -728,11 +471,11 @@ class Multibyte {
*
* @param string $haystack The string from which to get the first occurrence of $needle.
* @param string $needle The string to find in $haystack
* @param boolean $part Determines which portion of $haystack this function returns.
* @param bool $part Determines which portion of $haystack this function returns.
* If set to true, it returns all of $haystack from the beginning to the first occurrence of $needle.
* If set to false, it returns all of $haystack from the first occurrence of $needle to the end,
* Default value is FALSE.
* @return string|boolean The portion of $haystack, or true if $needle is not found.
* @return string|bool The portion of $haystack, or true if $needle is not found.
*/
public static function strstr($haystack, $needle, $part = false) {
$php = (PHP_VERSION < 5.3);
@ -807,7 +550,7 @@ class Multibyte {
$matched = true;
} else {
$matched = false;
$keys = self::_find($char, 'upper');
$keys = static::_find($char, 'upper');
if (!empty($keys)) {
foreach ($keys as $key => $value) {
@ -853,7 +596,7 @@ class Multibyte {
} else {
$matched = false;
$keys = self::_find($char);
$keys = static::_find($char);
$keyCount = count($keys);
if (!empty($keys)) {
@ -919,7 +662,7 @@ class Multibyte {
*
* @param string $haystack The string being checked.
* @param string $needle The string being found.
* @return integer The number of times the $needle substring occurs in the $haystack string.
* @return int The number of times the $needle substring occurs in the $haystack string.
*/
public static function substrCount($haystack, $needle) {
$count = 0;
@ -953,8 +696,8 @@ class Multibyte {
* Get part of string
*
* @param string $string The string being checked.
* @param integer $start The first position used in $string.
* @param integer $length The maximum length of the returned string.
* @param int $start The first position used in $string.
* @param int $length The maximum length of the returned string.
* @return string The portion of $string specified by the $string and $length parameters.
*/
public static function substr($string, $start, $length = null) {
@ -985,7 +728,7 @@ class Multibyte {
*
* @param string $string value to encode
* @param string $charset charset to use for encoding. defaults to UTF-8
* @param string $newline
* @param string $newline Newline string.
* @return string
*/
public static function mimeEncode($string, $charset = null, $newline = "\r\n") {
@ -1004,7 +747,7 @@ class Multibyte {
$length = 75 - strlen($start) - strlen($end);
$length = $length - ($length % 4);
if ($charset == 'UTF-8') {
if ($charset === 'UTF-8') {
$parts = array();
$maxchars = floor(($length * 3) / 4);
$stringLength = strlen($string);
@ -1031,7 +774,7 @@ class Multibyte {
/**
* Return the Code points range for Unicode characters
*
* @param integer $decimal
* @param int $decimal Decimal value.
* @return string
*/
protected static function _codepoint($decimal) {
@ -1072,44 +815,44 @@ class Multibyte {
} else {
$return = false;
}
self::$_codeRange[$decimal] = $return;
static::$_codeRange[$decimal] = $return;
return $return;
}
/**
* Find the related code folding values for $char
*
* @param integer $char decimal value of character
* @param string $type
* @param int $char decimal value of character
* @param string $type Type 'lower' or 'upper'. Defaults to 'lower'.
* @return array
*/
protected static function _find($char, $type = 'lower') {
$found = array();
if (!isset(self::$_codeRange[$char])) {
$range = self::_codepoint($char);
if (!isset(static::$_codeRange[$char])) {
$range = static::_codepoint($char);
if ($range === false) {
return null;
return array();
}
if (!Configure::configured('_cake_core_')) {
App::uses('PhpReader', 'Configure');
Configure::config('_cake_core_', new PhpReader(CAKE . 'Config' . DS));
}
Configure::load('unicode' . DS . 'casefolding' . DS . $range, '_cake_core_');
self::$_caseFold[$range] = Configure::read($range);
static::$_caseFold[$range] = Configure::read($range);
Configure::delete($range);
}
if (!self::$_codeRange[$char]) {
return null;
if (!static::$_codeRange[$char]) {
return array();
}
self::$_table = self::$_codeRange[$char];
$count = count(self::$_caseFold[self::$_table]);
static::$_table = static::$_codeRange[$char];
$count = count(static::$_caseFold[static::$_table]);
for ($i = 0; $i < $count; $i++) {
if ($type === 'lower' && self::$_caseFold[self::$_table][$i][$type][0] === $char) {
$found[] = self::$_caseFold[self::$_table][$i];
} elseif ($type === 'upper' && self::$_caseFold[self::$_table][$i][$type] === $char) {
$found[] = self::$_caseFold[self::$_table][$i];
if ($type === 'lower' && static::$_caseFold[static::$_table][$i][$type][0] === $char) {
$found[] = static::$_caseFold[static::$_table][$i];
} elseif ($type === 'upper' && static::$_caseFold[static::$_table][$i][$type] === $char) {
$found[] = static::$_caseFold[static::$_table][$i];
}
}
return $found;
@ -1117,13 +860,14 @@ class Multibyte {
/**
* Check the $string for multibyte characters
* @param string $string value to test
* @return boolean
*
* @param string $string Value to test.
* @return bool
*/
public static function checkMultibyte($string) {
$length = strlen($string);
for ($i = 0; $i < $length; $i++ ) {
for ($i = 0; $i < $length; $i++) {
$value = ord(($string[$i]));
if ($value > 128) {
return true;