Created
May 3, 2010 13:28
-
-
Save havvg/388086 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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