Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

refactor configuration so that it can be easily overridden

  • Loading branch information...
commit f2098689e69b97340ed8af7bbd0a0c08be6332f1 1 parent 5259b93
nick@sullivanflock.com authored
View
1  .gitignore
@@ -9,3 +9,4 @@ dev_mysql.log
test_mysql.log
development.log
*/cache/*
+LocalSettings.php
View
35 includes/CommonSettings.php
@@ -1,4 +1,7 @@
<?php
+/********
+ * Do not edit this file for making config changes. Change LocalConfig instead
+ ********/
// *** Auto load set up
function __autoload($class_name){
@@ -10,20 +13,32 @@ function __autoload($class_name){
}
}
-// *** Error handling. Be strict and loud in dev environments, and prudent in production
-$DEV_HOSTS = array("beer", "testubuntu.liftium.com");
-if (Framework::isDev()){
- error_reporting(E_STRICT | E_ALL);
- ini_set('display_errors', true);
-} else {
- error_reporting(E_ALL ^ E_NOTICE);
- ini_set('display_errors', false);
-}
+// *** Error handling. Note you can change this in your LocalSettings.php
+error_reporting(E_ALL ^ E_NOTICE);
+ini_set('display_errors', false);
ini_set('log_errors', true);
-// Misc global settings
+// These hosts are defined as development hosts, for Framework::isDev()
+$DEV_HOSTS = array("localhost");
+
+// Time zone stuff
define('MYSQL_DATE_FORMAT', 'Y-m-d H:i:s');
date_default_timezone_set('America/New_York'); // This suppresses E_STRICT notices when strtotime is called
+
+// Global include settings
$IP = dirname(__FILE__) . '/';
+// Default database and memcached settings. Note, do not change here. Override in LocalSettings.php
+// See LocalSettings-sample.php as an example
+$CONFIG = array(
+ 'db' => array(),
+ 'memcached' => array(),
+);
+// Pull in the local config for any overrides
+if ( file_exists(dirname(__FILE__) . '/LocalSettings.php')){
+ include dirname(__FILE__) . '/LocalSettings.php';
+} else {
+ echo "You need a LocalSettings.php file to set up configs. See LocalSettings-sample.php as an example";
+ exit;
+}
View
29 includes/Framework.php
@@ -4,37 +4,23 @@
// F U Symfony
class Framework {
- // I'd like to see a SERVICECLASS variable here instead of hard coded hostnames. Later.
-
static public function getDB ($connType = "master"){
- global $DEV_HOSTS;
- if (in_array(self::getHostname(), $DEV_HOSTS)){
- $masterhost = 'localhost';
- $slavehosts = array('localhost');
- $username = 'liftiumdev';
- $password = 'monkey';
- $dbname = "liftium_dev_delivery";
- } else {
- $masterhost = 'masterdb';
- $slavehosts = array('masterdb', 'slavedb1');
- $username = 'liftiumprod';
- $password = 'gorilla';
- $dbname = "liftium";
- }
+ // shortcut
+ $c = $GLOBALS['CONFIG']['db'];
// Randomly choose between slave hosts
- shuffle($slavehosts);
- $slavehost = $slavehosts[0];
+ shuffle($c['slavehosts']);
+ $slavehost = $c['slavehosts'][0];
switch ($connType){
- case 'master': $dsn = "mysql:dbname=$dbname;host=$masterhost"; break;
- case 'slave': $dsn = "mysql:dbname=$dbname;host=$slavehost"; break;
+ case 'master': $dsn = "mysql:dbname={$c['dbname']};host={$c['masterhost']}"; break;
+ case 'slave': $dsn = "mysql:dbname={$c['dbname']};host=$slavehost}"; break;
default: return false;
}
static $cons;
if (empty($cons[$connType])){
- $cons[$connType] = new PDO($dsn, $username, $password);
+ $cons[$connType] = new PDO($dsn, $c['username'], $c['password']);
$cons[$connType]->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL);
$cons[$connType]->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
}
@@ -213,7 +199,6 @@ static public function isDev() {
}
/* See http://www.freesoft.org/CIE/RFC/2068/185.htm for an explanation */
-
static public function httpCache($mtime=null){
// Make it easy to disable
if (isset($_GET['noCache'])){
View
10 includes/LiftiumCache.php
@@ -10,14 +10,8 @@ static function getInstance(){
$Cache = new LiftiumCache();
- global $DEV_HOSTS;
- if (in_array(Framework::getHostname(), $DEV_HOSTS)){
- $Cache->pconnect('localhost', 11211) || error_log('Error connecting to memcached');
- } else {
- $Cache->pconnect('memcached1', 11211) || error_log('Error connecting to memcached');
- ### disabled memcached2 for now, because the ruby & php libraries are using different
- ### hashing strategies. See FB 118 for details. -Jos
- #$Cache->pconnect('memcached2', 11211) || error_log('Error connecting to memcached');
+ foreach($GLOBALS['CONFIG']['memcached'] as $c){
+ $Cache->pconnect($c['host'], $c['port']) || trigger_error("Error connecting to memcached:" . print_r($c, true), E_USER_WARNING);
}
return $Cache;
View
45 includes/LocalSettings-sample.php
@@ -0,0 +1,45 @@
+<?php
+$CONFIG['db'] = array(
+ 'masterhost' => 'masterdb',
+ 'slavehosts' => array('masterdb', 'slavedb1'),
+ 'username' => 'your_username',
+ 'password' => 'your_password',
+ 'dbname' => "liftium"
+);
+
+$CONFIG['memcached'] = array(
+ // Array of memcached hosts
+ '0' => array(
+ 'host' => 'memcached1',
+ 'port' => '11211',
+ ),
+ '1' => array(
+ 'host' => 'memcached2',
+ 'port' => '11211',
+ )
+);
+
+// Different settings if on a dev box
+$DEV_HOSTS = array("localhost", "your.dev.server");
+if (Framework::isDev()){
+ // Turn up error reporting on dev
+ error_reporting(E_STRICT | E_ALL);
+ ini_set('display_errors', true);
+
+ $CONFIG['db'] = array(
+ 'masterhost' => 'localhost',
+ 'slavehosts' => array('localhost'),
+ 'username' => 'your_username',
+ 'password' => 'your_password',
+ 'dbname' => 'liftium_dev'
+ );
+
+ $CONFIG['memcached'] = array(
+ // Array of memcached hosts
+ '0' => array(
+ 'host' => 'localhost',
+ 'port' => '11211',
+ )
+ );
+}
+
Please sign in to comment.
Something went wrong with that request. Please try again.