ap-lib/conf
Composer 安装命令:
composer require ap-lib/conf
包简介
README 文档
README
AP\Conf is a library for managing project configuration variables, featuring validation and object transformation capabilities.
Installation
composer require ap-lib/conf
Features
- Retrieve environment variables and PHP configuration files as objects with validation.
- Built-in validation mechanisms with error handling.
Requirements
- PHP 8.3 or higher
Getting started
Lazy Loading with MyConf
You can create a custom configuration loader using a static class that extends Conf
use AP\Conf\Conf; use AP\Scheme\ToObject; use AP\Scheme\Validation; readonly class SecuritySettings implements ToObject, Validation { public function __construct() { public string $salt } } class MyConf extends Conf { public static function security(): SecuritySettings { return self::obj(__FUNCTION__, SecuritySettings::class); } } class Core { static public function conf(): MyConf { return new MyConf( [ __DIR__ . "/../conf", __DIR__ . "/../conf/local", ] ); } } $salt = Core::conf()->security()->salt;
Configuration Loading Behavior
- The library first checks the
$_SERVER['security']variable first, expecting a JSON string. - If not found in the environment variables, it merges values from the following files if they exist:
__DIR__/../conf/security.php__DIR__/../conf/local/security.php
- Values from the next file, such as
conf/local/security.php, take priority and override those from the previous file, such asconf/security.php.
统计信息
- 总下载量: 13
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-03-14