[Mapbender-commits] r1943 - trunk/mapbender/http/classes

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Jan 3 10:44:51 EST 2008


Author: christoph
Date: 2008-01-03 10:44:51 -0500 (Thu, 03 Jan 2008)
New Revision: 1943

Added:
   trunk/mapbender/http/classes/class_mb_log.php
   trunk/mapbender/http/classes/class_mb_notice.php
   trunk/mapbender/http/classes/class_mb_warning.php
Modified:
   trunk/mapbender/http/classes/class_mb_exception.php
Log:
rewritten for PHP5 OOP
added phpdoc comments

Modified: trunk/mapbender/http/classes/class_mb_exception.php
===================================================================
--- trunk/mapbender/http/classes/class_mb_exception.php	2008-01-03 15:02:48 UTC (rev 1942)
+++ trunk/mapbender/http/classes/class_mb_exception.php	2008-01-03 15:44:51 UTC (rev 1943)
@@ -18,97 +18,23 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
-/*
-* class exception
-*
-*/
-include(dirname(__FILE__)."/../../conf/mapbender.conf");
+require_once(dirname(__FILE__)."/../classes/class_mb_log.php");
 
-class mb_log {
-	var $log_levels = LOG_LEVEL_LIST;
-	var $mb_log_level = LOG_LEVEL;	
-	var $dir = "../../log/";
-	var $filename_prefix = "mb_error_";
-	var $result = false;
-	var $message = "";
+/**
+ * @package exceptionHandling
+ */
+class mb_exception extends mb_log {
 
-	function indexOf($level, $levelArray) {
-		$index = false;
-		for ($i=0; $i < count($levelArray); $i++) {
-			if ($levelArray[$i] == $level) {
-				$index = $i;
-			}
-		}
-		return $index;
+	/**
+	 * @param	string $message		message that is being logged
+	 */
+	public function __construct ($message) {
+		return $this->mb_log("ERROR: " . $message, $this->level);
 	}
 
-	function isValidLevel($level) {
-		$log_level_array = explode(",", $this->log_levels);
-		$isValid = in_array($level, $log_level_array);
-		$isAppropriate = ($this->indexOf($level, $log_level_array) <= $this->indexOf($this->mb_log_level, $log_level_array));
-		return $isValid && $isAppropriate;
-	}
-	
-	function mb_log($n, $level){
-		if (!isset($this->mb_log_level)) {
-			$n = "class_mb_exception: please set LOG_LEVEL in mapbender.conf" . $n;
-		}
-		if ($this->isValidLevel($level)) {
-			if(is_dir($this->dir)){
-				$logfile = $this->dir . $this->filename_prefix . date("Y_m_d") . ".log";
-				if($h = fopen($logfile,"a")){
-					$content = date("Y.m.d, H:i:s") . "," . $n .chr(13).chr(10);
-					if(!fwrite($h,$content)){
-						$this->result = false;
-						$this->message = "Unable to write " . $logfile;
-						return false;
-					}
-					fclose($h);
-					$this->result = true;
-					$this->message = "Successful.";
-					return true;
-				}
-				else {
-					$this->result = false;
-					$this->message = "Unable to open or generate " . $logfile;
-					return false;
-				}
-			}
-			else {
-				$this->result = false;
-				$this->message = "Directory " . $this->dir . " is not valid.";
-				return false;
-			}
-		}
-		else {
-			$this->result = false;
-			$this->message = "Log level '" . $level . "' is not valid or logging is disabled in mapbender.conf.";
-			return false; 
-		}
-	}
+	/**
+	 * @var string a description of the log level
+	 */
+	private $level = "error";
 }
-
-class mb_notice extends mb_log {
-	var $level = "notice";
-	
-	function mb_notice($message) {
-		return $this->mb_log("Notice: " . $message, $this->level);
-	}
-}
-
-class mb_warning extends mb_log {
-	var $level = "warning";
-	
-	function mb_warning($message) {
-		return $this->mb_log("Warning: " . $message, $this->level);
-	}
-}
-
-class mb_exception extends mb_log {
-	var $level = "error";
-	
-	function mb_exception($message) {
-		return $this->mb_log("ERROR: " . $message, $this->level);
-	}
-}
 ?>
\ No newline at end of file

Added: trunk/mapbender/http/classes/class_mb_log.php
===================================================================
--- trunk/mapbender/http/classes/class_mb_log.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_mb_log.php	2008-01-03 15:44:51 UTC (rev 1943)
@@ -0,0 +1,143 @@
+<?php
+
+# $Id: class_mb_exception.php 1827 2007-11-23 11:31:03Z christoph $
+# http://www.mapbender.org/index.php/class_mb_exception.php
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../../conf/mapbender.conf");
+require_once(dirname(__FILE__)."/../classes/class_mb_notice.php");
+require_once(dirname(__FILE__)."/../classes/class_mb_warning.php");
+require_once(dirname(__FILE__)."/../classes/class_mb_exception.php");
+
+/**
+ * @package exceptionHandling
+ */
+abstract class mb_log {
+	
+	/**
+	 * Appends a message to a given log file.
+	 * 
+	 * @param	string $n		the message that is being logged.
+	 * @param	string $level	the log level of the message.
+	 * @return	bool			true if the logging succeded; else false.
+	 */
+	protected function mb_log ($n, $level) {
+		if (!isset($this->mb_log_level)) {
+			$n = "class_mb_exception: please set LOG_LEVEL in mapbender.conf" . $n;
+		}
+		if ($this->isValidLevel($level)) {
+			if (is_dir($this->dir)) {
+				$logfile = $this->dir . $this->filename_prefix . date("Y_m_d") . ".log";
+				if ($h = fopen($logfile,"a")) {
+					$content = date("Y.m.d, H:i:s") . "," . $n .chr(13).chr(10);
+					if(!fwrite($h,$content)){
+						$this->result = false;
+						$this->message = "Unable to write " . $logfile;
+						return false;
+					}
+					fclose($h);
+					$this->result = true;
+					$this->message = "Successful.";
+					return true;
+				}
+				else {
+					$this->result = false;
+					$this->message = "Unable to open or generate " . $logfile;
+					return false;
+				}
+			}
+			else {
+				$this->result = false;
+				$this->message = "Directory " . $this->dir . " is not valid.";
+				return false;
+			}
+		}
+		else {
+			$this->result = false;
+			$this->message = "Log level '" . $level . "' is not valid or logging is disabled in mapbender.conf.";
+			return false; 
+		}
+	}
+
+	/**
+	 * Retrieves the index of the level in the array of available levels.
+	 * By this, we can find out if the message is eligable for logging.
+	 * 
+	 * @param	string $level			the log level of the message
+	 * @param	string[] $levelArray	an array of available levels
+	 * @return	mixed					false, if the level is not available; else 
+	 * 									the index of the level in the log level array
+	 */
+	protected function indexOf ($level, $levelArray) {
+		$index = false;
+		for ($i=0; $i < count($levelArray); $i++) {
+			if ($levelArray[$i] == $level) {
+				$index = $i;
+			}
+		}
+		return $index;
+	}
+
+	/**
+	 * Checks if the message will be logged. Example: Log level of the message is "warning",
+	 * but the log level set in 
+	 * {@link http://www.mapbender.org/index.php/Mapbender.conf#Mapbender_error_logging mapbender.conf}
+	 * is "off", then the message will not be logged.
+	 * 
+	 * @param	string $level	the log level of the message that is being logged.
+	 * @return	bool			true if the message will be logged; else false.
+	 */
+	protected function isValidLevel ($level) {
+		$log_level_array = explode(",", $this->log_levels);
+		$isValid = in_array($level, $log_level_array);
+		$isAppropriate = ($this->indexOf($level, $log_level_array) <= $this->indexOf($this->mb_log_level, $log_level_array));
+		return $isValid && $isAppropriate;
+	}
+	
+	/**
+	 * @var	string	a comma-separated list of available log levels, see 
+	 * 				{@link http://www.mapbender.org/index.php/Mapbender.conf#Mapbender_error_logging mapbender.conf}.
+	 */
+	protected $log_levels = LOG_LEVEL_LIST;
+
+	/**
+	 * @var	string	the selected log level, see 
+	 * 				{@link http://www.mapbender.org/index.php/Mapbender.conf#Mapbender_error_logging mapbender.conf}.
+	 */
+	protected $mb_log_level = LOG_LEVEL;	
+
+	/**
+	 * @var	string	the path to the log directory
+	 */
+	protected $dir = "../../log/";
+
+	/**
+	 * @var	string	the prefix of the logs' file name
+	 */
+	protected $filename_prefix = "mb_error_";
+
+	/**
+	 * @var	bool	true if the logging succeeded; else false.
+	 */
+	protected $result = false;
+
+	/**
+	 * @var	string	if the logging did not succeed, this contains an error message.
+	 */
+	protected $message = "";
+}
+?>
\ No newline at end of file

Added: trunk/mapbender/http/classes/class_mb_notice.php
===================================================================
--- trunk/mapbender/http/classes/class_mb_notice.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_mb_notice.php	2008-01-03 15:44:51 UTC (rev 1943)
@@ -0,0 +1,40 @@
+<?php
+
+# $Id: class_mb_exception.php 1827 2007-11-23 11:31:03Z christoph $
+# http://www.mapbender.org/index.php/class_mb_exception.php
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../classes/class_mb_log.php");
+
+/**
+ * @package exceptionHandling
+ */
+class mb_notice extends mb_log {
+
+	/**
+	 * @param	string $message		message that is being logged
+	 */
+	public function __construct ($message) {
+		return $this->mb_log("Notice: " . $message, $this->level);
+	}
+
+	/**
+	 * @var string a description of the log level
+	 */
+	private $level = "notice";
+}
+?>
\ No newline at end of file

Added: trunk/mapbender/http/classes/class_mb_warning.php
===================================================================
--- trunk/mapbender/http/classes/class_mb_warning.php	                        (rev 0)
+++ trunk/mapbender/http/classes/class_mb_warning.php	2008-01-03 15:44:51 UTC (rev 1943)
@@ -0,0 +1,40 @@
+<?php
+
+# $Id: class_mb_exception.php 1827 2007-11-23 11:31:03Z christoph $
+# http://www.mapbender.org/index.php/class_mb_exception.php
+# Copyright (C) 2002 CCGIS 
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+require_once(dirname(__FILE__)."/../classes/class_mb_log.php");
+
+/**
+ * @package exceptionHandling
+ */
+class mb_warning extends mb_log {
+	
+	/**
+	 * @param	string $message		message that is being logged
+	 */
+	public function __construct ($message) {
+		return $this->mb_log("Warning: " . $message, $this->level);
+	}
+
+	/**
+	 * @var string a description of the log level
+	 */
+	private $level = "warning";
+}
+?>
\ No newline at end of file



More information about the Mapbender_commits mailing list