Can YAML have inheritance?
Posted
by Jason
on Stack Overflow
See other posts from Stack Overflow
or by Jason
Published on 2010-06-17T00:10:39Z
Indexed on
2010/06/17
1:52 UTC
Read the original article
Hit count: 523
This question involves a lot of symfony but it should be easy enough for someone to follow who only knows YAML and not symfony.
My symfony models come from a three-step process: First, I create the tables in MySQL. Second, I run a symfony command (symfony doctrine:build-schema) to convert my table structure into a YAML file. Third, I run another symfony command (symfony doctrine:build-model) to convert the YAML file into PHP code.
Here's the problem: there are some tables in the database that I don't want to end up in my symfony code. For example, let's say I have two tables: one called my_table
and another called wordpress
. The YAML file I end up with might look like this:
MyTable:
connection: doctrine
tableName: my_table
Wordpress:
connection: doctrine
tableName: wordpress
That's great except the wordpress
table has nothing to do with my symfony models. The result is that every single time I make a change to my database and generate this YAML file, I have to manually remove wordpress
. It's annoying!
I'd like to be able to create a file called baseConfig.php or something that looks like this:
$config = array(
'MyTable' => array(
'connection' => 'doctrine',
'tableName' => 'my_table',
),
'Wordpress' => array(
'connection' => 'doctrine',
'tableName' => 'wordpress',
),
);
And then I could have a separate file called config.php or something where I could make modifications to the base config:
unset($config['Wordpress']);
So my question is: is there any way to convert YAML into executable PHP code (as opposed to load YAML INTO PHP code like what sfYaml::load() does) to achieve this sort of thing? Or is there maybe some other way to achieve YAML inheritance? Thanks, Jason
© Stack Overflow or respective owner