Respect / Config

A powerful, small, deadly simple configurator and dependency injection container DSL made to be easy
http://respect.github.io/Config
Other
98 stars 7 forks source link

Loading Folders #17

Closed alganet closed 12 years ago

alganet commented 12 years ago

Almost every project I develop using Config loads files from a directory. I need to manually call loadFile() onto the same container for every file, in order to keep the file order the same.

We need to investigate a mechanism to support directory loading in the Config core. I've thought on a special, optional "manifest.ini" file which declares the methods called on the Container upon a directory instantiation.

Sample:

<?php
$c = new Container('/my/folder');

/my/folder/manifest.ini:

loadFile[] = config.ini
loadFile[] = db.ini
loadFile[] = application.ini
augustohp commented 12 years ago

Kudos to that, that really annoys me.

But i think every file should have it's own namespace, like:

$c->config->database;
$c->db->pdo;
$c->application->template_dir;
alganet commented 12 years ago

Namespaces are great for reading, like you did. But they imply more than one container per folder, which means that variables cross-containers wouldn't work (unless we change the Container to have children, and I'm not willing to let my baby get pregnant).

The idea is split up a large INI onto several others, but keep its atomicity.

augustohp commented 12 years ago

And what about variables/instances with the same name?

alganet commented 12 years ago

They get overridden. In order to reuse them, we need to collide them. INI files only know two dimensions (sections and key/values), we can't namespace INI calls.

alganet commented 12 years ago

We need to get rid of the manifest.ini if we want to make the Respecteds useful. This means we need a simple, clean way to resolve dependencies between INI files.

We could try to resolve dependencies by entropy, similar to what Rest does with route ordering. The INI with more [sections] will probably be the most dependent of another INIs, so this guy will be loaded last.

A more sophisticated way to solve this is compare the entropies of each pair of INI files on the folder, then rank them all by their scores. Problem is: for 20 INIs we will run 400 entropy checks.

I'm willing to code the simple entropy dependency solver. It will probably fit our needs for the current components and Respecteds.

Any ideas?

augustohp commented 12 years ago

The solver would have to be very simple so we can live with its limitation peacefully.

The only annoying limitation I can think of is adding more sections so one INI could be loaded after another... this would be ugly and unpleasant, but with a very simple code as justification it would do just fine.

So +1 to the solver!

PS: Happy panda!

alganet commented 12 years ago

I've implemented the simple solver and a slightly better solver based on variable names with great performance (even though performance is not in our current concerns).

The solver is still not consistent for every case. It can always return consistent results for two INI files, but three INI files is just too much for it.

Next in this beautiful line of iterations trough this unpleasant algorithm is to implement a score-based entropy solver that assigns scores to each combination of INIs and them sort them all by that score.

Red Bull should sponsor us.

augustohp commented 12 years ago

It really should!

alganet commented 12 years ago

Loading folders is done. We should open another issue for the dependency solver.