jeffersongoncalves/laravel-zero-json-config 问题修复 & 功能扩展

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

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

jeffersongoncalves/laravel-zero-json-config

Composer 安装命令:

composer require jeffersongoncalves/laravel-zero-json-config

包简介

Base JSON configuration service for CLIs, with scope strategies (global, per-repo, per-project), get/set/all and 0600 writes.

README 文档

README

laravel-zero-json-config

laravel-zero-json-config

A tiny, self-contained JSON configuration service for PHP CLI tools (built with Laravel Zero in mind, but framework-free). It separates where a config file lives (the scope) from how values are read and written (the service), so you can swap a global config for a per-repo or per-project one without touching call sites.

  • No runtime dependencies (only php: ^8.2).
  • Three ready-made scope strategies.
  • get / set / all / has / forget with dot-notation support.
  • Safe writes: pretty JSON, file mode 0600, parent dir 0700.

Installation

composer require jeffersongoncalves/laravel-zero-json-config

Scopes

A scope implements ConfigScope and answers one question: path(): string, the absolute path of the JSON file.

Scope Path Use case
GlobalScope ~/.<app>/config.json One machine-wide config per app
PerRepoScope ${XDG_CONFIG_HOME:-~/.config}/<app>/<slug>.json One config per repository
PerProjectScope <basePath>/<fileName> (default <basePath>/<app>.json) Config committed next to the project
use JeffersonGoncalves\LaravelZero\JsonConfig\JsonConfigService;
use JeffersonGoncalves\LaravelZero\JsonConfig\Scopes\GlobalScope;
use JeffersonGoncalves\LaravelZero\JsonConfig\Scopes\PerRepoScope;
use JeffersonGoncalves\LaravelZero\JsonConfig\Scopes\PerProjectScope;

// Global: ~/.myapp/config.json
$config = new JsonConfigService(new GlobalScope('myapp'));

// Per-repo: ~/.config/myapp/owner-repo.json (slug is caller-supplied)
$config = new JsonConfigService(new PerRepoScope('myapp', 'owner-repo'));

// Per-project: ./myapp.json (next to where you run the tool)
$config = new JsonConfigService(new PerProjectScope(getcwd(), appName: 'myapp'));

The homeDir constructor argument on GlobalScope / PerRepoScope lets you override the home directory (useful for tests). PerRepoScope also honors the XDG_CONFIG_HOME environment variable.

Usage

$config->set('token', 'secret');
$config->get('token');             // 'secret'
$config->get('missing', 'fallback'); // 'fallback'

$config->has('token');             // true
$config->all();                    // ['token' => 'secret']
$config->forget('token');

$config->path();                   // absolute path of the JSON file

Dot-notation

Keys containing a dot are treated as nested paths:

$config->set('auth.token', 'xyz');
$config->get('auth');        // ['token' => 'xyz']
$config->get('auth.token');  // 'xyz'
$config->forget('auth.token');

When get is called, a flat top-level key matching the literal string is returned first if it exists; otherwise the key is split on . and resolved through the nested array.

Public API

  • JeffersonGoncalves\LaravelZero\JsonConfig\ConfigScope (interface) — path(): string
  • JeffersonGoncalves\LaravelZero\JsonConfig\JsonConfigServiceget, set, all, has, forget, path
  • JeffersonGoncalves\LaravelZero\JsonConfig\Scopes\GlobalScope
  • JeffersonGoncalves\LaravelZero\JsonConfig\Scopes\PerRepoScope
  • JeffersonGoncalves\LaravelZero\JsonConfig\Scopes\PerProjectScope

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固