yiiapi/framework/utils/CPropertyValue.php
(开头部分) 4KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
<?php
/**
* CPropertyValue class file.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/
* @copyright 2008-2013 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
/**
* CPropertyValue is a helper class that provides static methods to convert component property values to specific types.
*
* CPropertyValue is commonly used in component setter methods to ensure
* the new property value is of the specific type.
* For example, a boolean-typed property setter method would be as follows,
* <pre>
* public function setPropertyName($value)
* {
* $value=CPropertyValue::ensureBoolean($value);
* // $value is now of boolean type
* }
* </pre>
*
* Properties can be of the following types with specific type conversion rules:
* <ul>
* <li>string: a boolean value will be converted to 'true' or 'false'.</li>
* <li>boolean: string 'true' (case-insensitive) will be converted to true,
* string 'false' (case-insensitive) will be converted to false.</li>
* <li>integer</li>
* <li>float</li>
* <li>array: string starting with '(' and ending with ')' will be considered as
* as an array expression and will be evaluated. Otherwise, an array
* with the value to be ensured is returned.</li>
* <li>object</li>
* <li>enum: enumerable type, represented by an array of strings.</li>
* </ul>
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @package system.utils
* @since 1.0
*/
class CPropertyValue
{
/**
* Converts a value to boolean type.
* Note, string 'true' (case-insensitive) will be converted to true,
* string 'false' (case-insensitive) will be converted to false.
* If a string represents a non-zero number, it will be treated as true.
* @param mixed $value the value to be converted.
* @return boolean
*/
public static function ensureBoolean($value)
{
if (is_string($value))
return !strcasecmp($value,'true') || $value!=0;
else
return (boolean)$value;
}
后面还有 106 行代码,购买后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
