2005-06-18 23:26:35 +00:00
|
|
|
<?php
|
2005-08-21 06:49:02 +00:00
|
|
|
/* SVN FILE: $Id$ */
|
2005-07-04 01:45:26 +00:00
|
|
|
/**
|
2005-10-18 22:27:39 +00:00
|
|
|
* String handling methods.
|
|
|
|
*
|
2005-07-04 01:45:26 +00:00
|
|
|
*
|
2005-08-21 06:49:02 +00:00
|
|
|
* PHP versions 4 and 5
|
2005-07-04 01:45:26 +00:00
|
|
|
*
|
2007-02-02 10:39:45 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
|
|
|
|
* Copyright 2005-2007, Cake Software Foundation, Inc.
|
2006-05-26 05:29:17 +00:00
|
|
|
* 1785 E. Sahara Avenue, Suite 490-204
|
|
|
|
* Las Vegas, Nevada 89104
|
2005-07-04 01:45:26 +00:00
|
|
|
*
|
2005-12-23 21:57:26 +00:00
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
2006-05-26 05:29:17 +00:00
|
|
|
* @filesource
|
2007-02-02 10:39:45 +00:00
|
|
|
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
|
|
|
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
|
2006-05-26 05:29:17 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.libs
|
2007-02-02 10:39:45 +00:00
|
|
|
* @since CakePHP(tm) v 0.2.9
|
2006-05-26 05:29:17 +00:00
|
|
|
* @version $Revision$
|
|
|
|
* @modifiedby $LastChangedBy$
|
|
|
|
* @lastmodified $Date$
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
2005-07-04 01:45:26 +00:00
|
|
|
*/
|
|
|
|
/**
|
2005-10-18 22:27:39 +00:00
|
|
|
* String handling methods.
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
2005-07-04 01:45:26 +00:00
|
|
|
*
|
2006-05-26 05:29:17 +00:00
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.cake.libs
|
2005-07-04 01:45:26 +00:00
|
|
|
*/
|
2007-08-20 01:58:44 +00:00
|
|
|
class String extends Object {
|
2006-02-18 23:42:21 +00:00
|
|
|
/**
|
2007-08-20 01:58:44 +00:00
|
|
|
* Gets a reference to the String object instance
|
2005-12-27 03:33:44 +00:00
|
|
|
*
|
2007-08-20 01:58:44 +00:00
|
|
|
* @return object String instance
|
2007-05-21 19:38:39 +00:00
|
|
|
* @access public
|
|
|
|
* @static
|
2005-12-27 03:33:44 +00:00
|
|
|
*/
|
2007-08-20 01:58:44 +00:00
|
|
|
function &getInstance() {
|
|
|
|
static $instance = array();
|
|
|
|
|
|
|
|
if (!isset($instance[0]) || !$instance[0]) {
|
|
|
|
$instance[0] =& new String();
|
|
|
|
}
|
|
|
|
return $instance[0];
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2006-02-18 23:42:21 +00:00
|
|
|
/**
|
2007-08-20 01:58:44 +00:00
|
|
|
* Generate a random UUID
|
2005-12-27 03:33:44 +00:00
|
|
|
*
|
2007-08-20 01:58:44 +00:00
|
|
|
* @see http://www.ietf.org/rfc/rfc4122.txt
|
|
|
|
* @return RFC 4122 UUID
|
2007-05-21 19:38:39 +00:00
|
|
|
* @static
|
2005-12-27 03:33:44 +00:00
|
|
|
*/
|
2007-08-20 01:58:44 +00:00
|
|
|
function uuid() {
|
|
|
|
$node = env('SERVER_ADDR');
|
|
|
|
|
|
|
|
if(empty($node)) {
|
|
|
|
$host = env('HOSTNAME');
|
|
|
|
|
|
|
|
if (empty($host)) {
|
|
|
|
$host = env('HOST');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($host)) {
|
|
|
|
$node = ip2long('127.0.0.1');
|
|
|
|
} else {
|
|
|
|
$ip = gethostbyname($host);
|
|
|
|
if ($ip === $host) {
|
|
|
|
$node = crc32($host);
|
|
|
|
} else {
|
|
|
|
$node = ip2long($ip);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$node = ip2long($node);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (function_exists('zend_thread_id')) {
|
|
|
|
$pid = zend_thread_id();
|
|
|
|
} else {
|
|
|
|
$pid = getmypid();
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2007-08-20 01:58:44 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
return $uuid;
|
2006-05-26 05:29:17 +00:00
|
|
|
}
|
2005-06-18 23:26:35 +00:00
|
|
|
}
|
|
|
|
?>
|