定制 mireiawen/configuration 二次开发

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

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

mireiawen/configuration

Composer 安装命令:

composer require mireiawen/configuration

包简介

Configuration file reader

README 文档

README

Configuration file helpers to read different file formats.

  • Namespace: Mireiawen\Configuration

Requirements

  • PHP 7.3 or later
  • Extensions depending on needed file types:
    • JSON
    • YAML

Installation

You can clone or download the code from the GitHub repository or you can use composer: composer require mireiawen/configuration

Example

$configuration = new Mireiawen\Configuration\JSON('config.json');
$hostname = $configuration->GetString('hostname');
$port = $configuration->GetInt('port');

JSON specific methods

__construct

JSON class constructor

Configuration::__construct(string $filename)

Arguments

Type Name Description
string $filename The JSON file name to read

Exceptions thrown

Type Description
MissingExtension When expected extensions are not available
InvalidFile When the configuration file is missing or not readable

YAML specific methods

__construct

YAML class constructor

Configuration::__construct(string $filename)

Arguments

Type Name Description
string $filename The YAML file name to read

Exceptions thrown

Type Description
MissingExtension When expected extensions are not available
InvalidFile When the configuration file is missing or not readable

Common interface methods

Has

Check if the configuration variable exists and is set.

Configuration::Has(string $key) : bool

Arguments

Type Name Description
string $key The key to check

Return value

Type Description
bool TRUE if the value exists and is set, FALSE if the value does not exist

Get

Get the configuration variable and return its value, or default if it is not set.

Configuration::Get(string $key, mixed $default) : mixed

Arguments

Type Name Description
string $key The key to retrieve
mixed $default The default value for the key, set to NULL to throw error if key is not set

Return value

Type Description
mixed The value of the key, or the provided default if key is not set

Exceptions thrown

Type Description
MissingValue In case the key is not available and default value is not set

GetString

Get the configuration variable and return its value, or default if it is not set, and validating the type

Configuration::GetString(string $key, string|null $default) : string

Arguments

Type Name Description
string $key The key to retrieve
string|null $default The default value for the key, set to NULL to throw error if key is not set

Return value

Type Description
string The value of the key, or the provided default if key is not set

Exceptions thrown

Type Description
MissingValue In case the key is not available and default value is not set
\TypeError In case the value is not of type string

GetInt

Get the configuration variable and return its value, or default if it is not set, and validating the type

Configuration::GetInt(string $key, int|null $default) : int

Arguments

Type Name Description
string $key The key to retrieve
int|null $default The default value for the key, set to NULL to throw error if key is not set

Return value

Type Description
int The value of the key, or the provided default if key is not set

Exceptions thrown

Type Description
MissingValue In case the key is not available and default value is not set
\TypeError In case the value is not of type int

GetFloat

Get the configuration variable and return its value, or default if it is not set, and validating the type

Configuration::GetFloat(string $key, float|null $default) : float

Arguments

Type Name Description
string $key The key to retrieve
float|null $default The default value for the key, set to NULL to throw error if key is not set

Return value

Type Description
float The value of the key, or the provided default if key is not set

Exceptions thrown

Type Description
MissingValue In case the key is not available and default value is not set
\TypeError In case the value is not of type float

GetBool

Get the configuration variable and return its value, or default if it is not set, and validating the type

Configuration::GetBool(string $key, bool|null $default) : bool

Arguments

Type Name Description
string $key The key to retrieve
bool|null $default The default value for the key, set to NULL to throw error if key is not set

Return value

Type Description
bool The value of the key, or the provided default if key is not set

Exceptions thrown

Type Description
MissingValue In case the key is not available and default value is not set
\TypeError In case the value is not of type bool

GetAsString

Get the configuration variable and return its value, or default if it is not set, and casting the return value to correct type

Configuration::GetAsString(string $key, string|null $default) : string

Arguments

Type Name Description
string $key The key to retrieve
string|null $default The default value for the key, set to NULL to throw error if key is not set

Return value

Type Description
string The value of the key, or the provided default if key is not set

Exceptions thrown

Type Description
MissingValue In case the key is not available and default value is not set

GetAsInt

Get the configuration variable and return its value, or default if it is not set, and casting the return value to correct type

Configuration::GetAsInt(string $key, int|null $default) : int

Arguments

Type Name Description
string $key The key to retrieve
int|null $default The default value for the key, set to NULL to throw error if key is not set

Return value

Type Description
int The value of the key, or the provided default if key is not set

Exceptions thrown

Type Description
MissingValue In case the key is not available and default value is not set

GetAsFloat

Get the configuration variable and return its value, or default if it is not set, and casting the return value to correct type

Configuration::GetAsFloat(string $key, float|null $default) : float

Arguments

Type Name Description
string $key The key to retrieve
float|null $default The default value for the key, set to NULL to throw error if key is not set

Return value

Type Description
float The value of the key, or the provided default if key is not set

Exceptions thrown

Type Description
MissingValue In case the key is not available and default value is not set

GetAsBool

Get the configuration variable and return its value, or default if it is not set, and casting the return value to correct type

Configuration::GetAsBool(string key, bool|null default) : bool

Arguments

Type Name Description
string $key The key to retrieve
bool|null $default The default value for the key, set to NULL to throw error if key is not set

Return value

Type Description
bool The value of the key, or the provided default if key is not set

Exceptions thrown

Type Description
MissingValue In case the key is not available and default value is not set

mireiawen/configuration 适用场景与选型建议

mireiawen/configuration 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 194 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 09 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 mireiawen/configuration 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mireiawen/configuration 我们能提供哪些服务?
定制开发 / 二次开发

基于 mireiawen/configuration 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-09-03