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

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

juzaweb/config
==============

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

2.2.1(5y ago)2593.4k2MITPHPPHP &gt;=5.5.9

Since Nov 19Pushed 4y agoCompare

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

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

Config
======

[](#config)

[![Latest version](https://camo.githubusercontent.com/bf2c09fe22a312b89c5f49fcb8d15f390f9eea9d237dfa38a1483bfbc37cf11b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f68617373616e6b68616e2f636f6e6669672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hassankhan/config)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](http://hassankhan.mit-license.org)[![Build Status](https://camo.githubusercontent.com/1e8f6caf8d4271f2ed39738b05909cee7eb0c0429a3a82413caab99453be60f1/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f68617373616e6b68616e2f636f6e6669672f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/hassankhan/config)[![Coverage Status](https://camo.githubusercontent.com/a0035378103701b4b0b2f6437c57020c6c20f76c7441f958499cba19aaa26922/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f68617373616e6b68616e2f636f6e6669672e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/hassankhan/config/code-structure)[![Quality Score](https://camo.githubusercontent.com/ec8eb26f45014cb9e813c0cfbf48b2568eb6c3cfc081c5ac7b8d1fbf3405e87c/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f68617373616e6b68616e2f636f6e6669672e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/hassankhan/config)[![Total Downloads](https://camo.githubusercontent.com/8c201d4e7a3a0932b2771456ce97712454901dd41ae6cf3ef828fdfc206b39a2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f68617373616e6b68616e2f636f6e6669672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/hassankhan/config)[![Gitter](https://camo.githubusercontent.com/82b37b704e2e79c5d50f45f6cf0aab5873f32ffcca6c38864d72b1a66c2ba48c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4749545445522d4a4f494e253230434841542532302545322538362539322d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://gitter.im/hassankhan/config?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)

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

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

[](#requirements)

Config requires PHP 5.5.9+.

> **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 hassankhan/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 Noodlehaus\Config;
use Noodlehaus\Parser\Json;

// 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', new 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 Noodlehaus\Config;
use Noodlehaus\Parser\Json;
use Noodlehaus\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.

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

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

$config->toFile('config.yaml');
$config->toFile('config.txt', new 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
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email [contact@hassankhan.me](mailto:contact@hassankhan.me?subject=%5BSECURITY%5D%20Config%20Security%20Issue) instead of using the issue tracker.

Credits
-------

[](#credits)

- [Hassan Khan](https://github.com/hassankhan)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity33

Limited adoption so far

Community22

Small or concentrated contributor base

Maturity69

Established project with proven stability

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

Recently: every ~169 days

Total

28

Last Release

1988d ago

Major Versions

0.11.2 → 1.0.02018-03-03

1.1.0 → 2.0.02018-10-03

PHP version history (3 changes)0.0.1PHP &gt;= 5.3.0

0.4.0PHP &gt;=5.3.0

1.0.0PHP &gt;=5.5.9

### Community

Maintainers

![](https://www.gravatar.com/avatar/3169e8a8781068840e9300a57785089da521287dbe0279fc9cc7e8de1c1d95a9?d=identicon)[juzaweb](/maintainers/juzaweb)

---

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 (42 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)")[![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)")[![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)")[![wenschk](https://avatars.githubusercontent.com/u/13115759?v=4)](https://github.com/wenschk "wenschk (1 commits)")[![yannickroger](https://avatars.githubusercontent.com/u/4035241?v=4)](https://github.com/yannickroger "yannickroger (1 commits)")[![AydinHassan](https://avatars.githubusercontent.com/u/2817002?v=4)](https://github.com/AydinHassan "AydinHassan (1 commits)")[![cideveloper](https://avatars.githubusercontent.com/u/842530?v=4)](https://github.com/cideveloper "cideveloper (1 commits)")[![ftwbzhao](https://avatars.githubusercontent.com/u/492682?v=4)](https://github.com/ftwbzhao "ftwbzhao (1 commits)")[![garoevans](https://avatars.githubusercontent.com/u/1016708?v=4)](https://github.com/garoevans "garoevans (1 commits)")[![gbhorwood](https://avatars.githubusercontent.com/u/4615659?v=4)](https://github.com/gbhorwood "gbhorwood (1 commits)")

---

Tags

jsonconfigurationxmlconfigyamlymliniunframeworkmicrophp

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[hassankhan/config

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

97513.5M170](/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)
