Skip to content

Instantly share code, notes, and snippets.

@havvg
Created May 3, 2010 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save havvg/388086 to your computer and use it in GitHub Desktop.
Save havvg/388086 to your computer and use it in GitHub Desktop.
<?php
/**
* Cake database configuration for git repositories.
*
* It automatically detects the current working branch and uses the appropriate database connection.
* Fallback is given by the "default" entry.
*/
class DATABASE_CONFIG {
/**
* Fallback database connection for any branch that has no explicit config.
* e.g. "master" branch
*/
public $default = array();
/**
* Database connection for "stable" branch.
*/
public $stable = array();
/**
* Test database connection for "stable" branch.
*/
public $stable_test = array();
/**
* Database connection for branch: "another_branch".
*/
public $another_branch = array();
/**
* Test database connection for "another_branch" branch.
*/
public $another_branch_test = array();
/**
* Database connection for test suite. (from cake conventions)
*/
public $test_suite = array();
public function __construct() {
$git_branch_info = exec('git branch | grep "*"');
$matches = array();
preg_match('/\* (.+)$/', $git_branch_info, $matches);
$branch = $matches[1];
if (isset($this->{$branch})) {
$this->default = array_merge($this->default, $this->{$branch});
$branch_test = $branch . '_test';
$this->test_suite = array_merge($this->test_suite, $this->{$branch_test});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment