PHPackages                             yosymfony/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. yosymfony/config-loader

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

yosymfony/config-loader
=======================

Configuration file loader

v2.0.0(7y ago)10108.1k↓69.3%6[1 PRs](https://github.com/yosymfony/Config-loader/pulls)MITPHPPHP &gt;=7.2

Since Jul 19Pushed 6y ago2 watchersCompare

[ Source](https://github.com/yosymfony/Config-loader)[ Packagist](https://packagist.org/packages/yosymfony/config-loader)[ RSS](/packages/yosymfony-config-loader/feed)WikiDiscussions master Synced today

READMEChangelog (7)Dependencies (3)Versions (8)Used By (0)

Config loader for PHP
=====================

[](#config-loader-for-php)

An agnostics configuration loader with built-in loaders for YAML, TOML and JSON.

[![Build Status](https://camo.githubusercontent.com/77e808f4563aa381116ed1133b75942630b2ad96e4b3e5ff0d5a28585dbd82de/68747470733a2f2f7472617669732d63692e6f72672f796f73796d666f6e792f636f6e6669672d6c6f616465722e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/yosymfony/config-loader)[![Latest Stable Version](https://camo.githubusercontent.com/0895b4cf2faf6aca951cb911cb534b5a1ff5d23cb201a840003944ca6fd87154/68747470733a2f2f706f7365722e707567782e6f72672f796f73796d666f6e792f636f6e6669672d6c6f616465722f762f737461626c652e706e67)](https://packagist.org/packages/yosymfony/config-loader)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/353825b73e7622135f74faf254d98045fe556045ac5ae8ecf508128b66bb4214/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f796f73796d666f6e792f436f6e6669672d6c6f616465722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/yosymfony/Config-loader/?branch=master)

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

[](#installation)

**Requires PHP &gt;= 7.2.**

Use [Composer](http://getcomposer.org/) to install this package:

```
composer require yosymfony/config-loader
```

Usage
-----

[](#usage)

### Initialization

[](#initialization)

The class `ConfigLoader` let you load your configuration resources. It expects a list of loaders in the constructor so you can pass to it only those ones you need:

```
use Yosymfony\ConfigLoader\FileLocator;
use Yosymfony\ConfigLoader\ConfigLoader;

// The file locator uses an array of pre-defined paths to find files:
$locator = new FileLocator(['/path1', '/path2']);

// Set up the ConfigLoader to work with YAML and TOML configuration files:
$config = new ConfigLoader([
    new YamlLoader($locator),
    new TomlLoader($locator),
]);
```

### Available loaders

[](#available-loaders)

#### Yaml loader

[](#yaml-loader)

**Requires**: [Symfony YAML](https://github.com/symfony/yaml) component:

```
composer require symfony/yaml
```

Initialization:

```
$config = new ConfigLoader([
  new YamlLoader($locator),
]);
```

#### Toml loader

[](#toml-loader)

**Requires**: [Toml](https://github.com/yosymfony/toml) component:

```
composer require yosymfony/toml
```

Initialization:

```
$config = new ConfigLoader([
  new TomlLoader($locator),
]);
```

#### Json loader

[](#json-loader)

Initialization:

```
$config = new ConfigLoader([
  new JsonLoader($locator),
]);
```

### Loading configuration files:

[](#loading-configuration-files)

```
// Search this file in "path1" and "path2":
$config->load('user.yml');
// or load a file using its absolute path:
$config->load('/var/config/user1.yml');
```

#### *.dist* files

[](#dist-files)

This library has support for `.dist` files. The filename is resolved following the next hierarchy:

1. filename.ext
2. filename.ext.dist (if `filename.ext` does not exist)

### Loading inline configuration:

[](#loading-inline-configuration)

To parse inline configurations you just need to set the configuration text as first argument instead of the filename and set the format type as second one:

```
$repository = $config->load('server: "your-name.com"', YamlLoader::TYPE);
```

### Importing files

[](#importing-files)

This library has support for importing files. The example below shows a YAML file importing three files:

```
---
imports:
  - config-imported.yml
  - config-imported.toml
  - config-imported.json
```

Similar example using JSON syntax:

```
{
  "imports": [
    "config.json"
  ]
}
```

An example using TOML syntax:

```
imports = [
    "config.toml"
]

```

Repository
----------

[](#repository)

A configuration file is loaded into a repository. A repository is a wrapper that implements the [ArrayAccess interface](http://php.net/manual/en/class.arrayaccess.php) and exposes methods for working with configuration values.

```
// Returns the value associeted with key "name" or the default value in case not found
$repository->get('name', 'default');

// Do the same that the previous sentence but using array notation
$repository['name'];
```

### Operations

[](#operations)

#### Unions

[](#unions)

You can performs the union of a repository A with another B into C as result:

```
$resultC = $repositoryA->union($repositoryB);
```

The values of `$repositoryB` have less priority than values in `$repositoryA`.

#### Intersections

[](#intersections)

You can performs the intersection of a repository A with another B into C as result:

```
$resultC = $repositoryA->intersection($repositoryB);
```

The values of `$repositoryB` have less priority than values in `$repositoryA`.

### Creating a blank repository

[](#creating-a-blank-repository)

Creating a blank repository is too easy. You just need to create a instance of a `Repository` class:

```
use Yosymfony\Config-loader\Repository;

//...

$repository = new Repository([
  'name' => 'Yo! Symfony',
]);

$repository->set('server', 'your-name.com');
```

Unit tests
----------

[](#unit-tests)

You can run the unit tests with the following command:

```
$ cd toml
$ composer test
```

License
-------

[](#license)

This library is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).

###  Health Score

38

↑

LowBetter than 86% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity39

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 88.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~251 days

Recently: every ~328 days

Total

7

Last Release

2757d ago

Major Versions

v1.3.2 → v2.0.02018-09-02

PHP version history (3 changes)v1.0.0PHP &gt;=5.3.0

v1.1.0PHP &gt;=5.3.3

v2.0.0PHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/cac3ac1311a4a66c37c1c6cb3301e6a02e5f4f8b742dfb95d1ce6805e8d8fe94?d=identicon)[yosymfony](/maintainers/yosymfony)

---

Top Contributors

[![yosymfony](https://avatars.githubusercontent.com/u/3321099?v=4)](https://github.com/yosymfony "yosymfony (48 commits)")[![bigfoot90](https://avatars.githubusercontent.com/u/4598274?v=4)](https://github.com/bigfoot90 "bigfoot90 (2 commits)")[![dlundgren](https://avatars.githubusercontent.com/u/1322393?v=4)](https://github.com/dlundgren "dlundgren (2 commits)")[![christianp](https://avatars.githubusercontent.com/u/19513?v=4)](https://github.com/christianp "christianp (1 commits)")[![denis-n-ko](https://avatars.githubusercontent.com/u/2153591?v=4)](https://github.com/denis-n-ko "denis-n-ko (1 commits)")

---

Tags

configconfigurationjsonphptomlyamljsonconfigurationconfigyamltoml

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/yosymfony-config-loader/health.svg)

```
[![Health](https://phpackages.com/badges/yosymfony-config-loader/health.svg)](https://phpackages.com/packages/yosymfony-config-loader)
```

###  Alternatives

[hassankhan/config

Lightweight configuration file loader that supports PHP, INI, XML, JSON, and YAML files

1.0k13.4M156](/packages/hassankhan-config)[m1/vars

Vars is a simple to use and easily extendable configuration loader with in built loaders for ini, json, PHP, toml, XML and yaml/yml file types. It also comes with in built support for Silex and more frameworks to come soon.

64124.2k1](/packages/m1-vars)[thewunder/conphigure

Framework Agnostic Configuration Library

3115.2k](/packages/thewunder-conphigure)[northwoods/config

Simple configuration loader

1515.9k](/packages/northwoods-config)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
