本文整理汇总了PHP中Horde_Util::cloneObject方法的典型用法代码示例。如果您正苦于以下问题:PHP Horde_Util::cloneObject方法的具体用法?PHP Horde_Util::cloneObject怎么用?PHP Horde_Util::cloneObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Horde_Util
的用法示例。
在下文中一共展示了Horde_Util::cloneObject方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: convertCharset
/**
* Converts a string from one charset to another.
*
* Uses the iconv or the mbstring extensions.
* The original string is returned if conversion failed or none
* of the extensions were available.
*
* @param mixed $input The data to be converted. If $input is an an
* array, the array's values get converted
* recursively.
* @param string $from The string's current charset.
* @param string $to The charset to convert the string to.
* @param boolean $force Force conversion?
*
* @return mixed The converted input data.
*/
public static function convertCharset($input, $from, $to, $force = false)
{
/* Don't bother converting numbers. */
if (is_numeric($input)) {
return $input;
}
/* If the from and to character sets are identical, return now. */
if (!$force && $from == $to) {
return $input;
}
$from = self::lower($from);
$to = self::lower($to);
if (!$force && $from == $to) {
return $input;
}
if (is_array($input)) {
$tmp = array();
reset($input);
while (list($key, $val) = each($input)) {
$tmp[self::_convertCharset($key, $from, $to)] = self::convertCharset($val, $from, $to, $force);
}
return $tmp;
}
if (is_object($input)) {
// PEAR_Error/Exception objects are almost guaranteed to contain
// recursion, which will cause a segfault in PHP. We should never
// reach this line, but add a check.
if ($input instanceof Exception || $input instanceof PEAR_Error) {
return '';
}
$input = Horde_Util::cloneObject($input);
$vars = get_object_vars($input);
while (list($key, $val) = each($vars)) {
$input->{$key} = self::convertCharset($val, $from, $to, $force);
}
return $input;
}
if (!is_string($input)) {
return $input;
}
return self::_convertCharset($input, $from, $to);
}
示例2: getPart
/**
* Retrieve a specific MIME part.
*
* @param string $id The MIME_Part ID string.
*
* @return MIME_Part The MIME_Part requested, or false if the part
* doesn't exist.
*/
public function getPart($id)
{
$mimeid = $this->getMIMEId();
/* This will convert '#.0' to simply '#', which is how the part is
* internally stored. */
$search_id = $id;
if (($str = strrchr($id, '.')) && $str == '.0') {
$search_id = substr($search_id, 0, -2);
}
/* Return this part if:
1) There is only one part (e.g. the MIME ID is 0, or the
MIME ID is 1 and there are no subparts.
2) $id matches this parts MIME ID. */
if ($search_id == 0 || $search_id == 1 && !count($this->_parts) || !empty($mimeid) && $search_id == $mimeid) {
$part = $this;
} else {
$part = $this->_partFind($id, $this->_parts);
}
if ($part && $search_id != $id && $part->getType() == 'message/rfc822') {
$ret_part = Horde_Util::cloneObject($part);
$ret_part->_parts = array();
return $ret_part;
}
return $part;
}