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

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

carstenwindler/config
=====================

Very simple config

v1.1(5y ago)14.6kMITPHPPHP ^7.3 || ^8.0CI failing

Since Aug 26Pushed 5y ago1 watchersCompare

[ Source](https://github.com/carstenwindler/config)[ Packagist](https://packagist.org/packages/carstenwindler/config)[ Docs](https://github.com/carstenwindler/config)[ RSS](/packages/carstenwindler-config/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (3)Dependencies (4)Versions (10)Used By (0)

Config
======

[](#config)

[![Latest Stable Version](https://camo.githubusercontent.com/271f123776121fc5ff448ed9351b3ede420576b448d1ee515ef410f56ce45971/68747470733a2f2f706f7365722e707567782e6f72672f6361727374656e77696e646c65722f636f6e6669672f762f737461626c65)](https://packagist.org/packages/carstenwindler/config)[![Build Status](https://camo.githubusercontent.com/5b491760daeba8534e04772a0b2fd0f2423c97736201dd07334e6769578dd7bc/68747470733a2f2f7472617669732d63692e6f72672f6361727374656e77696e646c65722f636f6e6669672e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/carstenwindler/config)[![Minimum PHP Version](https://camo.githubusercontent.com/11abc476f7baba2167000d3198fc0e0d420f26d320f5aab0e199dc8fda059cf2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6361727374656e77696e646c65722f636f6e6669672e737667)](https://php.net/)[![License](https://camo.githubusercontent.com/c98f1399e7cfc769b2fcf4ec6d4f83ed791bbb3428a31bf19cace60c6cfb82c0/68747470733a2f2f706f7365722e707567782e6f72672f6361727374656e77696e646c65722f636f6e6669672f6c6963656e7365)](https://packagist.org/packages/carstenwindler/config)[![Total Downloads](https://camo.githubusercontent.com/23ebc78fe5a5617a18fa0249dae1a7cf60e555cf5f33bc22170f09624dca84d4/68747470733a2f2f706f7365722e707567782e6f72672f6361727374656e77696e646c65722f636f6e6669672f646f776e6c6f616473)](https://packagist.org/packages/carstenwindler/config)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/7a4851b23ed4f182663c5f8e7649a1060760b2d2dac49660ea217c06e2fdc653/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6361727374656e77696e646c65722f636f6e6669672f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/carstenwindler/config/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/52cb161f7b44153cd8f4f0b0a41897226aaed98eb6b3f0f6e4aeee58c4442b8c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6361727374656e77696e646c65722f636f6e6669672f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/carstenwindler/config/?branch=master)

About this package
------------------

[](#about-this-package)

Drop dead simple config package. Use it to bootstrap and access your configuration settings within your PHP application.

Slim, tested, works from PHP 7.3 upwards, and won't add any other dependencies to your codebase.

### Requirements

[](#requirements)

- PHP 7.3 (or above)

Yep, that's it.

### Installation

[](#installation)

Via composer:

```
$ composer require carstenwindler/config
```

Why one more config package?
----------------------------

[](#why-one-more-config-package)

This package started as even simpler config class I added to a project once, and I kept using and improving it. Add some point, I decided to publish it as a package. There are good reasons for using other (bigger) packages for sure, but if you just need a configuration class that won't add any overhead to your project, it might be the right choice.

### Cascading configs

[](#cascading-configs)

The basic idea behind this Config package is the idea of "Cascading configs": you don't lpad the whole config at once, but build it up step by step.

```
main.php
\- environment/develop.php
 \- markets/my_market.php

```

You start with a "main configuration" which is contains basic configuration for all purposes, and then you add more (or overwrite previous) configuration depending on the environment you are. For example, on the local development environment you might want to use different versions of web services than on production.

#### Simple "array dot" notation

[](#simple-array-dot-notation)

Unbeatable fast and easy is to use the "array dot" notation to address configuration items (e.g. `'lvl1.lvl2.lvl3.foo'`).

This has a big drawback though - the config is addressed using strings, which can lead to "rotting configuration" easily. Checkout below "Strict mode" section on how to fight that.

Usage
-----

[](#usage)

### Initialization

[](#initialization)

There are 3 ways to set the configuration.

#### Load from file

[](#load-from-file)

Often enough, application configurations are simply stored in files, so this is the standard use case for Config.

Config uses PHP arrays as the only configuration format. To store arrays in files, you could e.g. use this notation:

```
