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

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

camoo/config
============

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

1.0.3(2y ago)1163↓100%1MITPHPPHP &gt;=8.1

Since Jul 9Pushed 2y agoCompare

[ Source](https://github.com/camoo/config)[ Packagist](https://packagist.org/packages/camoo/config)[ Docs](http://hassankhan.me/config/)[ RSS](/packages/camoo-config/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (2)Versions (6)Used By (1)

Config
======

[](#config)

Config is a file configuration loader that supports PHP, INI, XML, JSON, YML, Properties and serialized files and strings.

 [ ![Build Status](https://github.com/camoo/config/actions/workflows/continuous-integration.yml/badge.svg) ](https://github.com/camoo/config) [ ![camoo-badge](https://camo.githubusercontent.com/087f6d8b78abd3ccb31a70cb0ace2ff8909315b319b89fb27d9478cd3d179ceb/68747470733a2f2f636f6465636f762e696f2f67682f63616d6f6f2f636f6e6669672f6272616e63682f6d61696e2f67726170682f62616467652e737667) ](https://codecov.io/gh/camoo/config)

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

[](#requirements)

Config requires PHP 8.1+.

> **IMPORTANT:** If you want to use YAML files or strings, require the [Symfony Yaml component](https://github.com/symfony/Yaml) in your `composer.json`.

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

[](#installation)

The supported way of installing Config is via Composer.

```
$ composer require camoo/config
```

Usage
-----

[](#usage)

Config is designed to be very simple and straightforward to use. All you can do with it is load, get, and set.

### Loading files

[](#loading-files)

The `Config` object can be created via the factory method `load()`, or by direct instantiation:

```
use Camoo\Config\Config;
use Camoo\Config\Enum\Parser;

// Load a single file
$conf = Config::load('config.json');
$conf = new Config('config.json');

// Load values from multiple files
$conf = new Config(['config.json', 'config.xml']);

// Load all supported files in a directory
$conf = new Config(__DIR__ . '/config');

// Load values from optional files
$conf = new Config(['config.dist.json', '?config.json']);

// Load a file using specified parser
$conf = new Config('configuration.config', Parser::JSON);
```

Files are parsed and loaded depending on the file extension or specified parser. If the parser is specified, it **will be used for all files**. Note that when loading multiple files, entries with **duplicate keys will take on the value from the last loaded file**.

When loading a directory, the path is `glob`ed and files are loaded in by name alphabetically.

**Warning:** Do not include untrusted configuration in PHP format. It could contain and execute malicious code.

### Loading string

[](#loading-string)

Configuration from string can be created via the factory method `load()` or by direct instantiation, with argument `$string` set to `true`:

```
use Camoo\Config\Config;
use Camoo\Config\Enum\Parser;
use Camoo\Config\Parser\Json;
use Camoo\Config\Parser\Yaml;

$settingsJson = get('app.timeout', 3000);
```

The second method, is by using it like an array:

```
// Get value using a simple key
$debug = $conf['debug'];

// Get value using a nested key
$secret = $conf['security.secret'];

// Get nested value like you would from a nested array
$secret = $conf['security']['secret'];
```

The third method, is by using the `all()` method:

```
// Get all values
$data = $conf->all();
```

### Setting values

[](#setting-values)

Although Config supports setting values via `set()` or, via the array syntax, **any changes made this way are NOT reflected back to the source files**. By design, if you need to make changes to your configuration files, you have to do it manually.

```
$conf = Config::load('config.json');

// Sample value from our config file
assert($conf['secret'] == '123');

// Update config value to something else
$conf['secret'] = '456';

// Reload the file
$conf = Config::load('config.json');

// Same value as before
assert($conf['secret'] == '123');

// This will fail
assert($conf['secret'] == '456');
```

### Saving config

[](#saving-config)

It is possible to save the config back to a file in any of the supported formats except PHP.

```
use use Camoo\Config\Enum\Writer;

$config = Config::load('config.json');

$ini = $config->toString(Writer::INI); // Encode to string if you want to save the file yourself

$config->toFile('config.yaml');
$config->toFile('config.txt', Writer::SERIALIZE); // you can also force the writer
```

### Using with default values

[](#using-with-default-values)

Sometimes in your own projects you may want to use Config for storing application settings, without needing file I/O. You can do this by extending the `AbstractConfig` class and populating the `getDefaults()` method:

```
class MyConfig extends AbstractConfig
{
    protected function getDefaults()
    {
        return [
            'host' => 'localhost',
            'port'    => 80,
            'servers' => [
                'host1',
                'host2',
                'host3'
            ],
            'application' => [
                'name'   => 'configuration',
                'secret' => 's3cr3t'
            ]
        ];
    }
}
```

### Merging instances

[](#merging-instances)

You may want merging multiple Config instances:

```
$conf1 = Config::load('conf1.json');
$conf2 = Config::load('conf2.json');
$conf1->merge($conf2);
```

### Examples of supported configuration files

[](#examples-of-supported-configuration-files)

Examples of simple, valid configuration files can be found [here](tests/mocks/pass).

Testing
-------

[](#testing)

```
$ phpunit
```

Resources
---------

[](#resources)

---

- [Report issues](https://github.com/camoo/config/issues)

Credits
-------

[](#credits)

- [Camoo Sarl](https://github.com/camoo)
- [Hassan Khan](https://github.com/hassankhan)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community21

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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 ~79 days

Total

4

Last Release

797d ago

### Community

Maintainers

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

---

Top Contributors

[![hassankhan](https://avatars.githubusercontent.com/u/1781985?v=4)](https://github.com/hassankhan "hassankhan (125 commits)")[![DavidePastore](https://avatars.githubusercontent.com/u/1949364?v=4)](https://github.com/DavidePastore "DavidePastore (74 commits)")[![filips123](https://avatars.githubusercontent.com/u/16626308?v=4)](https://github.com/filips123 "filips123 (31 commits)")[![noodlehaus](https://avatars.githubusercontent.com/u/683976?v=4)](https://github.com/noodlehaus "noodlehaus (19 commits)")[![markdegrootnl](https://avatars.githubusercontent.com/u/3601019?v=4)](https://github.com/markdegrootnl "markdegrootnl (16 commits)")[![nbayramberdiyev](https://avatars.githubusercontent.com/u/23094428?v=4)](https://github.com/nbayramberdiyev "nbayramberdiyev (14 commits)")[![camoo](https://avatars.githubusercontent.com/u/24289021?v=4)](https://github.com/camoo "camoo (9 commits)")[![equinoxmatt](https://avatars.githubusercontent.com/u/5101742?v=4)](https://github.com/equinoxmatt "equinoxmatt (7 commits)")[![mp3000mp](https://avatars.githubusercontent.com/u/54006012?v=4)](https://github.com/mp3000mp "mp3000mp (6 commits)")[![dmleach](https://avatars.githubusercontent.com/u/3705674?v=4)](https://github.com/dmleach "dmleach (4 commits)")[![ashnazg](https://avatars.githubusercontent.com/u/100170?v=4)](https://github.com/ashnazg "ashnazg (3 commits)")[![MPur](https://avatars.githubusercontent.com/u/5575697?v=4)](https://github.com/MPur "MPur (3 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (3 commits)")[![s4msung](https://avatars.githubusercontent.com/u/58741?v=4)](https://github.com/s4msung "s4msung (3 commits)")[![tomzx](https://avatars.githubusercontent.com/u/188960?v=4)](https://github.com/tomzx "tomzx (2 commits)")[![hannesvdvreken](https://avatars.githubusercontent.com/u/1410358?v=4)](https://github.com/hannesvdvreken "hannesvdvreken (2 commits)")[![mre](https://avatars.githubusercontent.com/u/175809?v=4)](https://github.com/mre "mre (1 commits)")[![cideveloper](https://avatars.githubusercontent.com/u/842530?v=4)](https://github.com/cideveloper "cideveloper (1 commits)")[![AydinHassan](https://avatars.githubusercontent.com/u/2817002?v=4)](https://github.com/AydinHassan "AydinHassan (1 commits)")[![o5](https://avatars.githubusercontent.com/u/218562?v=4)](https://github.com/o5 "o5 (1 commits)")

---

Tags

jsonconfigurationxmlconfigyamlymliniunframeworkmicrophp

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[hassankhan/config

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

97513.5M169](/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.

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

Framework Agnostic Configuration Library

3115.9k](/packages/thewunder-conphigure)[davidepastore/slim-config

A slim middleware to read configuration from different files based on hassankhan/config

338.9k1](/packages/davidepastore-slim-config)

PHPackages © 2026

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