PHPackages                             league/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. league/config

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

league/config
=============

Define configuration arrays with strict schemas and access values with dot notation

v1.2.0(3y ago)564302.2M—0.2%19[4 PRs](https://github.com/thephpleague/config/pulls)19BSD-3-ClausePHPPHP ^7.4 || ^8.0CI passing

Since May 31Pushed today5 watchersCompare

[ Source](https://github.com/thephpleague/config)[ Packagist](https://packagist.org/packages/league/config)[ Docs](https://config.thephpleague.com)[ Fund](https://www.colinodell.com/sponsor)[ Fund](https://www.paypal.me/colinpodell/10.00)[ RSS](/packages/league-config/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (7)Versions (11)Used By (19)

league/config
=============

[](#leagueconfig)

[![Latest Version](https://camo.githubusercontent.com/4c5ba0266ccfa35b4c554d9440eaa6293f4dacdc39b5098a940f12f4e259be27/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c65616775652f636f6e6669672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/league/config)[![Total Downloads](https://camo.githubusercontent.com/d742973d6d2c5bc3665b7512341205ca1238ae4c72e3e897ce1bb7d78244654d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c65616775652f636f6e6669672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/league/config)[![Software License](https://camo.githubusercontent.com/d8c1f1b4c1b899449e9539d4de1ca66abde4c190f41ce41e7abc3330da5cad2e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4253442d2d332d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Build Status](https://camo.githubusercontent.com/ba9c4e067a17c556d2a23ac2cde3dedc42f4e9c6243f483aa640903ecd94cabd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f7468657068706c65616775652f636f6e6669672f54657374732f6d61696e2e7376673f7374796c653d666c61742d737175617265)](https://github.com/thephpleague/config/actions?query=workflow%3ATests+branch%3Amain)[![Coverage Status](https://camo.githubusercontent.com/364e675d6fd0d61f6374dacc7dfcef23463ee8ed2e08c6b14eeb00733c1b3bbf/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f7468657068706c65616775652f636f6e6669672e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/thephpleague/config/code-structure)[![Quality Score](https://camo.githubusercontent.com/8826715a9cc7944e053e783ea9054cfd2d7f7f7f90f742b477be8e12f446d3f6/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7468657068706c65616775652f636f6e6669672e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/thephpleague/config)[![Sponsor development of this project](https://camo.githubusercontent.com/2e662697b46a37233abdd7e45373397aab0bd5206336533151cdf42455d81048/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f73706f6e736f72253230746869732532307061636b6167652d2545322539442541342d6666363962342e7376673f7374796c653d666c61742d737175617265)](https://www.colinodell.com/sponsor)

**league/config** helps you define nested configuration arrays with strict schemas and access configuration values with dot notation. It was created by [Colin O'Dell](https://www.twitter.com/colinodell).

📦 Installation
--------------

[](#-installation)

This project requires PHP 7.4 or higher. To install it via [Composer](https://getcomposer.org/) simply run:

```
composer require league/config
```

🧰️ Basic Usage
--------------

[](#️-basic-usage)

The `Configuration` class provides everything you need to define the configuration structure and fetch values:

```
use League\Config\Configuration;
use Nette\Schema\Expect;

// Define your configuration schema
$config = new Configuration([
    'database' => Expect::structure([
        'driver' => Expect::anyOf('mysql', 'postgresql', 'sqlite')->required(),
        'host' => Expect::string()->default('localhost'),
        'port' => Expect::int()->min(1)->max(65535),
        'ssl' => Expect::bool(),
        'database' => Expect::string()->required(),
        'username' => Expect::string()->required(),
        'password' => Expect::string()->nullable(),
    ]),
    'logging' => Expect::structure([
        'enabled' => Expect::bool()->default($_ENV['DEBUG'] == true),
        'file' => Expect::string()->deprecated("use logging.path instead"),
        'path' => Expect::string()->assert(function ($path) { return \is_writeable($path); })->required(),
    ]),
]);

// Set the values, either all at once with `merge()`:
$config->merge([
    'database' => [
        'driver' => 'mysql',
        'port' => 3306,
        'database' => 'mydb',
        'username' => 'user',
        'password' => 'secret',
    ],
]);

// Or one-at-a-time with `set()`:
$config->set('logging.path', '/var/log/myapp.log');

// You can now retrieve those values with `get()`.
// Validation and defaults will be applied for you automatically
$config->get('database');        // Fetches the entire "database" section as an array
$config->get('database.driver'); // Fetch a specific nested value with dot notation
$config->get('database/driver'); // Fetch a specific nested value with slash notation
$config->get('database.host');   // Returns the default value "localhost"
$config->get('logging.path');    // Guaranteed to be writeable thanks to the assertion in the schema

// If validation fails an `InvalidConfigurationException` will be thrown:
$config->set('database.driver', 'mongodb');
$config->get('database.driver'); // InvalidConfigurationException

// Attempting to fetch a non-existent key will result in an `InvalidConfigurationException`
$config->get('foo.bar');

// You could avoid this by checking whether that item exists:
$config->exists('foo.bar'); // Returns `false`
```

📓 Documentation
---------------

[](#-documentation)

Full documentation can be found at [config.thephpleague.com](https://config.thephpleague.com/).

💭 Philosophy
------------

[](#-philosophy)

This library aims to provide a **simple yet opinionated** approach to configuration with the following goals:

- The configuration should operate on **arrays with nested values** which are easily accessible
- The configuration structure should be **defined with strict schemas** defining the overall structure, allowed types, and allowed values
- Schemas should be defined using a **simple, fluent interface**
- You should be able to **add and combine schemas but never modify existing ones**
- Both the configuration values and the schema should be **defined and managed with PHP code**
- Schemas should be **immutable**; they should never change once they are set
- Configuration values should never define or influence the schemas

As a result, this library will likely **never** support features like:

- Loading and/or exporting configuration values or schemas using YAML, XML, or other files
- Parsing configuration values from a command line or other user interface
- Dynamically changing the schema, allowed values, or default values based on other configuration values

If you need that functionality you should check out other libraries like:

- [symfony/config](https://symfony.com/doc/current/components/config.html)
- [symfony/options-resolver](https://symfony.com/doc/current/components/options_resolver.html)
- [hassankhan/config](https://github.com/hassankhan/config)
- [consolidation/config](https://github.com/consolidation/config)
- [laminas/laminas-config](https://docs.laminas.dev/laminas-config/)

🏷️ Versioning
-------------

[](#️-versioning)

[SemVer](http://semver.org/) is followed closely. Minor and patch releases should not introduce breaking changes to the codebase.

Any classes or methods marked `@internal` are not intended for use outside this library and are subject to breaking changes at any time, so please avoid using them.

🛠️ Maintenance &amp; Support
----------------------------

[](#️-maintenance--support)

When a new **minor** version (e.g. `1.0` -&gt; `1.1`) is released, the previous one (`1.0`) will continue to receive security and critical bug fixes for *at least* 3 months.

When a new **major** version is released (e.g. `1.1` -&gt; `2.0`), the previous one (`1.1`) will receive critical bug fixes for *at least* 3 months and security updates for 6 months after that new release comes out.

(This policy may change in the future and exceptions may be made on a case-by-case basis.)

👷‍️ Contributing
----------------

[](#‍️-contributing)

Contributions to this library are **welcome**! We only ask that you adhere to our [contributor guidelines](https://github.com/thephpleague/config/blob/main/.github/CONTRIBUTING.md) and avoid making changes that conflict with our Philosophy above.

🧪 Testing
---------

[](#-testing)

```
composer test
```

📄 License
---------

[](#-license)

**league/config** is licensed under the BSD-3 license. See the [`LICENSE.md`](https://github.com/thephpleague/config/blob/main/LICENSE.md) file for more details.

🗺️ Who Uses It?
---------------

[](#️--who-uses-it)

This project is used by [league/commonmark](https://commonmark.thephpleague.com).

###  Health Score

62

—

FairBetter than 99% of packages

Maintenance65

Regular maintenance activity

Popularity75

Solid adoption and visibility

Community32

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 67% 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 ~93 days

Recently: every ~136 days

Total

7

Last Release

1254d ago

PHP version history (2 changes)v1.0.0PHP ^7.2.5 || ^8.0

v1.1.0PHP ^7.4 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/4325b62a6ad366c731c3120595d861469be50f9da88df3ea99752c30ff98c179?d=identicon)[colinodell](/maintainers/colinodell)

---

Top Contributors

[![colinodell](https://avatars.githubusercontent.com/u/202034?v=4)](https://github.com/colinodell "colinodell (59 commits)")[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (14 commits)")[![pdelre](https://avatars.githubusercontent.com/u/1379248?v=4)](https://github.com/pdelre "pdelre (8 commits)")[![driesvints](https://avatars.githubusercontent.com/u/594614?v=4)](https://github.com/driesvints "driesvints (2 commits)")[![Awilum](https://avatars.githubusercontent.com/u/477114?v=4)](https://github.com/Awilum "Awilum (2 commits)")[![nyamsprod](https://avatars.githubusercontent.com/u/51073?v=4)](https://github.com/nyamsprod "nyamsprod (1 commits)")[![acairns](https://avatars.githubusercontent.com/u/705212?v=4)](https://github.com/acairns "acairns (1 commits)")[![praem90](https://avatars.githubusercontent.com/u/6235720?v=4)](https://github.com/praem90 "praem90 (1 commits)")

---

Tags

configconfigurationhacktoberfestphpschemaschemaconfigurationarrayconfigdotnesteddot-access

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[symfony/options-resolver

Provides an improved replacement for the array\_replace PHP function

3.2k493.9M1.6k](/packages/symfony-options-resolver)[dflydev/dot-access-configuration

Given a deep data structure representing a configuration, access configuration by dot notation.

13414.5M4](/packages/dflydev-dot-access-configuration)[jbzoo/data

An extended version of the ArrayObject object for working with system settings or just for working with data arrays

891.6M23](/packages/jbzoo-data)[caseyamcl/configula

A simple, but versatile, PHP config loader

42146.6k6](/packages/caseyamcl-configula)[illuminatech/array-factory

Allows DI aware object creation from array definition

2159.6k6](/packages/illuminatech-array-factory)[selective/transformer

A strictly typed array transformer with dot-access, fluent interface and filters.

3817.8k1](/packages/selective-transformer)

PHPackages © 2026

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