Q:

Share configuration file at CakePHP between Config files (routles.php, mail.php...)

I have a site running in localhost as a development environment and in a server for production.
There are some differences in some configuration files between both and I every time I have to update the changes in the server I have to be careful not to overwrite some files which are different.
I would like to be able to simplify this process by creating just one single file with the correct configuration for each environment. 
I need to read that file currently in this Config files:

app/Config/email.php
app/Config/routes.php

And ideally, if possible in:

app/Vendor/Vendor_name/vendor_file.php

Is it possible somehow?
I have tried to use Configure::read and Configure::write but it seems it can not be done inside email settings such as public $smtp or in the routes file.
Thaks.

A:

The routes file is simply a php file with calls to the router. You could very simply split it up into multiple files and load them yourself:
app/Config/
  routes.php
  routes_dev.php
  routes_production.php

routes.php would then load the proper routes file.
<?php
if ($env == 'dev') {
  include 'routes_dev.php';
} else {
  include 'routes_production.php';
}

The email config is also just a php file. You could write a function to set the proper default config based on the environment.
class EmailConfig {

  public function __construct() {
    if ($env == 'dev') {
      $this->default = $this->dev;
    }
  }

  public $default = array(
      'host' => 'mail.example.com',
      'transport' => 'Smtp'
  );

  public $dev = array(
      'host' => 'mail2.example.com',
      'transport' => 'Smtp'
  );

}

As for vendor files, that's a case by case basis.
If you have a deployment system, it might be better to actually have separate files for each environment (maybe even a full config directory) and rename them after the deployment build is complete, making Cake and your code none the wiser.

