|
@ -0,0 +1,58 @@ |
|
|
|
|
|
<?php |
|
|
|
|
|
|
|
|
|
|
|
namespace Blobt\Luxcore\scene; |
|
|
|
|
|
|
|
|
|
|
|
use Blobt\Luxcore\core\Base; |
|
|
|
|
|
use Blobt\Luxcore\utils\StringHelper; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BaseCfg extends Base |
|
|
|
|
|
{ |
|
|
|
|
|
public function __toString() |
|
|
|
|
|
{ |
|
|
|
|
|
return $this->toString(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function toString($parentClassName = false) |
|
|
|
|
|
{ |
|
|
|
|
|
$object = new \ReflectionClass($this); |
|
|
|
|
|
$properties = $object->getProperties(); |
|
|
|
|
|
|
|
|
|
|
|
//获取类名 -> 去除命名空间 -> 转成全小写
|
|
|
|
|
|
$className = get_called_class(); |
|
|
|
|
|
$className = strtolower(array_reverse(explode('\\', $className))[0]); |
|
|
|
|
|
if (!empty($parentClassName)) { |
|
|
|
|
|
$className = "{$parentClassName}.$className"; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$ret = ""; |
|
|
|
|
|
foreach ($properties as $item) { |
|
|
|
|
|
|
|
|
|
|
|
$item->setAccessible(true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取属性名称,并根据驼峰规则截开后从新用‘.’连接
|
|
|
|
|
|
$name = $item->getName(); |
|
|
|
|
|
$name = implode(".", array_map('strtolower', StringHelper::camelStrToArray($name))); |
|
|
|
|
|
|
|
|
|
|
|
$value = $item->getValue($this); |
|
|
|
|
|
|
|
|
|
|
|
if (is_string($value)) { |
|
|
|
|
|
$ret .= "{$className}.{$name} = \"{$value}\"\n"; |
|
|
|
|
|
} else if (is_integer($value)) { |
|
|
|
|
|
$ret .= "{$className}.{$name} = {$value}\n"; |
|
|
|
|
|
} else if (is_bool($value)) { |
|
|
|
|
|
$value = $value ? 1 : 0; |
|
|
|
|
|
$ret .= "{$className}.{$name} = {$value}\n"; |
|
|
|
|
|
} else if (is_object($value) && $value instanceof BaseCfg) { |
|
|
|
|
|
$ret .= $value->toString($className); |
|
|
|
|
|
} else if(is_null($value)){ |
|
|
|
|
|
$ret .= "{$className}.{$name} = \"null\"\n"; |
|
|
|
|
|
} else |
|
|
|
|
|
{ |
|
|
|
|
|
$ret .= "{$className}.{$name} = \"unknow type\"\n"; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return $ret; |
|
|
|
|
|
} |
|
|
|
|
|
} |