devly/config-loader 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

devly/config-loader

最新稳定版本:1.0.1

Composer 安装命令:

composer require devly/config-loader

包简介

Load configurations from multiple sources into a `Devly\Repository` object.

README 文档

README

Load configurations from multiple sources into a Repository object. Supported file formats are: PHP, JSON, INI, XML, Yaml & Neon.

Install

Install using composer:

$ composer require devly/config-loader

Usage

Create Loader object

$safeMode = false // Set 'true' to skip exceptions

$loader = new \Devly\ConfigLoader\Loader($safeMode);

Load configurations from file

// Load config from a single file
$config = $loader->load('path/to/config.php');

// Load config from a list of files
$segment = true; // Segment configuration by file name

$files = [
    'path/to/config/app.php',
    'path/to/config/database.php',
];

$config = $loader->load($files, $segment);

var_dump($config->all());

// array(1) {
//  'app' => ...,
//  'database' => ...
// }

Load configuration files from a directory

// Load config from a single file
$formats = ['php', 'json']; // load only php and json files. keep null to load all the files in the directory
$segment = true; // Segment configuration by file names
$config = $loader->load('path/to/config', $segment, $formats);

Cache configurations

Configurations can be cached to a file, a MySQL database or a custom storage provider.

Cache to file

The only thing needed to cache configurations to file is to set a full path to cache directory:

// When creating new Loader instance
$loader = new Loader($safeMode, 'full/path/to/cache');

// Or using the `setStorage()` method:
$loader->setStorage('full/path/to/cache');

Cache to MySQL database

$name = 'db_name';
$username = 'db_user';
$password = 'db_password';
$host = '172.0.0.1'; // Default 'localhost'

// Create instance of DatabaseStorage
$storage = new \Devly\ConfigLoader\Storages\DatabaseStorage($name, $username, $password, $host)

// Creating new Loader instance
$loader = new Loader($safeMode, $storage);

// Or using the `setStorage()` method:
$loader->setStorage($storage);

Custom cache storage

class CustomStorage implements \Devly\ConfigLoader\Contracts\IStorage
{
    ...
}

$storage = new CustomStorage();

// Creating new Loader instance
$loader = new Loader($safeMode, $storage);

// Or using the `setStorage()` method:
$loader->setStorage($storage);

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2022-10-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固