PHP Simple two way config package, and a backstory
Tags: php, opensource, showdev, discuss
Published: 2018-11-13 18:18:24

---
title: PHP Simple two way config package, and a backstory
published: true
description: Simple 2 way (read/write) php-based configuration package, and a back story for what i passed through since i started my project.
cover_image: https://thepracticaldev.s3.amazonaws.com/i/6f4nhsb5qopppt7dfo9l.jpg
tags: #php #opensource #showdev #discuss
---

Hi, folks

I'm happy to introduce my first open source project. Which is a two way PHP-based configuration package. This package is designed to make it easy synchronizing the source file with the run-time values. It's suitable for applications that require the use of file-based system to store preferences or configuration.

{% github mazentouati/simple-2way-config %}

### example of usage

```php
use MazenTouati\Simple2wayConfig\S2WConfigFactory;

$config = S2WConfigFactory::create( __DIR__ . '/demo' );

// Get a value from the config
$old_host = $config->get('database.drivers.mysql.host');

// Change the value at the run-time
$config->set('database.drivers.mysql.host', '127.0.0.1');

// Sync the changes with the source file
$config->sync('database');

```

If you like the project kindly share love and leave a start, it will help me a lot. Suggestions and contributions are welcomed too. 

##Back story
Somewhere in my full-stack development journey, I decided to be involved in the open source industry and practice my knowledge more and more, especially for the front-end part as it's evolving so fast with a lot of over-engineered libraries and frameworks. So I started planning then creating a project I thought about for a while. Which is a database toolkit dedicated to small and medium project. Well, it's totally worth it as I learnt a lot of new things. From comparing and testing: Vue, Angular and React, later I abandoned them, to creating my own solutions or small packages like: templating, data binding, etc. I don't think that I'm re-inventing the wheel in this case because as I mentioned before there's a plenty of over-engineered solutions that aim to solve all problems and cover all use cases. I'm a simple, pragmatic man, I want only to use what's enough for me and my product. Bombarding it with a lot of unused code or generic solution is against my most prioritized goal (for the toolkit) which is "Performance".

With that said, it brings us to this post subject, I came across a point where I needed to make configuring the database credentials read and write. I don't have another choices, I searched for a simple package that offers the ability to make the configuration two ways but noway. 
Here is my use case: I'm building a SQL console that execute commands one by one, when the Developer type `use _database_` it should take the database name and update it in the config file then return a success message to the console interface (using AJAX of course). So when he continues throwing SQL commands to the console the Back-end code uses the new database name. Which will become persistent for future use. In a case like this I didn't have the luxury to use a database for dynamic configuration. To solve my issue, I forked an existing package and added the write functionality just to be able to continue working on the console. I used composer VCS repositories to load the fork. Later, after I finished the console I created this package and implemented it in my toolkit because I wasn't comfortable enough with that fork.

The console (part of the toolkit) is ready for a pre-release I'll publish it as soon as I finish creating it's homepage.I'll post more details about my journey creating this toolkit when I release it.

These are the things I have learned till now as far as I can recall (some I heard about but never used them, some I knew them but I practiced them more)

- Javascript: React, Vue, Reveal Pattern, Sub-pub, Data binding, ES2016, Gulp, More VanillaJS, HTML Tag's templating ( usings custom attribute ) ...
- CSS: SMACSS, More flexbox
- PHP: Unit Testing, Continuous Integration, Slim Micro Framework, Code-sniffer, More composer
- Other: Git, Vim, Lossless coupled components, Modular Programming in general, more command line...

Again, I'm very happy and satisfied for what I passed through till now. Go ahead and start creating your open source projects.

> practice makes perfect

I'd like to hear your thoughts, peace !