Dynamically populate config.ini.php for AppFog

Howdy all,
I’m trying to get Piwik up and running on AppFog. They don’t give you a real connection string for your MySQL DB instances; instead, they populate an environment variable and then you use a PHP array to fill the proper values in.

For instance, their WordPress example does this:


$services = getenv("VCAP_SERVICES");
$services_json = json_decode($services,true);
$mysql_config = $services_json["mysql-5.1"][0]["credentials"];

// ** MySQL settings from resource descriptor ** //
if (getenv("VCAP_SERVICES")) {
        define('DB_NAME', $mysql_config["name"]);
        define('DB_USER', $mysql_config["user"]);
        define('DB_PASSWORD', $mysql_config["password"]);
        define('DB_HOST', $mysql_config["hostname"]);
        define('DB_PORT', $mysql_config["port"]);
} else {
        define('DB_NAME', $mysql_config["name"]);
        define('DB_USER', $mysql_config["user"]);
        define('DB_PASSWORD', $mysql_config["password"]);
        define('DB_HOST', $mysql_config["hostname"]);
        define('DB_PORT', $mysql_config["port"]);
        define('WP_SITEURL', 'http://localhost/');
};

Now, since config.ini.php for Piwik expressly dumps out of PHP execution, I’m not entirely certain how to replicate this functionality.

A little help, anyone?