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

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

phlak/config
============

Config loading and management

9.0.0(1mo ago)59332.0k↓33.8%10[3 issues](https://github.com/PHLAK/Config/issues)[1 PRs](https://github.com/PHLAK/Config/pulls)10MITPHPPHP &gt;= 8.2CI passing

Since Aug 21Pushed 2w ago4 watchersCompare

[ Source](https://github.com/PHLAK/Config)[ Packagist](https://packagist.org/packages/phlak/config)[ GitHub Sponsors](https://github.com/sponsors/PHLAK)[ Fund](https://paypal.me/ChrisKankiewicz)[ RSS](/packages/phlak-config/feed)WikiDiscussions master Synced yesterday

READMEChangelog (9)Dependencies (12)Versions (19)Used By (10)

 [![Config](config.png)](config.png)

 [![Join our Community](https://camo.githubusercontent.com/073a08ec4c3c801a8e24c53184d95a6562d74582854cb46320bcd76ef48ea543/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4a6f696e5f7468652d436f6d6d756e6974792d3762313666662e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/PHLAK/Config/discussions) [![Become a Sponsor](https://camo.githubusercontent.com/00da07edf5fbff7528a4743d85563603f9284f02680e0ab1e73652e680878548/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4265636f6d655f612d53706f6e736f722d6363343139352e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/users/PHLAK/sponsorship) [![One-time Donation](https://camo.githubusercontent.com/e9b5aa71ffdb17943c10c6d6b4a3132b66a938495331e488ecbdad1f3c078879/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4d616b655f612d446f6e6174696f6e2d3030366262362e7376673f7374796c653d666f722d7468652d6261646765)](https://paypal.me/ChrisKankiewicz)
 [![Latest Stable Version](https://camo.githubusercontent.com/8db785b8c05ba7d0108a5fe3b0e48bd088c9d65973b2d51527474bbb77db7d2f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f50484c414b2f436f6e6669672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/PHLAK/Config) [![Total Downloads](https://camo.githubusercontent.com/b037b622beacc45743804340d6dd67cf7f5fdf160191a741ac01cb4493080d03/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f50484c414b2f436f6e6669672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/PHLAK/Config) [![License](https://camo.githubusercontent.com/98329e5e6f67af0372996f025513de27b7aa36fb67121e6bd29200f9b177aeba/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f50484c414b2f436f6e6669672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/PHLAK/Config) [![](https://camo.githubusercontent.com/ed0444f0805b4fa27fb4d6afcea7e77ebd0cbe9a2fde9b000a36f73097b39316/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f50484c414b2f436f6e6669672f746573742d73756974652e79616d6c3f7374796c653d666c61742d737175617265)](https://github.com/PHLAK/Config/actions/workflows/test-suite.yaml)

 PHP library for simple configuration management -- Created by [Chris Kankiewicz](https://www.ChrisKankiewicz.com) ([@PHLAK.dev](https://bsky.app/profile/phlak.dev))

---

Introduction
------------

[](#introduction)

Config is a simple PHP configuration management library supporting multiple configuration file formats and an expressive API.

Supported file formats:

- PHP
- INI
- JSON
- [TOML](https://github.com/toml-lang/toml)
- YAML
- XML

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

[](#requirements)

- [PHP](https://php.net)

Install with Composer
---------------------

[](#install-with-composer)

```
composer require phlak/config
```

Initializing the Client
-----------------------

[](#initializing-the-client)

First, import `Config`:

```
use PHLAK\Config\Config;
```

Then instantiate the class:

```
$config = new Config($context, $prefix = null);
```

Where `$context` is one of the following:

- A path to a supported file type
- A directory path containing one or more supported file types
- An array of configuration options

And `$prefix` is a string to be used as a key prefix for options of this `Config` object.

Configuration File Formats
--------------------------

[](#configuration-file-formats)

### PHP

[](#php)

A PHP configuration file must have the `.php` file extension, be a valid PHP file and and return a valid PHP array.

 Example PHP file```

    mysql

            database.sqlite

            localhost
            blog
            blogger
            hunter2
            utf8

```

Usage
-----

[](#usage)

### \_\_construct

[](#__construct)

> Create a new `Config` object.

```
Config::__construct( mixed $context [, string $prefix = null ] ) : Config
```

 `$context` Raw array of configuration options or path to a configuration file or directory containing one or more configuration files `$prefix` A key under which the loaded config will be nested#### Examples

[](#examples)

Create a new `Config` object from a YAML file.

```
$config = new Config('path/to/config.yaml');
```

Create a new `Config` object from a directory of config files.

```
$config = new Config('path/to/configs/');
```

Create a new `Config` object from an array.

```
$config = new Config([
    'hostname' => 'localhost',
    'port' => 12345
]);
```

---

### set

[](#set)

> Store a config value with a specified key.

```
Config::set( string $key, mixed $value ) : bool
```

 `$key` Unique configuration option key `$value` Config item value#### Example

[](#example)

```
$config->set('hostname', 'localhost');
$config->set('port', 12345);
```

---

### get

[](#get)

> Retrieve a configuration option via a provided key.

```
Config::get( string $key [, mixed $default = null ] ) : mixed
```

 `$key` Unique configuration option key `$value` Config item value#### Examples

[](#examples-1)

```
// Return the hostname option value or null if not found.
$config->get('hostname');
```

Define a default value to return if the option is not set.

```
// Returns 'localhost' if hostname option is not set
$config->get('hostname', 'localhost');
```

---

### has

[](#has)

> Check for the existence of a configuration item.

```
Config::has( string $key ) : bool
```

 `$key` Unique configuration option key#### Example

[](#example-1)

```
$config = new Config([
    'hostname' => 'localhost'
]);

$config->has('hostname'); // Returns true
$config->has('port');     // Returns false
```

---

### append

[](#append)

> Append a value onto an existing array configuration option.

```
Config::append( string $key, mixed $value ) : bool
```

 `$key` Unique configuration option key `$value` Config item value#### Example

[](#example-2)

Append `baz` to the `tags` config item array.

```
$config->set('tags', ['foo', 'bar']);
$config->append('tags', 'baz'); // ['foo', 'bar', 'baz']
```

---

### prepend

[](#prepend)

> Prepend a value onto an existing array configuration option.

```
Config::prepend( string $key, mixed $value ) : bool
```

 `$key` Unique configuration option key `$value` Config item value#### Example

[](#example-3)

Prepend `baz` to the `tags` config item array.

```
$config->set('tags', ['foo', 'bar'])
$config->prepend('tags', 'baz'); // ['baz', 'foo', 'bar']
```

---

### unset

[](#unset)

> Unset a configuration option via a provided key.

```
Config::unset( string $key ) : bool
```

 `$key` Unique configuration option key#### Example

[](#example-4)

```
$config->unset('hostname');
```

---

### load

[](#load)

> Load configuration options from a file or directory.

```
Config::load( string $path [, string $prefix = null [, bool $override = true ]] ) : self
```

 `$path` Path to configuration file or directory `$prefix` A key under which the loaded config will be nested `$override` Whether or not to override existing options with values from the loaded file#### Examples

[](#examples-2)

Load a single additional file.

```
$config->load('path/to/config.php');
```

Load an additional file with a prefix.

```
$config->load('database.php', 'database');
```

Load an additional file without overriding existing values.

```
$config->load('additional-options.php', null, false);
```

---

### merge

[](#merge)

> Merge another `Config` object into this one.

```
Config::merge( ConfigInterface $config [, bool $override = true ] ) : self
```

 `$config` Instance of ConfigInterface `$override` Whether or not to override existing options with values from the merged config object#### Examples

[](#examples-3)

Merge `$anotherConfig` into `$config` and override values in `$config` with values from `$anotherConfig`.

```
$anotherConfig = new Config('some/config.php');

$config->merge($anotherConfig);
```

Merge `$anotherConfig` into `$config` without overriding any values. Duplicate values in `$anotherConfig` will be lost.

```
$anotherConfig = new Config('some/config.php');

$config->merge($anotherConfig, false);
```

---

### split

[](#split)

> Split a sub-array of configuration options into its own `Config` object.

```
Config::split( string $key ) : Config
```

 `$key` Unique configuration option key#### Example

[](#example-5)

```
$config = new Config([
    'foo' => 'foo',
    'bar' => [
        'baz' => 'barbaz'
    ],
]);

$barConfig = $config->split('bar');

$barConfig->get('baz');  // Returns 'barbaz'
```

---

### toArray

[](#toarray)

> Return the entire configuration as an array.

```
Config::toArray( void ) : array
```

#### Example

[](#example-6)

```
$config = new Config(['foo' => 'foo']);

$config->toArray(); // Returns ['foo' => 'foo']
```

---

Troubleshooting
---------------

[](#troubleshooting)

For general help and support join our [GitHub Discussion](https://github.com/PHLAK/Config/discussions)or reach out on [Bluesky](https://bsky.app/profile/phlak.dev).

Please report bugs to the [GitHub Issue Tracker](https://github.com/PHLAK/Config/issues).

Copyright
---------

[](#copyright)

This project is licensed under the [MIT License](https://github.com/PHLAK/Config/blob/master/LICENSE).

###  Health Score

67

—

FairBetter than 99% of packages

Maintenance93

Actively maintained with recent releases

Popularity47

Moderate usage in the ecosystem

Community27

Small or concentrated contributor base

Maturity84

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 91.1% 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 ~254 days

Recently: every ~712 days

Total

15

Last Release

41d ago

Major Versions

4.0.0 → 5.0.02018-06-07

5.0.0 → 6.0.02018-08-04

6.1.0 → 7.0.02020-03-16

7.0.0 → 8.0.02023-10-31

8.0.0 → 9.0.02026-05-23

PHP version history (7 changes)0.1.0PHP &gt;=5.4

1.0.0PHP &gt;=5.5.9

2.0.0PHP &gt;=5.6

5.0.0PHP &gt;=7.0

6.0.0PHP &gt;=7.1

8.0.0PHP ^8.0 || ^8.1 || ^8.2

9.0.0PHP &gt;= 8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/53531?v=4)[Chris Kankiewicz](/maintainers/PHLAK)[@PHLAK](https://github.com/PHLAK)

---

Top Contributors

[![PHLAK](https://avatars.githubusercontent.com/u/53531?v=4)](https://github.com/PHLAK "PHLAK (185 commits)")[![Externaluse](https://avatars.githubusercontent.com/u/14993667?v=4)](https://github.com/Externaluse "Externaluse (10 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (3 commits)")[![brutto](https://avatars.githubusercontent.com/u/954379?v=4)](https://github.com/brutto "brutto (2 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (2 commits)")[![dependabot-preview[bot]](https://avatars.githubusercontent.com/in/2141?v=4)](https://github.com/dependabot-preview[bot] "dependabot-preview[bot] (1 commits)")

---

Tags

configconfig-managementinijsonphpphp-librarytomlxmlyaml

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M3.1k](/packages/craftcms-cms)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[rcsofttech/audit-trail-bundle

Enterprise-grade, high-performance Symfony audit trail bundle. Automatically track Doctrine entity changes with split-phase architecture, multiple transports (HTTP, Queue, Doctrine), and sensitive data masking.

1189.8k](/packages/rcsofttech-audit-trail-bundle)[friendsoftypo3/content-blocks

TYPO3 CMS Content Blocks - Content Types API | Define reusable components via YAML

103519.9k53](/packages/friendsoftypo3-content-blocks)[2lenet/crudit-bundle

The easy like Crud'it Bundle.

1616.4k14](/packages/2lenet-crudit-bundle)[aeliot/todo-registrar

Register TODOs from source code in issue tracker

153.0k](/packages/aeliot-todo-registrar)

PHPackages © 2026

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