mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-04 18:42:40 +00:00
merging 1.3-misc into master
This commit is contained in:
parent
1f7eb18107
commit
15518b8c9a
17 changed files with 782 additions and 458 deletions
|
@ -1,27 +1,22 @@
|
|||
<?php
|
||||
/* SVN FILE: $Id$ */
|
||||
/**
|
||||
* String handling methods.
|
||||
*
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
|
||||
* Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
||||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
||||
* Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
|
||||
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
||||
* @link http://cakephp.org
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs
|
||||
* @since CakePHP(tm) v 1.2.0.5551
|
||||
* @version $Revision$
|
||||
* @modifiedby $LastChangedBy$
|
||||
* @lastmodified $Date$
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
||||
*/
|
||||
/**
|
||||
* String handling methods.
|
||||
|
@ -59,7 +54,9 @@ class String extends Object {
|
|||
|
||||
if (strpos($node, ':') !== false) {
|
||||
if (substr_count($node, '::')) {
|
||||
$node = str_replace('::', str_repeat(':0000', 8 - substr_count($node, ':')) . ':', $node);
|
||||
$node = str_replace(
|
||||
'::', str_repeat(':0000', 8 - substr_count($node, ':')) . ':', $node
|
||||
);
|
||||
}
|
||||
$node = explode(':', $node) ;
|
||||
$ipv6 = '' ;
|
||||
|
@ -111,14 +108,16 @@ class String extends Object {
|
|||
}
|
||||
|
||||
list($timeMid, $timeLow) = explode(' ', microtime());
|
||||
$uuid = sprintf("%08x-%04x-%04x-%02x%02x-%04x%08x", (int)$timeLow, (int)substr($timeMid, 2) & 0xffff,
|
||||
mt_rand(0, 0xfff) | 0x4000, mt_rand(0, 0x3f) | 0x80, mt_rand(0, 0xff), $pid, $node);
|
||||
$uuid = sprintf(
|
||||
"%08x-%04x-%04x-%02x%02x-%04x%08x", (int)$timeLow, (int)substr($timeMid, 2) & 0xffff,
|
||||
mt_rand(0, 0xfff) | 0x4000, mt_rand(0, 0x3f) | 0x80, mt_rand(0, 0xff), $pid, $node
|
||||
);
|
||||
|
||||
return $uuid;
|
||||
}
|
||||
/**
|
||||
* Tokenizes a string using $separator, ignoring any instance of $separator that appears between $leftBound
|
||||
* and $rightBound
|
||||
* Tokenizes a string using $separator, ignoring any instance of $separator that appears between
|
||||
* $leftBound and $rightBound
|
||||
*
|
||||
* @param string $data The data to tokenize
|
||||
* @param string $separator The token to split the data on
|
||||
|
@ -140,7 +139,11 @@ class String extends Object {
|
|||
|
||||
while ($offset <= $length) {
|
||||
$tmpOffset = -1;
|
||||
$offsets = array(strpos($data, $separator, $offset), strpos($data, $leftBound, $offset), strpos($data, $rightBound, $offset));
|
||||
$offsets = array(
|
||||
strpos($data, $separator, $offset),
|
||||
strpos($data, $leftBound, $offset),
|
||||
strpos($data, $rightBound, $offset)
|
||||
);
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
if ($offsets[$i] !== false && ($offsets[$i] < $tmpOffset || $tmpOffset == -1)) {
|
||||
$tmpOffset = $offsets[$i];
|
||||
|
@ -190,21 +193,22 @@ class String extends Object {
|
|||
return $data;
|
||||
}
|
||||
/**
|
||||
* Replaces variable placeholders inside a $str with any given $data. Each key in the $data array corresponds to a variable
|
||||
* placeholder name in $str. Example:
|
||||
*
|
||||
* Sample: String::insert('My name is :name and I am :age years old.', array('name' => 'Bob', '65'));
|
||||
* Returns: My name is Bob and I am 65 years old.
|
||||
* Replaces variable placeholders inside a $str with any given $data. Each key in the $data array
|
||||
* corresponds to a variable placeholder name in $str.
|
||||
* Example: String::insert(':name is :age years old.', array('name' => 'Bob', '65'));
|
||||
* Returns: Bob is 65 years old.
|
||||
*
|
||||
* Available $options are:
|
||||
* before: The character or string in front of the name of the variable placeholder (Defaults to ':')
|
||||
* after: The character or string after the name of the variable placeholder (Defaults to null)
|
||||
* escape: The character or string used to escape the before character / string (Defaults to '\')
|
||||
* format: A regex to use for matching variable placeholders. Default is: '/(?<!\\)\:%s/' (Overwrites before, after, breaks escape / clean)
|
||||
* format: A regex to use for matching variable placeholders. Default is: '/(?<!\\)\:%s/'
|
||||
* (Overwrites before, after, breaks escape / clean)
|
||||
* clean: A boolean or array with instructions for String::cleanInsert
|
||||
*
|
||||
* @param string $str A string containing variable placeholders
|
||||
* @param string $data A key => val array where each key stands for a placeholder variable name to be replaced with val
|
||||
* @param string $data A key => val array where each key stands for a placeholder variable name
|
||||
* to be replaced with val
|
||||
* @param string $options An array of options, see description above
|
||||
* @return string
|
||||
* @access public
|
||||
|
@ -247,6 +251,9 @@ class String extends Object {
|
|||
}
|
||||
$dataReplacements = array_combine($hashKeys, array_values($data));
|
||||
foreach ($dataReplacements as $tmpHash => $data) {
|
||||
if (is_array($data)) {
|
||||
$data = '';
|
||||
}
|
||||
$str = str_replace($tmpHash, $data, $str);
|
||||
}
|
||||
}
|
||||
|
@ -260,15 +267,17 @@ class String extends Object {
|
|||
return String::cleanInsert($str, $options);
|
||||
}
|
||||
/**
|
||||
* Cleans up a Set::insert formated string with given $options depending on the 'clean' key in $options. The default method used is
|
||||
* text but html is also available. The goal of this function is to replace all whitespace and uneeded markup around placeholders
|
||||
* that did not get replaced by Set::insert.
|
||||
* Cleans up a Set::insert formated string with given $options depending on the 'clean' key in
|
||||
* $options. The default method used is text but html is also available. The goal of this function
|
||||
* is to replace all whitespace and uneeded markup around placeholders that did not get replaced
|
||||
* by Set::insert.
|
||||
*
|
||||
* @param string $str
|
||||
* @param string $options
|
||||
* @return string
|
||||
* @access public
|
||||
* @static
|
||||
* @see Set::insert()
|
||||
*/
|
||||
function cleanInsert($str, $options) {
|
||||
$clean = $options['clean'];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue