code formatting, changed $mode_additions to $callbacks

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@44567 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2007-11-10 05:17:30 +00:00
parent 80f6224d38
commit 97a44ce0be

View File

@ -8,10 +8,33 @@
* steps. * steps.
*/ */
class Director { class Director {
static private $urlSegment; static private $urlSegment;
static private $urlParams; static private $urlParams;
static private $rules = array(); static private $rules = array();
static $siteMode;
static $alternateBaseFolder;
static $alternateBaseURL;
static $dev_servers = array(
'localhost',
'127.0.0.1'
);
static $test_servers = array();
static protected $environment_type;
/**
* Sets the site mode (if it is the public site or the cms),
* and runs registered modules.
*/
static protected $callbacks;
function __construct() { function __construct() {
if(isset($_GET['debug_profile'])) Profiler::mark("Director", "construct"); if(isset($_GET['debug_profile'])) Profiler::mark("Director", "construct");
@ -163,6 +186,7 @@ class Director {
static function urlParam($name) { static function urlParam($name) {
return Director::$urlParams[$name]; return Director::$urlParams[$name];
} }
static function urlParams() { static function urlParams() {
return Director::$urlParams; return Director::$urlParams;
} }
@ -259,7 +283,6 @@ class Director {
/** /**
* Returns a URL for the given controller * Returns a URL for the given controller
*/ */
static $alternateBaseURL;
static function baseURL() { static function baseURL() {
if(self::$alternateBaseURL) return self::$alternateBaseURL; if(self::$alternateBaseURL) return self::$alternateBaseURL;
else { else {
@ -268,11 +291,11 @@ class Director {
else return $base . '/'; else return $base . '/';
} }
} }
static function setBaseURL($baseURL) { static function setBaseURL($baseURL) {
self::$alternateBaseURL = $baseURL; self::$alternateBaseURL = $baseURL;
} }
static $alternateBaseFolder;
static function baseFolder() { static function baseFolder() {
if(self::$alternateBaseFolder) return self::$alternateBaseFolder; if(self::$alternateBaseFolder) return self::$alternateBaseFolder;
else return dirname(dirname($_SERVER['SCRIPT_FILENAME'])); else return dirname(dirname($_SERVER['SCRIPT_FILENAME']));
@ -296,10 +319,12 @@ class Director {
static function getAbsURL($url) { static function getAbsURL($url) {
return Director::baseURL() . '/' . $url; return Director::baseURL() . '/' . $url;
} }
static function getAbsFile($file) { static function getAbsFile($file) {
if($file[0] == '/') return $file; if($file[0] == '/') return $file;
return Director::baseFolder() . '/' . $file; return Director::baseFolder() . '/' . $file;
} }
static function fileExists($file) { static function fileExists($file) {
return file_exists(Director::getAbsFile($file)); return file_exists(Director::getAbsFile($file));
} }
@ -310,6 +335,7 @@ class Director {
static function absoluteBaseURL() { static function absoluteBaseURL() {
return Director::absoluteURL(Director::baseURL()); return Director::absoluteURL(Director::baseURL());
} }
static function absoluteBaseURLWithAuth() { static function absoluteBaseURLWithAuth() {
if($_SERVER['PHP_AUTH_USER']) if($_SERVER['PHP_AUTH_USER'])
$login = "$_SERVER[PHP_AUTH_USER]:$_SERVER[PHP_AUTH_PW]@"; $login = "$_SERVER[PHP_AUTH_USER]:$_SERVER[PHP_AUTH_PW]@";
@ -363,16 +389,6 @@ class Director {
} }
} }
static $siteMode;
/**
* Sets the site mode (if it is the public site or the cms),
* and runs registered modules.
*/
static protected $mode_additions;
/** /**
* Sets the site mode (if it is the public site or the cms), * Sets the site mode (if it is the public site or the cms),
* and runs registered modules. * and runs registered modules.
@ -380,12 +396,13 @@ class Director {
static function set_site_mode($mode) { static function set_site_mode($mode) {
Director::$siteMode = $mode; Director::$siteMode = $mode;
if(isset(self::$mode_additions[$mode])) { if(isset(self::$callbacks[$mode])) {
foreach(self::$mode_additions[$mode] as $extension) { foreach(self::$callbacks[$mode] as $extension) {
call_user_func($extension); call_user_func($extension);
} }
} }
} }
static function get_site_mode() { static function get_site_mode() {
return Director::$siteMode; return Director::$siteMode;
} }
@ -395,29 +412,23 @@ class Director {
* the controller is instantiated. The optional 'mode' parameter * the controller is instantiated. The optional 'mode' parameter
* can be either 'site' or 'cms', as those are the two values currently * can be either 'site' or 'cms', as those are the two values currently
* set by controllers. The callback function will be run at the * set by controllers. The callback function will be run at the
* initialization of the relavant controller. * initialization of the relevant controller.
*
* @param $function string PHP-function array based on http://php.net/call_user_func
* @param $mode string
*/ */
static function extendSite($function, $mode='site') { static function add_callback($function, $mode = 'site') {
self::$mode_additions[$mode][] = $function; self::$callbacks[$mode][] = $function;
} }
static $dev_servers = array(
'localhost',
'127.0.0.1'
);
static function set_dev_servers($servers) { static function set_dev_servers($servers) {
Director::$dev_servers = $servers; Director::$dev_servers = $servers;
} }
static $test_servers = array();
static function set_test_servers($servers) { static function set_test_servers($servers) {
Director::$test_servers = $servers; Director::$test_servers = $servers;
} }
static protected $environment_type;
/** /**
* Force the environment type to be dev, test or live. * Force the environment type to be dev, test or live.
* This will affect the results of isLive, isDev, and isTest * This will affect the results of isLive, isDev, and isTest
@ -433,6 +444,7 @@ class Director {
static function isLive() { static function isLive() {
return !(Director::isDev() || Director::isTest()); return !(Director::isDev() || Director::isTest());
} }
static function isDev() { static function isDev() {
if(self::$environment_type) return self::$environment_type == 'dev'; if(self::$environment_type) return self::$environment_type == 'dev';
@ -453,8 +465,6 @@ class Director {
return true; return true;
} }
// Check if we are running on one of the test servers // Check if we are running on one of the test servers
if(in_array($_SERVER['HTTP_HOST'], Director::$test_servers)) { if(in_array($_SERVER['HTTP_HOST'], Director::$test_servers)) {
return true; return true;
@ -485,4 +495,4 @@ class Director {
} }
?> ?>