定制 andrewdyer/settings 二次开发

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

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

andrewdyer/settings

最新稳定版本:0.1.4

Composer 安装命令:

composer require andrewdyer/settings

包简介

A framework-agnostic PHP settings library for managing application configuration in a consistent and structured way

README 文档

README

Settings

Latest Stable Version Total Downloads License PHP Version Required

Settings

A framework-agnostic PHP settings library for managing application configuration in a consistent and structured way.

Introduction

This library provides a lightweight wrapper around a plain PHP array, exposing a clean interface for storing and retrieving application configuration values. It offers a straightforward, dependency-free way to manage configuration without coupling application code to a specific framework, making it easy to drop into any project or architecture.

Prerequisites

  • PHP: Version 8.3 or higher is required.
  • Composer: Dependency management tool for PHP.

Installation

composer require andrewdyer/settings

Getting Started

Create a AndrewDyer\Settings\Settings instance by passing in the configuration array.

$settings = new Settings([
    'app_name' => 'My Application',
    'database' => [
        'host' => 'localhost',
        'port' => 5432,
        'credentials' => [
            'username' => 'admin',
            'password' => 'secret',
        ],
    ],
]);

Usage

Retrieve all settings

The entire settings array is returned by the all() method.

$all = $settings->all();

Retrieve a setting

A top-level setting is accessed by its key with the get() method.

$appName = $settings->get('app_name'); // 'My Application'

The get() method can also access nested settings using dot notation.

$host = $settings->get('database.host'); // 'localhost'

Dot notation can traverse multiple levels of configuration.

$username = $settings->get('database.credentials.username'); // 'admin'

Requesting a parent key with get() returns the entire nested configuration array.

$database = $settings->get('database');

Check if a setting exists

The has() method checks whether a top-level key exists.

$settings->has('app_name'); // true

The has() method also supports nested keys using dot notation.

$settings->has('database.credentials.password'); // true

Literal keys containing dots

If a top-level key contains dots, the exact key takes precedence over nested resolution.

$settings = new Settings([
    'database.host' => 'literal',
]);

$settings->get('database.host'); // 'literal'

If the exact key does not exist, the get() method falls back to resolving nested values using dot notation.

$settings = new Settings([
    'database' => [
        'host' => 'nested',
    ],
]);

$settings->get('database.host'); // 'nested'

License

Licensed under the MIT license and is free for private or commercial projects.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固