ap-lib / conf
dev-main
2025-03-14 03:29 UTC
Requires
- php: ^8.3
- ap-lib/logger: dev-main
- ap-lib/to-object: dev-main
- ap-lib/validator: dev-main
Requires (Dev)
- phpunit/phpunit: 10.5.*
This package is auto-updated.
Last update: 2025-03-14 03:29:48 UTC
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
.