linkorb / loader
加载器:具有高级功能的通用数据/配置加载器
v1.2.1
2019-11-25 13:12 UTC
Requires
- colinodell/json5: ^2.0
- guzzlehttp/guzzle: ^6.0
- psr/log: ^1.0
- symfony/expression-language: ^3.0|^4.0
- symfony/yaml: ^3.0|^4.0
Requires (Dev)
- monolog/monolog: ^2.0
- phpunit/phpunit: ^7
This package is auto-updated.
Last update: 2024-08-25 23:36:47 UTC
README
具有高级功能的通用数据/配置加载器
用法
$loader = Loader::create(); $data = $loader->load('my.yaml');
功能
文件格式
- JSON
- JSON5(注释、尾随逗号等)
- YAML
JSON 引用 ($ref)
您可以在任何支持的文件格式(json、json5、yaml)中使用 json 引用
示例
localExample: $ref: example.json5 remoteExample: $ref: https://example.web/example.json
这将“包含”引用的文件,就像它们是主文件的一部分。
文件类型基于文件扩展名或(在远程文件的情况下)HTTP 响应头确定
变量插值(表达式)
您可以在文件的任何地方引用其他变量
preferences: color: green text: My favorite color is {{hello.color}}!
辅助函数
您可以在变量块内部使用各种辅助函数。
- strtoupper
- strtolower
- ucfirst
- array_merge_recursive:递归合并两个数组(可以嵌套多次)
- dict:将键/值字典转换为键+值项数组
您也可以注册自己的辅助函数
$interpolator->register( 'myHelper', function ($arguments, $text) { // do something with the input arguments and return return ucfirst($text); } )
引用中的变量
您还可以在引用中使用变量
license: MIT licenseUrl: https://open-source.org.cn/licenses/{{ config.license }}
许可证
MIT。请参阅许可证文件以获取详细信息。
由 LinkORB 工程团队提供
查看我们的其他项目linkorb.com/engineering。
顺便说一句,我们正在招聘!