Created
July 28, 2010 20:01
-
-
Save aenigme/496050 to your computer and use it in GitHub Desktop.
Kohana System Configuration Hook
This file contains 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 defined('SYSPATH') or die('No direct script access.'); | |
class System_Config | |
{ | |
// First host should be the production server. | |
public static $configs = array( | |
'example.com' => array( | |
'database.default.connection' => array( | |
'type' => 'mysql', | |
'user' => 'username', | |
'pass' => 'password', | |
'host' => 'localhost', | |
'port' => FALSE, | |
'socket' => FALSE, | |
'database' => 'example_db' | |
), | |
'config.display_errors' => FALSE, | |
'common.auth_net_login_id' => '', | |
'common.auth_net_tran_key' => '', | |
'common.google_map_key' => '', | |
'common.autofill' => FALSE, | |
'common.typekit' => TRUE, | |
'session.expiration' => 0, | |
), | |
'example.dev' => array( | |
'database.default.connection' => array( | |
'type' => 'mysql', | |
'user' => 'username', | |
'pass' => 'password', | |
'host' => 'localhost', | |
'port' => FALSE, | |
'socket' => FALSE, | |
'database' => 'example_db' | |
), | |
'config.display_errors' => TRUE, | |
'common.auth_net_login_id' => '', | |
'common.auth_net_tran_key' => '', | |
'common.google_map_key' => '', | |
'common.typekit' => FALSE, | |
'common.autofill' => TRUE, | |
'session.expiration' => 0, | |
), | |
); | |
public static function init() | |
{ | |
$configs = self::$configs; | |
$production_server = current(array_keys($configs)); | |
$server_name = isset($_SERVER['SERVER_NAME']) ? preg_replace('#^www\.#i', '', $_SERVER['SERVER_NAME']) : $production_server; | |
Kohana::config_set('config.in_production', $server_name == $production_server); | |
// Enable errors if on cmd line | |
if (PHP_SAPI == 'cli') | |
{ | |
ini_set('display_errors', 1); | |
} | |
// Set configuration vars if there is a config set for this hostname | |
if (isset($configs[$server_name])) | |
{ | |
// If a site domain isn't configured, defaults to server name. | |
if (!isset($configs[$server_name]['config.site_domain'])) | |
{ | |
$configs[$server_name]['config.site_domain'] = $server_name . '/'; | |
} | |
foreach ($configs[$server_name] as $k => $v) | |
{ | |
Kohana::config_set($k, $v); | |
$config_key = explode('.', $k); | |
$config_namespace = array_shift($config_key); | |
$config_key = implode('', $config_key); | |
// If namespace is config, reapply it to core as well. | |
if ($config_namespace == 'config') | |
{ | |
if ($k == 'config.display_errors') | |
{ | |
ini_set('display_errors', $v); | |
Kohana::config_set("core.$config_key", $v); | |
} | |
} | |
} | |
} | |
else | |
{ | |
die('could not find any config for this host.'); | |
} | |
} | |
} | |
Event::add('system.ready', array('System_Config', 'init')); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment