whotrades / formatter
该包最新版本(v1.0.2)没有提供许可证信息。
通用格式化器
v1.0.2
2020-06-09 12:05 UTC
Requires
- php: >=7.0
- symfony/yaml: ^4.0
Requires (Dev)
- phpunit/phpunit: ~6.3.0
- symfony/console: ^4.0
This package is auto-updated.
Last update: 2024-09-09 20:47:49 UTC
README
通用格式化器
示例
获取特定的格式化类实例
$format = \whotrades\formatter\Formatter::factory('{
"root": {
"node1": ["text1", "text2"],
"node2": "text3",
"node3": ["text4", "text5"]
}
}');
获取格式名称
var_dump($format->getFormatName());
string 'json' (length=4)
使用xpath请求精细节点
- 如果节点是标量,则返回节点值,否则返回包含内容的节点
var_dump($format->getValueListByXPathList(["//node2", "//node3"]));
array (size=2)
0 => string 'text3' (length=5)
1 => string '{"node3":["text4","text5"]}' (length=27)
以数组形式获取
var_dump($format->getAsArray());
array (size=1)
'root' =>
array (size=3)
'node1' =>
array (size=2)
0 => string 'text1' (length=5)
1 => string 'text2' (length=5)
'node2' => string 'text3' (length=5)
'node3' =>
array (size=2)
0 => string 'text4' (length=5)
1 => string 'text5' (length=5)
用于用户友好的渲染
var_dump($format->getFormatted());
string 'Array
(
[root] => Array
(
[node1] => Array
(
[0] => text1
[1] => text2
)
[node2] => text3
[node3] => Array
(
[0] => text4
[1] => text5
)
)
)
' (length=344)