dtkahl/php-simple-config

1.2.0 2017-09-25 10:15 UTC

This package is auto-updated.

Last update: 2024-08-29 03:47:39 UTC


README

Latest Stable Version License Build Status

PHP 简单配置

这是一个使用点符号的简单配置处理类,适用于 PHP。

依赖

  • PHP >= 5.6.0

安装

使用 Composer 安装

composer require dtkahl/php-simple-config

用法

引用命名空间

use Dtkahl\SimpleConfig\Config;

创建新的 Config 实例

$config = new Config([
    "database" => [
      "host" => "localhost",
      "port" => 1337,
      "username" => "developer",> 1337,
38
      "usernam
      "password" => "secret",
    ],
    "debug" => true,
    // ...
);

您也可以从文件加载 Config

$config = new Config(require("./config.php"));

示例 config.php

<?php
return [
  "database" => [
    "host" => "localhost",
    "port" => 1337,
    "username" => "developer",
    "password" => "secret",
  ],
  "debug" => true,
  // ...
]

方法

has($path)

确定在给定路径上是否存在配置条目。

get($path, $default = null)

如果给定路径上存在配置条目,则返回配置条目,如果路径不存在于配置中,则返回 $default

set($path, $value, $force = false)

在给定路径上设置配置条目(如果存在则覆盖)。如果给定路径不存在,则设置参数 $force。返回配置实例。

remove($path)

如果存在,则在给定路径上删除配置条目。返回配置实例。

setAlias($alias, $path)

为给定路径添加别名。出于明显的原因,别名不应包含点。