当前位置: 首页>>代码示例>>PHP>>正文


PHP string::wrap方法代码示例

本文整理汇总了PHP中string::wrap方法的典型用法代码示例。如果您正苦于以下问题:PHP string::wrap方法的具体用法?PHP string::wrap怎么用?PHP string::wrap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在string的用法示例。


在下文中一共展示了string::wrap方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _S

/**
 * Wraps provided native string in a managed string instance.
 *
 * On providing managed string instance it's cloned.
 *
 * If parameter $useIfNotAString is containing string and $string is not a
 * string, then the former is used to replace the latter. This is available
 * for conveniently validating parameters expected to be string.
 *
 * @param string $string native or managed string to wrap/clone
 * @param string $encoding encoding of provided string, ignored on cloning
 * @param string $useIfNotAString if $string is not a string this string is used instead
 * @return \de\toxa\txf\string managed string instance
 */
function _S($string, $encoding = null, $useIfNotAString = null)
{
    return string::wrap($string, $encoding, $useIfNotAString);
}
开发者ID:cepharum,项目名称:txf,代码行数:18,代码来源:shortcuts.php

示例2: describe

 /**
  * Describes provided value.
  *
  * This method is returning string containing provided value extended by its
  * type and length/size. If value is exceeding length of 30 characters it's
  * being shortened.
  *
  * @param mixed $value value to describe
  * @param boolean $includeType true to have type included in description
  * @param boolean $fullSize true to disable shortening of longer values
  * @param void $_internal
  * @return string description of provided value
  */
 public static function describe($value, $includeType = true, $fullSize = false, $_internal = null)
 {
     $type = gettype($value);
     switch ($type) {
         case 'string':
             $type = 'string[' . strlen($value) . ']';
             $value = '"' . ($fullSize ? $value : string::wrap($value)->limit(40)) . '"';
             break;
         case 'boolean':
             $type = 'boolean';
             $value = $value ? 'true' : 'false';
             break;
         case 'unknown':
             $type = 'unknown';
             $value = '?';
             break;
         case 'array':
             $type = 'array[' . count($value) . ']';
             if ($_internal > 10) {
                 $value = '*MAX-DEPTH*';
             } else {
                 $isRegular = static::isRegularArray($value);
                 $out = '';
                 foreach ($value as $key => $item) {
                     $out .= $out !== '' ? ', ' : '[';
                     if (!$isRegular) {
                         $out .= (is_integer($key) ? $key : '"' . $key . '"') . ' => ';
                     }
                     $out .= static::describe($item, $includeType, $fullSize, $_internal + 1);
                 }
                 $value = $out . ']';
             }
             break;
         case 'object':
             $type = get_class($value);
             // can't use is_callable() here due to occasional use of __call() in inspected objects
             $inspector = new \ReflectionObject($value);
             if ($inspector->hasMethod('__describe')) {
                 list($type, $value) = $value->__describe();
             } else {
                 if ($inspector->hasMethod('__toString')) {
                     $value = strval($value);
                 } else {
                     $value = '[no-string]';
                 }
             }
             if (!$fullSize) {
                 $value = string::wrap($value)->limit(40);
             }
             break;
     }
     if ($includeType) {
         return "({$type}) {$value}";
     }
     return strval($value);
 }
开发者ID:cepharum,项目名称:txf,代码行数:69,代码来源:data.php


注:本文中的string::wrap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。