symplely / yaml
PHP 的一个异步简单 YAML 加载/卸载类
1.0.1
2019-09-19 21:31 UTC
Requires
- php: ^7.0
Requires (Dev)
- phpunit/phpunit: >5.7.0
This package is auto-updated.
Last update: 2024-08-29 05:07:01 UTC
README
一个基于纯 PHP 的 YAML 加载/卸载实现。
-
给定一个 YAML 文档,将返回一个数组,您可以按需使用。
-
给定一个数组,将返回一个字符串,其中包含从您的数据构建的 YAML 文档。
YAML 是一种非常友好且功能强大的数据序列化语言,可用于日志文件、配置文件、自定义协议等。有关更多信息,请参阅 http://www.yaml.org。
支持 YAML 1.1 规范。
安装
composer require symplely/yaml
使用
使用 Yaml 非常简单
parse()
或 loader()
方法解析 YAML 字符串并将其转换为 PHP 数组
require 'vendor/autoload.php'; use Async\Yaml; // Reading YAML Contents $Data = Yaml::loader('config.yaml'); // Or $Data = Yaml::parse("foo: bar"); // Or $Data = yaml_load("foo: bar"); // $Data = ['foo' => 'bar']
或(如果您喜欢函数式语法)
require 'vendor/autoload.php'; $Data = yaml_load_file('config.yaml');
dumper()
方法将任何 PHP 数组卸载为其 YAML 表示形式
require 'vendor/autoload.php'; use Async\Yaml; $array = [ 'foo' => 'bar', 'bar' => ['foo' => 'bar','bar' => 'baz'], ]; $yaml = Yaml::dumper($array); // Or $yaml = yaml_dump($array); // Writing YAML Files file_put_contents('/path/to/file.yaml', $yaml);