PHPackages                             baagee/php-config - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. baagee/php-config

ActiveLibrary

baagee/php-config
=================

PHP Config library

v0.0.5(5y ago)1581MITPHPPHP &gt;=7.1

Since Mar 31Pushed 5y agoCompare

[ Source](https://github.com/baagee/php-config)[ Packagist](https://packagist.org/packages/baagee/php-config)[ RSS](/packages/baagee-php-config/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (4)DependenciesVersions (6)Used By (1)

Config
======

[](#config)

php Config library

内置获取配置文件的方法

```
interface ConfigInterface
{
    public static function get(string $key);
}
```

### 支持json,php,yaml,ini,xml配置文件解析获取

[](#支持jsonphpyamlinixml配置文件解析获取)

### 安装使用：

[](#安装使用)

composer require baagee/php-config

### 示例代码：

[](#示例代码)

#### 解析ini配置

[](#解析ini配置)

ini配置文件memcache.ini

```
;memcache配置
host = 127.0.0.1
port = 9089
password = fsdt3ty4e
[other]
abc=pp0
```

```
// 解析ini配置文件
//ini方法两个参数 第一个是配置文件存放的根目录
\BaAGee\Config\Config::init(__DIR__ . '/config', \BaAGee\Config\Parser\IniParser::class);
$password = \BaAGee\Config\Config::get('memcache/password');// 获取memcache文件的password值
$host     = \BaAGee\Config\Config::get('memcache/host');
```

#### 解析yaml配置

[](#解析yaml配置)

meituan.yaml配置

```
server:
  host: 127.0.0.1
  port: 9098
access_key: dsgfdsgdf
access_token: 98y8u67
```

```
include_once __DIR__ . '/../vendor/autoload.php';
//使用内置的yaml配置解析 需要安装yaml扩展
\BaAGee\Config\Config::init(__DIR__ . '/config', \BaAGee\Config\Parser\YamlParser::class);
$meituanServer = \BaAGee\Config\Config::get('meituan/server');
$accessKey     = \BaAGee\Config\Config::get('meituan/access_key');
var_dump($meituanServer, $accessKey);
```

#### 配置文件支持子目录存放和获取

[](#配置文件支持子目录存放和获取)

假设配置文件存放在tests/config/service/meituan.yaml php代码：

```
include_once __DIR__ . '/../vendor/autoload.php';
//使用内置的yaml配置解析 需要安装yaml扩展
\BaAGee\Config\Config::init(__DIR__ . '/config', \BaAGee\Config\Parser\YamlParser::class);
// 从config目录开始 service文件夹下meituan.yaml配置文件下的server的值
$meituanServer = \BaAGee\Config\Config::get('service/meituan/server');
$accessKey     = \BaAGee\Config\Config::get('service/meituan/access_key');
var_dump($meituanServer, $accessKey);
```

### 使用自定义的配置文件结构

[](#使用自定义的配置文件结构)

假设配置文件：tests/config/keyvalue.kv

```
name=>小冰
age=>17
sex=>女

```

解析kv文件的php代码；

```
//继承 \BaAGee\Config\Base\ParseConfigAbstract
class ParseKVFile extends \BaAGee\Config\Base\ParseConfigAbstract
{
    // 声明配置文件后缀
    protected static $configSuffix = 'kv';

    // 具体的解析方法，返回解析后的配置数组
    public static function parse(string $configFile): array
    {
        if (is_file($configFile)) {
            $content       = file_get_contents($configFile);
            $content_array = explode(PHP_EOL, $content);
            $config        = [];
            foreach ($content_array as $item) {
                list($key, $val) = explode('=>', $item);
                $config[$key] = $val;
            }
            return $config;
        }
    }
}
```

获取配置文件信息

```
include_once __DIR__ . '/../vendor/autoload.php';
// 引入解析类
include_once __DIR__ . '/ParseKVFile.php';
// 自定义配置文件解析获取
\BaAGee\Config\Config::init(__DIR__ . '/config', ParseKVFile::class);
$name = \BaAGee\Config\Config::get('keyvalue/name');
$age  = \BaAGee\Config\Config::get('keyvalue/age');

echo 'name：' . $name . PHP_EOL;
echo 'age：' . $age . PHP_EOL;
```

输出结果：

```
name：小冰
age：17

```

加快配置信息读取

```
use BaAGee\Config\Config;

include_once __DIR__ . '/../vendor/autoload.php';

\BaAGee\Config\Config::init(__DIR__ . '/config', \BaAGee\Config\Parser\PhpParser::class);
// 设置配置文件缓存目录 加速读取
Config::fast(__DIR__);

$t1 = microtime(true);
for ($i = 0; $i < 100; $i++) {
    $c = Config::get('service/ddd/asd/cc/ddd/dd');
}
$t2 = microtime(true);
var_dump($t2 - $t1);
```

### 其他具体使用：tests目录

[](#其他具体使用tests目录)

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~110 days

Total

5

Last Release

2159d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/22995500?v=4)[BaAGee](/maintainers/baagee)[@baagee](https://github.com/baagee)

---

Top Contributors

[![baagee](https://avatars.githubusercontent.com/u/22995500?v=4)](https://github.com/baagee "baagee (3 commits)")

---

Tags

phpconfig

### Embed Badge

![Health badge](/badges/baagee-php-config/health.svg)

```
[![Health](https://phpackages.com/badges/baagee-php-config/health.svg)](https://phpackages.com/packages/baagee-php-config)
```

###  Alternatives

[redchamps/module-clean-admin-menu

It will merge all third party extensions menu items to single menu item named 'Extensions'.

164416.3k](/packages/redchamps-module-clean-admin-menu)[m1/vars

Vars is a simple to use and easily extendable configuration loader with in built loaders for ini, json, PHP, toml, XML and yaml/yml file types. It also comes with in built support for Silex and more frameworks to come soon.

69124.2k1](/packages/m1-vars)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
