承接 stefna/config 相关项目开发

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

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

stefna/config

Composer 安装命令:

composer require stefna/config

包简介

Lightweight config loader with type safety

README 文档

README

Build Status Latest Version on Packagist Software License

This package is a lightweight config loader with type safety as the primary corner stone.

Requirements

PHP 8.2 or higher.

Installation

composer require stefna/config

Motivation

Most config loaders fail to give the user a way to use it in a type safe way.

It also promises to be immutable after first read.

Usage

Load config from file

We support writing your config in php files

Example:

<?php

// config.php

return [
	'config-key' => 'value',
	'nested' => [
		'key' => 'nested-value'
		'bool-key' => false,
	],
];
$config = new \Stefna\Config\FileConfig('path-to-php/config.php');
// config file is not read until it's needed

$config->getBool('nested.bool-key') === false;
$config->getString('config-key') === 'value';

Load multiple files into config

<?php

// common.php

return [
	'config-key' => 'value',
	'nested' => [
		'key' => 'nested-value'
		'bool-key' => false,
	],
];
<?php

// production.php

return [
	'config-key' => 'production-value',
	'nested' => [
		'extra-key' => 42,
	],
];
$config = new \Stefna\Config\FileCollectionConfig('path-to-php/');
$config->addFile('common.php');
$config->addFile('production.php');

// config files is not read until it's needed

$config->getInt('nested.extra-key') === 42;
$config->getString('config-key') === 'product-value';

Mutable config

We do provide a mutable config that allows you to override values in the "root" config this is meant to be used when testing applications but still allow the "root" configuration to stay immutable

$rootConfig = new \Stefna\Config\FileCollectionConfig('path-to-php/');
$rootConfig->addFile('common.php');
$rootConfig->addFile('production.php');

$config = new \Stefna\Config\MutableConfig($rootConfig);

$config->setConfigValue('config-key', 'overridden-value');

$config->getString('config-key') === 'overridden-value';

$config->resetConfigValue('config-key');

$config->getString('config-key') === 'production-value';

Contribute

We are always happy to receive bug/security reports and bug/security fixes

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-01-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固