定制 ap-lib/conf 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ap-lib/conf

Composer 安装命令:

composer require ap-lib/conf

包简介

README 文档

README

MIT License

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

  1. The library first checks the $_SERVER['security'] variable first, expecting a JSON string.
  2. 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
  3. Values from the next file, such as conf/local/security.php, take priority and override those from the previous file, such as conf/security.php.

统计信息

  • 总下载量: 13
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-03-14