PHPackages                             philiprehberger/php-config-loader - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. philiprehberger/php-config-loader

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

philiprehberger/php-config-loader
=================================

Load configuration from JSON and PHP files with environment variable substitution

v1.2.0(4mo ago)168MITPHPPHP ^8.2CI passing

Since Mar 13Pushed 1mo agoCompare

[ Source](https://github.com/philiprehberger/php-config-loader)[ Packagist](https://packagist.org/packages/philiprehberger/php-config-loader)[ Docs](https://github.com/philiprehberger/php-config-loader)[ GitHub Sponsors](https://github.com/philiprehberger)[ RSS](/packages/philiprehberger-php-config-loader/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (6)Versions (7)Used By (0)

PHP Config Loader
=================

[](#php-config-loader)

[![Tests](https://github.com/philiprehberger/php-config-loader/actions/workflows/tests.yml/badge.svg)](https://github.com/philiprehberger/php-config-loader/actions/workflows/tests.yml)[![Latest Version on Packagist](https://camo.githubusercontent.com/561a2bacdea9995f0c582052cf054e159561ea4ac81f3a63196b7eff01e19d2b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7068696c69707265686265726765722f7068702d636f6e6669672d6c6f616465722e737667)](https://packagist.org/packages/philiprehberger/php-config-loader)[![Last updated](https://camo.githubusercontent.com/a309438701f68f7c30ec652a57b44b80fb264c957c7a4fa11968cf2185c4d2f9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f7068696c69707265686265726765722f7068702d636f6e6669672d6c6f61646572)](https://github.com/philiprehberger/php-config-loader/commits/main)

Load configuration from JSON, PHP, YAML, and TOML files with environment variable substitution.

Requirements
------------

[](#requirements)

- PHP 8.2+
- ext-yaml (optional, required for YAML file support)

Installation
------------

[](#installation)

```
composer require philiprehberger/php-config-loader
```

Usage
-----

[](#usage)

### Loading a Single File

[](#loading-a-single-file)

```
use PhilipRehberger\ConfigLoader\ConfigLoader;

// Load a PHP config file
$config = ConfigLoader::load(__DIR__ . '/config/app.php');

// Load a JSON config file
$config = ConfigLoader::load(__DIR__ . '/config/database.json');

// Load a YAML config file (requires ext-yaml)
$config = ConfigLoader::load(__DIR__ . '/config/cache.yaml');

// Load a TOML config file
$config = ConfigLoader::load(__DIR__ . '/config/services.toml');
```

**PHP config file** (`app.php`):

```
