ghostwriter/config

提供一个对象,将配置键映射到值。

0.4.1 2023-07-11 10:18 UTC

This package is auto-updated.

Last update: 2024-09-17 21:05:50 UTC


README

Compliance Supported PHP Version Mutation Coverage Code Coverage Type Coverage Latest Version on Packagist Downloads

提供一个对象,将配置键映射到值。

安装

您可以通过composer安装此包

composer require ghostwriter/config

如果您觉得此仓库有用,请给它加星标 ⭐️

您也可以给它加星标(🌟)以便以后更容易找到。

使用

$key = 'nested';
$path = 'path/to/config.php';
$options = [
    'settings' => [
        'enable' => true,
    ],
];

$config = $configFactory->create($options);
$config->toArray(); // ['settings' => ['enable'=>true]]

$config = Config::fromPath($path);
$config->toArray(); // ['settings' => ['enable'=>true]]

$config = Config::fromPath($path, $key);
$config->toArray(); // ['nested' => ['settings' => ['enable'=>true]]]
$config->has('nested.settings.disabled'); // true

//

$config = new Config($options);
$config->has('settings'); // true
$config->has('settings.enable'); // true
$config->get('settings.enable'); // true

$config = Config::new($options);
$config->has('settings.disabled'); // false
$config->get('settings.disabled'); // null
$config->get('settings.disabled', 'default'); // 'default'

$config->set('settings.disabled', false); // true
$config->has('settings.disabled'); // true

$config->get('settings.disabled'); // false

$config->toArray(); // ['settings' => ['enable'=>true,'disabled'=>false]]

$config->remove('settings.disabled');

$config->get('settings.disabled'); // null

$config->toArray(); // ['settings' => ['enable'=>true]]

API

interface ConfigInterface
{
    public function get(string $key, mixed $default = null): mixed;

    public function has(string $key): bool;

    public function remove(string $key): void;

    public function set(string $key, mixed $value): void;

    public function toArray(): array;
}

测试

composer test

变更日志

请查看CHANGELOG.md以获取更多关于最近更改的信息。

安全

如果您发现任何安全相关的问题,请通过电子邮件nathanael.esayeas@protonmail.com报告,而不是使用问题跟踪器。

支持

[成为GitHub赞助者]

致谢

许可证

The BSD-3-Clause. 请查看许可证文件以获取更多信息。