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

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

cupoftea/config-editor
======================

Programatically edit array-based php configuration files.

v1.0.1(5y ago)09MITPHPPHP ^7.3 || ^8.0

Since Feb 6Pushed 5y ago1 watchersCompare

[ Source](https://github.com/CupOfTea696/ConfigEditor)[ Packagist](https://packagist.org/packages/cupoftea/config-editor)[ Docs](https://github.com/CupOfTea696/ConfigEditor)[ RSS](/packages/cupoftea-config-editor/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (2)Dependencies (3)Versions (3)Used By (0)

Config Editor
=============

[](#config-editor)

Programatically edit array-based php configuration files.

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

[](#installation)

Config Editor can be installed via [Composer](https://getcomposer.org/) using the require command.

```
$ composer require cupoftea/config-editor

```

Usage
-----

[](#usage)

### Basic Example

[](#basic-example)

```
/**
 * Config Editor does not include file read & write operations
 * and must be passed a string representing the file contents.
 */
$config = file_get_contents('config/my_config.php');
$editor = new \CupOfTea\Config\Editor($config);

// Values can be set by passing a key and a value, or passing it an associative array with the values you want to set.
// Editor::set() returns the editor instance for easy chaining.
$editor->set('foo', 'bar')
    ->set(['baz' => 'qux', 'quux' => 'quuz']);

// Nested values can be set using array "dot" notation
$editor->set('paths.views', 'resources/views')
    ->set('paths.lang', 'resources/lang');

// Use the unset() method to completely remove a key from the configuration.
$editor->unset('foo')
    ->unset(['baz', 'quux']);

// Once you are done making edits, you can compile the config back to a string and write it to a file.
$newConfig = $editor->compile();
file_put_contents('config/my_edited_config.php', $newConfig);
```

### Configuration File

[](#configuration-file)

A configuration file must return an array. The array cannot be computed at runtime.

When using an invalid configuration file, the `Editor::compile()` method will throw a `CupOfTea\Config\InvalidConfigurationException`.

Valid:

```
