Download the PHP package ibrostudio/laravel-neon-config without Composer
On this page you can find all versions of the php package ibrostudio/laravel-neon-config. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ibrostudio/laravel-neon-config
More information about ibrostudio/laravel-neon-config
Files in ibrostudio/laravel-neon-config
Package laravel-neon-config
Short Description Add Neon config values to Laravel config'
License MIT
Homepage https://github.com/ibrostudio/laravel-neon-config
Informations about the package laravel-neon-config
Laravel Neon Config
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:
Basic Usage
In a Package Service Provider
Add the trait UseNeonConfig
to your package service provider and define your "neon to config" mapping:
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:
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:
The user can create a file named your-package.neon
at the root of their project:
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:
At the root of your package, create a file named neon-config.neon
:
Then, the user can override the enum value in their Neon file:
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:
In your neon-config.neon
:
And in the user's Neon file:
Dynamic Values from Config or Environment
You can also reference other config values or environment variables:
In your neon-config.neon
:
And in the user's Neon file:
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:
Create a test.neon
file at the root of your package (add it to .gitignore):
During tests, you can now access these values with config('test.key1')
.
Testing
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
- iBroStudio
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-neon-config with dependencies
illuminate/contracts Version ^10.0||^11.0||^12.0
nette/neon Version ^3.4
spatie/laravel-data Version ^4.9
spatie/laravel-package-tools Version ^1.16