ibrostudio/laravel-neon-config
Composer 安装命令:
composer require ibrostudio/laravel-neon-config
包简介
Add Neon config values to Laravel config'
README 文档
README
Introduction
Laravel Neon Config is a package that integrates Neon configuration files with Laravel's config system. Neon is a human-friendly data serialization language similar to YAML but with a focus on being more readable and concise.
What is Neon?
Neon (Nette Object Notation) is a human-readable structured data format. It is similar to YAML but is more focused on being concise and readable. Neon is developed by the Nette Foundation and is used extensively in Nette Framework applications.
Goal of this Package
The primary goal of this package is to provide a configuration mechanism that works outside the context of a Laravel application. This is particularly useful in scenarios such as:
- When developing a package that is used as a dev dependency of another package
- When you need an environment file for tests while developing a package
- When you want to allow users of your package to easily override configuration values without modifying your package's files
This package allows you to use a .neon file to overwrite a Laravel config file.
Installation
You can install the package via composer:
composer require ibrostudio/laravel-neon-config
Basic Usage
In a Package Service Provider
Add the trait UseNeonConfig to your package service provider and define your "neon to config" mapping:
use IBroStudio\NeonConfig\Concerns\UseNeonConfig; class PackageServiceProvider extends ServiceProvider { use UseNeonConfig; public function register() { $this->handleNeon('package-neon-file')->forConfig('package-config-key'); } }
With Spatie's Package Skeleton
If your package uses PackageServiceProvider from Spatie's package-skeleton-laravel and you are only dealing with a single config file, you can omit the name parameters:
use IBroStudio\NeonConfig\Concerns\UseNeonConfig; class PackageServiceProvider extends PackageServiceProvider { use UseNeonConfig; public function packageRegistered(): void { $this->handleNeon()->forConfig(); } }
How It Works
When a user of your package creates a .neon file at the root of their project with the same name as your package, the values from that file will be merged with your package's configuration.
For example, if your package has this configuration:
// config/your-package.php return [ 'key1' => 'value1', 'key2' => 'value2', 'array' => [ 'array_key1' => 'array_value1', 'array_key2' => 'array_value2', ], ];
The user can create a file named your-package.neon at the root of their project:
key1: new value array: - new_array_key: new_value - array_key2: new_array_value
Values are merged by keys, which means:
- Values with the same keys are replaced
- Omitted keys are kept
- New keys are added
Advanced Features
Casting and Dynamic Values
Enums
If your config uses PHP Enums, you can cast values from the Neon file to the appropriate enum type:
// config/your-package.php return [ 'key1' => SomeEnumClass::VALUE, ];
At the root of your package, create a file named neon-config.neon:
casts: - key1: \Namespace\SomeEnumClass
Then, the user can override the enum value in their Neon file:
key1: newValue
Now, calling config('your-package.key1') will return an instance of \Namespace\SomeEnumClass::NEW_VALUE.
Array of Enums
You can also cast arrays of values to arrays of enum instances:
// config/your-package.php return [ 'key1' => [ SomeEnumClass::VALUE1, SomeEnumClass::VALUE2, SomeEnumClass::VALUE3, ], ];
In your neon-config.neon:
casts: - key1: AsEnumCollection::\Namespace\SomeEnumClass
And in the user's Neon file:
key1: - value4 - value5 - value6
Dynamic Values from Config or Environment
You can also reference other config values or environment variables:
// config/your-package.php return [ 'key1' => config('some.config', 'default value'), 'key2' => env('MY_ENV_VAR', 'default value'), ];
In your neon-config.neon:
casts: - key1: AsConfig::some.config - key2: AsEnv::MY_ENV_VAR
And in the user's Neon file:
key1: other.config.key(type: config, default: 'other default value') key2: OTHER_ENV(type: env)
Using as an Environment File for Tests
When developing a package, you can use Neon files as environment files for your tests:
Configuration
Add the trait to your TestCase instead of the package service provider:
use IBroStudio\NeonConfig\Concerns\UseNeonConfig; class TestCase extends Orchestra { use UseNeonConfig; public function getEnvironmentSetUp($app) { $this->handleNeon('test')->forConfig('test'); } }
Create a test.neon file at the root of your package (add it to .gitignore):
key1: test-value-1 key2: test-value-2
During tests, you can now access these values with config('test.key1').
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
ibrostudio/laravel-neon-config 适用场景与选型建议
ibrostudio/laravel-neon-config 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 21 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 09 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「package」 「config」 「neon」 「laravel」 「iBroStudio」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ibrostudio/laravel-neon-config 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ibrostudio/laravel-neon-config 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ibrostudio/laravel-neon-config 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Zend Framework module to quickly and easily set PHP settings.
Load configuration files the easy way. This configuration loader supports PHP, INI, JSON, XML, YAML and NEON file extensions.
A loader that is able to load various types of configuration files
Easy translating of PHP applications
Native Postgres full-text search + pg_trgm engine for Laravel Scout.
Promare Gradients standardizes the use of neon colors on the web for backgrounds..
统计信息
- 总下载量: 21
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 18
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-09-25