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


PHP string::isString方法代码示例

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


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

示例1: __construct

 /**
  * @param array $set array to be managed
  */
 public function __construct($type, $set = null)
 {
     if (is_callable($type)) {
         $this->type = $type;
     } else {
         if (!string::isString($type)) {
             throw new \InvalidArgumentException('invalid type specifier');
         } else {
             $this->type = trim(_S($type)->asUtf8);
         }
     }
     if (func_num_args() > 1) {
         parent::__construct($this->filterByType($set, false));
     } else {
         parent::__construct();
     }
 }
开发者ID:cepharum,项目名称:txf,代码行数:20,代码来源:typed_set.php

示例2: isValidClassName

 /**
  * Detects if provided string contains valid class name.
  *
  * This check is testing syntactical validity, only. It doesn't check
  * whether related class actually exists or not.
  *
  * @param string $name class name to check
  * @return boolean true on a valid class name, false otherwise
  */
 public static function isValidClassName(&$name)
 {
     if (string::isString($name)) {
         $name = trim($name);
         return preg_match('/^([a-z_][a-z0-9_]*\\\\)*[a-z_][a-z0-9_]*$/i', $name);
     }
     return false;
 }
开发者ID:cepharum,项目名称:txf,代码行数:17,代码来源:txf.php

示例3: array2Xml

 /**
  * Recursively converts provided value to XML thread.
  *
  * @param mixed $set data to convert
  * @param string $indent indentation to use on value
  * @param string $name name used to wrap around converted data
  * @return string XML notation of provided data
  */
 protected static function array2Xml($set, $indent = null, $name = 'root')
 {
     $name = _S($name)->asUtf8;
     if (!xml::isValidName($name)) {
         throw new \UnexpectedValueException('invalid element name cannot be converted to XML');
     }
     if (is_array($set)) {
         // there are subordinated elements to be converted into XML nodes
         //
         // collect hash-like and set-like elements separately
         $separateName = $sameName = array();
         foreach ($set as $subName => $sub) {
             if (ctype_digit(trim($subName))) {
                 $sameName[] = static::array2Xml($sub, $indent, $name);
             } else {
                 $separateName[$subName] = static::array2Xml($sub, "{$indent} ", $subName);
             }
         }
         // exclude to have both sorts of elements (as it can't be mapped into XML notation)
         if (count($separateName) && count($sameName)) {
             throw new \UnexpectedValueException('unsupported state of mixing hash-like and set-like array in converting to XML');
         }
         // convert elements to XML
         if (count($separateName)) {
             return "{$indent}<{$name}>\n" . implode('', $separateName) . "{$indent}</{$name}>\n";
         } else {
             if (count($sameName)) {
                 // prevent multiple root nodes here
                 if (strval($indent) === '') {
                     if (count($set) > 1) {
                         throw new \UnexpectedValueException('cannot convert array with multiple root elements into XML');
                     }
                 }
                 return implode('', $sameName);
             } else {
                 // support empty elements
                 return "{$indent}<{$name}/>\n";
             }
         }
     } else {
         // it's a leaf node
         // -> convert to element containing single text element
         if (string::isString($set)) {
             $set = _S($set)->asUtf8;
         } else {
             $set = data::asAutoTypable($set);
         }
         return "{$indent}<{$name}>{$set}</{$name}>\n";
     }
 }
开发者ID:cepharum,项目名称:txf,代码行数:58,代码来源:set.php

示例4: autoType

 /**
  * Converts provided value to best matching type according to actual value.
  *
  * This method is parsing a provided string for containing an integer,
  * decimal or special string for marking boolean values. Any non-string
  * value is passed as is.
  *
  * @param mixed $value value to convert optionally
  * @param string $type name of type to prefer
  * @return mixed provided or converted value
  */
 public static function autoType($value, $type = null)
 {
     if (string::isString($value)) {
         $type = strtolower(trim($type));
         if ($type === 'string') {
             return $value;
         }
         if (strtolower(trim($value)) == 'null') {
             return null;
         }
         if ($type === 'integer' || preg_match('/^[+-]?\\d+$/', trim($value)) || $type === 'integer') {
             return intval($value);
         }
         if (is_numeric($value)) {
             return doubleval($value);
         }
         // due to different locale is_numeric() probably won't detect
         // non-localized decimals
         if (preg_match('/^(([+-]?)\\d+)(\\.(\\d+))?$/', trim($value), $matches)) {
             return doubleval($matches[1]) + "{$matches['2']}1" * doubleval($matches[4]) * pow(10, -strlen($matches[4]));
         }
         if ($type === 'double') {
             return doubleval($value);
         }
         if (preg_match('/^(o(ff|n)|true|false|yes|no)$/i', trim($value), $matches)) {
             return in_array(strtolower($matches[1]), array('on', 'yes', 'true'));
         }
         if ($type === 'boolean') {
             return in_array(strtolower(trim($value)), array('on', 'yes', 'true'));
         }
         if (preg_match('/^=\\?8bit\\?B\\?(.+)\\?=$/i', $value, $matches)) {
             return static::autotype(unserialize(base64_decode($matches[1])), $type);
         }
     }
     return $value;
 }
开发者ID:cepharum,项目名称:txf,代码行数:47,代码来源:data.php


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