Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jaxwilko/simple-config
A simple fluent interface for creating php config files
https://github.com/jaxwilko/simple-config
configuration-management php php7
Last synced: 3 months ago
JSON representation
A simple fluent interface for creating php config files
- Host: GitHub
- URL: https://github.com/jaxwilko/simple-config
- Owner: jaxwilko
- License: mit
- Created: 2019-10-25T22:03:09.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2019-11-15T23:23:27.000Z (about 5 years ago)
- Last Synced: 2024-04-18T14:22:41.878Z (8 months ago)
- Topics: configuration-management, php, php7
- Language: PHP
- Homepage:
- Size: 10.7 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
> Archived: use [winter/laravel-config-writer](https://github.com/wintercms/laravel-config-writer) instead.
# SimpleConfig
This package aims to provide a simple interface for creating php config files.
### Installation
Add the package to your project via:
```
composer require jaxwilko/simple-config
```### Usage
```php
title = 'Database';
$section->key = 'database';
$section->comment = 'This is where your database config goes.';
$section->value = ['mysql' => ['host' => 'localhost']];
$compiler->addSection($section);
echo $compiler->render();
```Would return:
```php
[
'mysql' => [
'host' => 'localhost',
],
],
];
```A simpler way of achieving the same thing would be:
```php
addSection(new Section([
'title' => 'Database',
'key' => 'database',
'comment' => 'This is where your database config goes.',
'value' => ['mysql' => ['host' => 'localhost']],
]));
echo $compiler->render();
```Everything can be omitted, for example just having a comment and title:
```php
$compiler = new Compiler();
$compiler->addSection(new Section([
'title' => 'Database',
'comment' => 'This is where your database config goes.',
]));
echo $compiler->render();
```Will return:
```php
addSection(new Section([
'key' => 'database',
'value' => ['mysql' => ['host' => 'localhost']],
]));
echo $compiler->render();
```Will return:
```php
[
'mysql' => [
'host' => 'localhost',
],
],
];
```Multiple sections can be added via chaining:
```php
addSection(new Section([
'title' => 'Section one',
'key' => 'section_one',
'comment' => 'This is a section',
'value' => [
'foo' => 'bar',
'bar' => [
'foo'
]
]
]))
->addSection(new Section([
'title' => 'Section two',
'key' => 'section_two',
'comment' => 'This is another section',
'value' => [
'bar' => 'foo',
'foo' => [
'bar'
]
]
]));
```Functions can be passed in by prefixing the method with `@@`. E.g.
```php
addSection(new Section([
'title' => 'Section',
'key' => 'section',
'comment' => 'This is a section',
'value' => [
'foo' => '@@env(\'VALUE\')',
]
]));
```Will result in:
```php
[
'foo' => env('VALUE'),
],
];
```Compiler options can be set via:
```php
option('length', 80);
// use spaces over tabs
$compiler->option('tabs', false);
// define the indentation length
$compiler->option('indent', 4);
```