The border detection of arrays and subarrays in a php configuration file is a real headache to me. Especially when pretty coding is not in the top priorities, which is the case for the most of the time.
I met Yaml in Ruby on Rails config files and I really appreciated when I was first encountered the Yii’s ones (With no offense sir Qiang )
I don’t know if it’s the optimal way to do this but I crafted a solution with Symfony YAML that produces a double interface consisting:
-
A php config array to Yii
-
A yml structure to user
This is possible just by adding a php tag on the top of configuration file
<?php
Yii::import('system.vendors.SymfonyComponents.YAML.*');
list(,$caller) = debug_backtrace(false);
if($caller['file'] !== __FILE__)
return sfYaml::load(__FILE__);
?>
All the necessary files to make it happen are included here 1417
Installation process
1.(optional)Install Symfony YAML as described here
2.Go to the folder \PHP_installation_folder\PEAR (Yes I’m on Windows) and copy the folder SymfonyComponents or take it from the attachment
3.Paste it to Yii_path\framework\vendors
4.Create a new Yii web app and copy yml attachment files to your_new_web_app\protected\config folder
For new files to get involved, these should simply be renamed as php (remove the yml extension) or, mainly for code highlight reasons, change the $config assignment adding the ".yml" extension at the end of the reference path in the following files of your_new_web_app folder
-
index.php line 5
-
index-test.php line 9
-
protected\yiic.php line 5
-
protected\tests\bootstrap.php line 5
Please read the The YAML Format, an excellent single page documentation, for further details about the topic.
I’ll be happy to know your opinion about this (or my English )
Happy coding!!
[CORRECTION]
In file main.php.yml and line 45 please replace db file name testdrive1.db with testdrive.db (remove the ‘1’)