PHPackages                             sunny-solaris/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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. sunny-solaris/config-editor

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

sunny-solaris/config-editor
===========================

A powerful PHP configuration file editor using nikic/php-parser. Programmatically read and modify PHP config files while preserving formatting and structure.

v1.1.0(2mo ago)056↓40%MITPHPPHP ^8.2

Since Feb 10Pushed 2mo agoCompare

[ Source](https://github.com/dev-sunny-solaris/Solaris-ConfigEditor)[ Packagist](https://packagist.org/packages/sunny-solaris/config-editor)[ Docs](https://github.com/dev-sunny-solaris/solaris-config-editor)[ RSS](/packages/sunny-solaris-config-editor/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (3)Used By (0)

Solaris Config Editor
=====================

[](#solaris-config-editor)

A powerful PHP configuration file editor that allows you to programmatically read and modify PHP configuration files while preserving formatting and structure. Built with [nikic/php-parser](https://github.com/nikic/PHP-Parser).

Features
--------

[](#features)

- 📝 **Read &amp; Modify** PHP config files programmatically
- 🔧 **Preserve Formatting** - Maintains original code formatting and structure
- 🎯 **Dot Notation** - Access nested arrays using dot notation (e.g., `database.connections.mysql.host`)
- 🔄 **Merge Config** - Merge configuration files intelligently
- 🚀 **Laravel Support** - Works seamlessly with Laravel 12+
- 🐘 **PHP 8.2+** - Modern PHP with typed properties and union types
- ⚙️ **Raw Code** - Support for raw PHP expressions via `setRaw()` and `addRaw()`

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

[](#requirements)

- PHP 8.2 or higher
- nikic/php-parser ^4.13 or ^5.0

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

[](#installation)

Install the package via Composer:

```
composer require solaris/config-editor
```

Quick Start
-----------

[](#quick-start)

### Basic Usage

[](#basic-usage)

```
use Solaris\ConfigEditor\ConfigEditor;

// Load a config file
$config = new ConfigEditor('config/database.php');

// Set a value
$config->set('connections.mysql.host', '127.0.0.1');
$config->set('connections.mysql.port', 3306);

// Get a value (has method)
if ($config->has('connections.mysql.username')) {
    // Do something
}

// Add a new key (throws exception if key exists)
$config->add('new_setting', 'value');

// Delete a key
$config->delete('connections.mysql');

// Save changes
$config->save();
```

### Working with Raw PHP Code

[](#working-with-raw-php-code)

For complex values like closures or PHP expressions:

```
// Set raw PHP code
$config->setRaw('cache.stores.redis.client', 'env("REDIS_CLIENT", "phpredis")');

// Add raw PHP code
$config->addRaw('logging.channels.custom', 'Log::channel("custom")');

// Push raw value to array
$config->pushRaw('providers', 'AppServiceProvider::class');
```

### Array Operations

[](#array-operations)

```
// Add value to existing array
$config->push('providers', 'MyServiceProvider::class');

// Push raw PHP expression to array
$config->pushRaw('middleware', 'TrustProxies::class');
```

### Merging Configurations

[](#merging-configurations)

```
$config = new ConfigEditor('config/app.php');

// Merge another config file
$config->merge('config/app.local.php')
    ->save();
```

### Fluent Interface

[](#fluent-interface)

Most methods return `$this`, allowing method chaining:

```
$config = new ConfigEditor('config/database.php');

$config
    ->set('connections.mysql.host', 'localhost')
    ->set('connections.mysql.database', 'myapp')
    ->set('connections.mysql.prefix', 'app_')
    ->merge('config/database.local.php')
    ->save();
```

API Reference
-------------

[](#api-reference)

### Constructor

[](#constructor)

```
new ConfigEditor(string $path)
```

Loads a PHP configuration file. Path can be with or without `.php` extension.

**Throws:** `RuntimeException` if file not found or is not a valid config file.

### Methods

[](#methods)

#### `set(string $key, mixed $value): void`

[](#setstring-key-mixed-value-void)

Set a configuration value. Creates intermediate arrays if needed.

#### `add(string $key, mixed $value): void`

[](#addstring-key-mixed-value-void)

Add a new configuration key. Throws exception if key already exists.

#### `setRaw(string $key, string $code): self`

[](#setrawstring-key-string-code-self)

Set a value using raw PHP code.

#### `addRaw(string $key, string $code): self`

[](#addrawstring-key-string-code-self)

Add a new value using raw PHP code.

#### `push(string $key, mixed $value): void`

[](#pushstring-key-mixed-value-void)

Add a value to an existing array.

#### `pushRaw(string $key, string $code): self`

[](#pushrawstring-key-string-code-self)

Add a raw PHP expression to an existing array.

#### `delete(string $key): void`

[](#deletestring-key-void)

Delete a configuration key.

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

[](#hasstring-key-bool)

Check if a configuration key exists.

#### `merge(string $path): self`

[](#mergestring-path-self)

Merge another configuration file. Returns self for chaining.

#### `save(?string $filename = null): self`

[](#savestring-filename--null-self)

Save changes to file. If filename is provided, saves to that file instead.

Laravel Integration
-------------------

[](#laravel-integration)

This package works seamlessly with Laravel's configuration files:

```
use Solaris\ConfigEditor\ConfigEditor;

// Edit Laravel config file
$config = new ConfigEditor(config_path('database.php'));

$config
    ->set('default', 'pgsql')
    ->set('connections.pgsql.host', env('DB_HOST', 'localhost'))
    ->save();
```

### Laravel Service Provider (Optional)

[](#laravel-service-provider-optional)

You can create a service provider to register this as a singleton:

```
namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Solaris\ConfigEditor\ConfigEditor;

class ConfigEditorProvider extends ServiceProvider
{
    public function register()
    {
        $this->app->singleton('config-editor', function ($app) {
            return new ConfigEditor(config_path('app.php'));
        });
    }
}
```

Then use it in your application:

```
app('config-editor')->set('key', 'value')->save();
```

Examples
--------

[](#examples)

### Update Database Configuration

[](#update-database-configuration)

```
$config = new ConfigEditor('config/database.php');

$config
    ->set('connections.mysql.host', 'db.example.com')
    ->set('connections.mysql.username', 'dbuser')
    ->set('connections.mysql.password', 'secret')
    ->set('connections.mysql.database', 'production_db')
    ->save();
```

### Add New Service Provider

[](#add-new-service-provider)

```
$config = new ConfigEditor('config/app.php');

$config->push('providers', 'App\\Providers\\CustomServiceProvider::class');
$config->save();
```

### Merge Environment-Specific Config

[](#merge-environment-specific-config)

```
$config = new ConfigEditor('config/app.php');

if (env('APP_ENV') === 'production') {
    $config->merge('config/app.production.php');
}

$config->save();
```

Testing
-------

[](#testing)

Run the test suite:

```
composer test
```

Changelog
---------

[](#changelog)

See [CHANGELOG.md](CHANGELOG.md) for release notes and version history.

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

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](LICENSE).

Support
-------

[](#support)

For issues and questions, please use the [GitHub Issues](https://github.com/solaris/solaris-config-editor/issues) page.

---

Made with ❤️ by Solaris

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance83

Actively maintained with recent releases

Popularity11

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 80% 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 ~3 days

Total

2

Last Release

88d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ae43366b810137ba1ea996ba18b61692ad3c29475cb517baca050decffa798c4?d=identicon)[dev-sunny-solaris](/maintainers/dev-sunny-solaris)

---

Top Contributors

[![dev-midun](https://avatars.githubusercontent.com/u/42397721?v=4)](https://github.com/dev-midun "dev-midun (4 commits)")[![dev-sunny-solaris](https://avatars.githubusercontent.com/u/243304679?v=4)](https://github.com/dev-sunny-solaris "dev-sunny-solaris (1 commits)")

---

Tags

phplaravelconfigurationconfigparsereditor

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/sunny-solaris-config-editor/health.svg)

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

###  Alternatives

[romanpitak/nginx-config-processor

Nginx configuration files processor.

7235.3k1](/packages/romanpitak-nginx-config-processor)[sbsaga/toon

🧠 TOON for Laravel — a compact, human-readable, and token-efficient data format for AI prompts &amp; LLM contexts. Perfect for ChatGPT, Gemini, Claude, Mistral, and OpenAI integrations (JSON ⇄ TOON).

6115.6k](/packages/sbsaga-toon)[northwoods/config

Simple configuration loader

1516.0k](/packages/northwoods-config)

PHPackages © 2026

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