maer/config-yaml-reader

maer/config 库的 yaml 读取器

1.0.0 2018-04-12 14:54 UTC

This package is auto-updated.

Last update: 2024-08-29 04:37:18 UTC


README

Build Status

为了保持 maer/config 库小巧且无依赖,默认不支持 yaml 文件。

如果您想使用 yaml 文件,您可以安装此读取器并将其注册为 yaml 文件扩展。此扩展需要您使用 maer/config 版本 2 或更高版本。

安装

composer require maer/config-yaml-reader

如果之前未安装 maer/config,它也会被安装。

注册

您需要注册读取器并将其与 yml 文件扩展名关联。

# Either add the reader to an existing config instance
$config->setReader('yml', new Maer\Config\Yaml\Reader);

# or you can add the reader when you instantiate the config class as a second argument
$options = [
    'readers' => [
        'yml' => new Maer\Config\Yaml\Reader,
    ],
];

$config = new Config(['/path-to-your-config.yml'], $options);

如果您选择第一种方案,您需要在加载 yaml 文件之前设置读取器。

异常

如果无法解析 yaml 文件,它将抛出 Symfony\Component\Yaml\Exception\ParseException