Download the PHP package vaibhavpandeyvpz/kunfig without Composer
On this page you can find all versions of the php package vaibhavpandeyvpz/kunfig. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download vaibhavpandeyvpz/kunfig
More information about vaibhavpandeyvpz/kunfig
Files in vaibhavpandeyvpz/kunfig
Package kunfig
Short Description Helper library to easily merge & use multiple configuration files.
License MIT
Homepage https://github.com/vaibhavpandeyvpz/kunfig
Informations about the package kunfig
Kunfig
A modern, flexible PHP configuration management library that provides multiple access patterns (methods, arrays, properties, and dot notation) for managing configuration values with support for nested configurations, merging, and type safety.
Features
- 🎯 Multiple Access Patterns: Access configuration values using methods, array syntax, or object properties
- 🔄 Nested Configurations: Automatic conversion of arrays to nested
Configinstances - 🔀 Configuration Merging: Recursively merge multiple configurations with
mix() - 📝 Dot Notation: Access nested values using dot syntax (e.g.,
$config->get('app.debug')) - 🔒 Type Safety: Full PHP 8.2+ type declarations with strict types
- 📊 Iterable & Countable: Implements
IteratorAggregateandCountableinterfaces - 🎨 Modern PHP: Built with PHP 8.2+ features including traits, union types, and more
- ✅ 100% Test Coverage: Comprehensive test suite with full code coverage
Requirements
- PHP 8.2 or higher
Installation
Install via Composer:
Quick Start
Usage Examples
Basic Operations
Creating a Configuration
Getting Values
Setting Values
Checking Existence
Removing Values
Dot Notation
Kunfig supports dot notation for accessing nested configuration values, providing a convenient alternative to chained property or array access.
Basic Usage
Setting Nested Values
Dot notation automatically creates the nested structure when setting values:
Checking Existence
Removing Nested Values
Deeply Nested Access
Dot notation works with any depth of nesting:
Edge Cases
Merging Configurations
The mix() method allows you to merge configurations, with values from the source configuration overriding existing values. Nested configurations are recursively merged.
Iterating Over Configuration
Since Config implements IteratorAggregate, you can iterate over configuration values:
Getting All Values
The all() method returns all configuration values as a plain array, recursively converting nested Config instances:
Counting Configuration Items
Since Config implements Countable, you can use count():
Real-World Example
API Reference
ConfigInterface
The main interface that defines the configuration contract.
Methods
all(): array- Get all configuration values as an arrayhas(string $key): bool- Check if a key exists (supports dot notation)get(string $key, mixed $fallback = null): mixed- Get a value by key (supports dot notation)set(string $key, mixed $value): void- Set a value (supports dot notation, creates nested structure)remove(string $key): void- Remove a key (supports dot notation)mix(ConfigInterface $config): void- Merge another configuration
Implemented Interfaces
ArrayAccess- Array-like access ($config['key']or$config['app.debug']with dot notation)Countable- Count items (count($config))IteratorAggregate- Iterate over values (foreach ($config as ...))
Config
The main configuration class implementing ConfigInterface.
Constructor
Creates a new Config instance. Array values are automatically converted to nested Config instances.
Static Methods
Creates a new instance from an exported array (for var_export() compatibility).
ConfigTrait
A trait that provides default implementations for ArrayAccess and property access methods. Can be used by any class implementing ConfigInterface.
Advanced Usage
Custom Configuration Classes
You can create custom configuration classes by implementing ConfigInterface and using ConfigTrait:
Type-Safe Configuration
With PHP 8.2+ type declarations, you get full type safety:
Handling Different Value Types
Testing
The project maintains 100% code coverage. Run tests with:
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is open-sourced software licensed under the MIT license.