Changeset 468 for trunk/lib/App.inc.php
- Timestamp:
- Feb 20, 2014 3:03:59 AM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property
svn:mergeinfo
set to
/branches/eli_branch merged eligible
-
Property
svn:mergeinfo
set to
-
trunk/lib/App.inc.php
r453 r468 42 42 class App { 43 43 44 // A place to keep an object instance for the singleton pattern. 45 private static $instance = null; 46 44 47 // Namespace of this application instance. 45 var$_ns;48 private $_ns; 46 49 47 50 // If $app->start has run successfully. 48 var$running = false;51 public $running = false; 49 52 50 53 // Instance of database object. 51 var$db;54 public $db; 52 55 53 56 // Array of query arguments will be carried persistently between requests. 54 var$_carry_queries = array();57 private $_carry_queries = array(); 55 58 56 59 // Dictionary of global application parameters. 57 var$_params = array();60 private $_params = array(); 58 61 59 62 // Default parameters. 60 var$_param_defaults = array(63 private $_param_defaults = array( 61 64 62 65 // Public name and email address for this application. … … 162 165 163 166 /** 167 * Constructor. 168 */ 169 public function __construct($namespace='') 170 { 171 // Set namespace of application instance. 172 $this->_ns = $namespace; 173 174 // Initialize default parameters. 175 $this->_params = array_merge($this->_params, $this->_param_defaults); 176 177 // Begin timing script. 178 require_once dirname(__FILE__) . '/ScriptTimer.inc.php'; 179 $this->timer = new ScriptTimer(); 180 $this->timer->start('_app'); 181 } 182 183 /** 164 184 * This method enforces the singleton pattern for this class. Only one application is running at a time. 165 185 * … … 169 189 * @static 170 190 */ 171 static function &getInstance($namespace='') 172 { 173 static $instance = null; 174 175 if ($instance === null) { 176 $instance = new App($namespace); 177 } 178 179 return $instance; 180 } 181 182 /** 183 * Constructor. 184 */ 185 function App($namespace='') 186 { 187 // Set namespace of application instance. 188 $this->_ns = $namespace; 189 190 // Initialize default parameters. 191 $this->_params = array_merge($this->_params, $this->_param_defaults); 192 193 // Begin timing script. 194 require_once dirname(__FILE__) . '/ScriptTimer.inc.php'; 195 $this->timer = new ScriptTimer(); 196 $this->timer->start('_app'); 191 public static function &getInstance($namespace='') 192 { 193 if (self::$instance === null) { 194 // TODO: Yep, having a namespace with one singletone instance is not very useful. 195 self::$instance = new self($namespace); 196 } 197 198 return self::$instance; 197 199 } 198 200 … … 203 205 * @param array $param Array of parameters (key => val pairs). 204 206 */ 205 function setParam($param=null)207 public function setParam($param=null) 206 208 { 207 209 if (isset($param) && is_array($param)) { … … 218 220 * @return mixed Parameter value, or null if not existing. 219 221 */ 220 function getParam($param=null)222 public function getParam($param=null) 221 223 { 222 224 if ($param === null) { … … 225 227 return $this->_params[$param]; 226 228 } else { 227 trigger_error(sprintf('Parameter is not set: %s', $param), E_USER_NOTICE);228 229 return null; 229 230 } … … 237 238 * @since 15 Jul 2005 00:32:21 238 239 */ 239 function start()240 public function start() 240 241 { 241 242 if ($this->running) { … … 275 276 276 277 // DB connection parameters taken from environment variables in the httpd.conf file, readable only by root. 277 if (!empty($_SERVER['DB_SERVER']) ) {278 if (!empty($_SERVER['DB_SERVER']) && !$this->getParam('db_server')) { 278 279 $this->setParam(array('db_server' => $_SERVER['DB_SERVER'])); 279 280 } 280 if (!empty($_SERVER['DB_NAME']) ) {281 if (!empty($_SERVER['DB_NAME']) && !$this->getParam('db_name')) { 281 282 $this->setParam(array('db_name' => $_SERVER['DB_NAME'])); 282 283 } 283 if (!empty($_SERVER['DB_USER']) ) {284 if (!empty($_SERVER['DB_USER']) && !$this->getParam('db_user')) { 284 285 $this->setParam(array('db_user' => $_SERVER['DB_USER'])); 285 286 } 286 if (!empty($_SERVER['DB_PASS']) ) {287 if (!empty($_SERVER['DB_PASS']) && !$this->getParam('db_pass')) { 287 288 $this->setParam(array('db_pass' => $_SERVER['DB_PASS'])); 288 289 } … … 394 395 * @since 17 Jul 2005 17:20:18 395 396 */ 396 function stop()397 public function stop() 397 398 { 398 399 session_write_close(); 399 restore_include_path();400 400 $this->running = false; 401 401 $num_queries = 0; … … 423 423 * @param string $line __LINE__. 424 424 */ 425 function raiseMsg($message, $type=MSG_NOTICE, $file=null, $line=null)425 public function raiseMsg($message, $type=MSG_NOTICE, $file=null, $line=null) 426 426 { 427 427 $message = trim($message); … … 465 465 * @since 21 Dec 2005 13:09:20 466 466 */ 467 function getRaisedMessages()467 public function getRaisedMessages() 468 468 { 469 469 if (!$this->running) { … … 471 471 return false; 472 472 } 473 474 473 return isset($_SESSION['_app'][$this->_ns]['messages']) ? $_SESSION['_app'][$this->_ns]['messages'] : array(); 475 474 } … … 482 481 * @since 21 Dec 2005 13:21:54 483 482 */ 484 function clearRaisedMessages()483 public function clearRaisedMessages() 485 484 { 486 485 if (!$this->running) { … … 503 502 * @since 15 Jul 2005 01:39:14 504 503 */ 505 function printRaisedMessages($above='', $below='', $print_gotohash_js=false, $hash='sc-msg') 506 { 504 public function printRaisedMessages($above='', $below='', $print_gotohash_js=false, $hash='sc-msg') 505 { 506 507 507 if (!$this->running) { 508 508 $this->logMsg(sprintf('Canceled method call %s, application not running.', __FUNCTION__), LOG_NOTICE, __FILE__, __LINE__); … … 576 576 * @param string $line The line of the file where the log event occurs. 577 577 */ 578 function logMsg($message, $priority=LOG_INFO, $file=null, $line=null)578 public function logMsg($message, $priority=LOG_INFO, $file=null, $line=null) 579 579 { 580 580 static $previous_events = array(); … … 690 690 // SCREEN ACTION 691 691 if (false !== $this->getParam('log_screen_priority') && $priority <= $this->getParam('log_screen_priority')) { 692 echo "[{$event['type']}] [{$event['message']}]\n";692 file_put_contents('php://stderr', "[{$event['type']}] [{$event['message']}]\n", FILE_APPEND); 693 693 } 694 694 … … 706 706 * @return The string representation of $priority. 707 707 */ 708 function logPriorityToString($priority) {708 public function logPriorityToString($priority) { 709 709 $priorities = array( 710 710 LOG_EMERG => 'emergency', … … 735 735 * @since 13 Oct 2007 11:34:51 736 736 */ 737 function setQuery($query_key, $val)737 public function setQuery($query_key, $val) 738 738 { 739 739 if (!is_array($query_key)) { … … 757 757 * @since 14 Nov 2005 19:24:52 758 758 */ 759 function carryQuery($query_key, $default=false)759 public function carryQuery($query_key, $default=false) 760 760 { 761 761 if (!is_array($query_key)) { … … 782 782 * @since 18 Jun 2007 20:57:29 783 783 */ 784 function dropQuery($query_key, $unset=false)784 public function dropQuery($query_key, $unset=false) 785 785 { 786 786 if (!is_array($query_key)) { … … 818 818 * @return string url with attached queries and, if not using cookies, the session id 819 819 */ 820 function url($url, $carry_args=null, $always_include_sid=false)820 public function url($url, $carry_args=null, $always_include_sid=false) 821 821 { 822 822 if (!$this->running) { … … 909 909 * @since 09 Dec 2005 17:58:45 910 910 */ 911 function oHREF($url, $carry_args=null, $always_include_sid=false)911 public function oHREF($url, $carry_args=null, $always_include_sid=false) 912 912 { 913 913 $url = $this->url($url, $carry_args, $always_include_sid); … … 929 929 * false <-- To not carry any queries. If URL already has queries those will be retained. 930 930 */ 931 function printHiddenSession($carry_args=null)931 public function printHiddenSession($carry_args=null) 932 932 { 933 933 if (!$this->running) { … … 995 995 * @param bool $always_include_sid Force session id to be added to Location header. 996 996 */ 997 function dieURL($url, $carry_args=null, $always_include_sid=false)997 public function dieURL($url, $carry_args=null, $always_include_sid=false) 998 998 { 999 999 if (!$this->running) { … … 1042 1042 * @since 31 Mar 2006 19:17:00 1043 1043 */ 1044 function dieBoomerangURL($id=null, $carry_args=null, $default_url=null, $queryless_referrer_comparison=false)1044 public function dieBoomerangURL($id=null, $carry_args=null, $default_url=null, $queryless_referrer_comparison=false) 1045 1045 { 1046 1046 if (!$this->running) { … … 1085 1085 * FIXME: url garbage collection? 1086 1086 */ 1087 function setBoomerangURL($url=null, $id=null)1087 public function setBoomerangURL($url=null, $id=null) 1088 1088 { 1089 1089 if (!$this->running) { … … 1093 1093 // A redirection will never happen immediately after setting the boomerangURL. 1094 1094 // Set the time so ensure this doesn't happen. See $app->validBoomerangURL for more. 1095 /// FIXME: Why isn't the time set here under setBoomerangURL() and only under dieBoomerangURL()?1096 1095 1097 1096 if ('' != $url && is_string($url)) { … … 1124 1123 * @param string $id An identification tag for this url. 1125 1124 */ 1126 function getBoomerangURL($id=null)1125 public function getBoomerangURL($id=null) 1127 1126 { 1128 1127 if (!$this->running) { … … 1149 1148 * @param string $id An identification tag for this url. 1150 1149 */ 1151 function deleteBoomerangURL($id=null)1150 public function deleteBoomerangURL($id=null) 1152 1151 { 1153 1152 if (!$this->running) { … … 1171 1170 * @return bool True if it is set and valid, false otherwise. 1172 1171 */ 1173 function validBoomerangURL($id=null, $use_nonspecificboomerang=false)1172 public function validBoomerangURL($id=null, $use_nonspecificboomerang=false) 1174 1173 { 1175 1174 if (!$this->running) { … … 1221 1220 * the same page but with https. 1222 1221 */ 1223 function sslOn()1222 public function sslOn() 1224 1223 { 1225 1224 if (function_exists('apache_get_modules')) { … … 1242 1241 * a http version of the current url. 1243 1242 */ 1244 function sslOff()1243 public function sslOff() 1245 1244 { 1246 1245 if ('' != getenv('HTTPS')) { … … 1248 1247 } 1249 1248 } 1250 1251 1252 1249 } // End. 1253 1254 ?>
Note: See TracChangeset
for help on using the changeset viewer.