承接 duyler/config 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

duyler/config

Composer 安装命令:

composer require duyler/config

包简介

Duyler config file loader

关键字:

README 文档

README

Quality Gate Status Coverage Psalm Type Coverage PHP Version

Duyler Config

Description

Duyler Config is a powerful and flexible configuration management library for PHP applications. It provides a simple and intuitive way to handle configuration files and environment variables in your projects.

Features

  • Recursive configuration file loading
  • Environment variables support with .env files
  • Configuration caching for production environments
  • Type-safe configuration values with typed getters
  • Circular dependency detection
  • Extensible through interfaces
  • Clean architecture with SOLID principles
  • PHP 8.4+ support

Installation

composer require duyler/config

Basic Usage

use Duyler\Config\FileConfig;

// Initialize config
$config = new FileConfig(
    configDir: 'config',
    rootFile: 'composer.json'
);

// Get configuration value
$value = $config->get('app', 'name', 'default');

// Check if config key exists
if ($config->has('app', 'name')) {
    // ...
}

// Get all values from config file
$allConfig = $config->all('app');

// Type-safe getters
$timeout = $config->getInt('app', 'timeout', 30);
$debug = $config->getBool('app', 'debug', false);
$name = $config->getString('app', 'name', 'MyApp');
$servers = $config->getArray('app', 'servers', []);

// Get environment variable
$env = $config->env('APP_ENV', 'production');

// Get project path
$path = $config->path('storage/logs');

Advanced Usage

Configuration Caching

For production environments, you can enable configuration caching:

$config = new FileConfig(
    configDir: 'config',
    rootFile: 'composer.json',
    cacheDir: 'var/cache',
    useCache: true
);

// Warm up cache (optional, useful for deployment)
$config->warmup();

// Clear cache when needed
$config->clearCache();

Cross-Config References

Configuration files can reference values from other configs:

// config/app.php
return [
    'name' => 'MyApp',
    'database' => $config->get('database', 'default', 'mysql'),
];

// config/database.php
return [
    'default' => 'postgresql',
    'connections' => [
        'mysql' => ['host' => 'localhost'],
        'postgresql' => ['host' => 'localhost'],
    ],
];

The library automatically handles circular dependencies.

Requirements

  • PHP 8.4 or higher
  • Composer

Architecture

The library follows clean architecture principles and SOLID design:

  • ProjectRootFinder - Locates project root directory
  • ConfigFileLoader - Loads configuration files from filesystem
  • EnvironmentResolver - Handles environment variables
  • ConfigCache - Manages configuration caching
  • FileConfig - Main facade for configuration access

License

This project is licensed under the MIT License - see the LICENSE file for details.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-08-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固