Update of /cvsroot/phpweather/phpweather
In directory usw-pr-cvs1:/tmp/cvs-serv5332

Modified Files:
        base_object.php 
Log Message:
We now have three functions for reporting errors, warnings, and
debug-information. They all accept a message (mandatory argument) and
optionally a filename and a linenumber.

Whether or not the functions make any output, is controlled by
$this->verbosity.


Index: base_object.php
===================================================================
RCS file: /cvsroot/phpweather/phpweather/base_object.php,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -3 -r1.10 -r1.11
--- base_object.php     2001/07/08 18:57:34     1.10
+++ base_object.php     2001/07/17 12:12:03     1.11
@@ -33,6 +33,26 @@
    * @var  string
    */
   var $version;
+
+
+  /**
+   * The verbosity level of PHP Weather.
+   *
+   * This variable controls the amount of output you'll see when PHP
+   * Weather is running.
+   *
+   * If the first bit is set, then errors will be reported and
+   * terminate the script. If the second bit it set warnings will be
+   * reported, and if the third bit is set, then debug-information
+   * will also be printed.
+   *
+   * It works like error_reporting() does in PHP, so take a look at
+   * that.
+   *
+   * @var integer
+   */
+  var $verbosity = 0;
+
   
   /**
    * Sets up the properties by overriding the defaults with the actual input.
@@ -50,13 +70,15 @@
     include(PHPWEATHER_BASE_DIR . '/defaults-dist.php');
 
     if(file_exists(PHPWEATHER_BASE_DIR . '/defaults.php')) {
-      include_once(PHPWEATHER_BASE_DIR . '/defaults.php');
+      include(PHPWEATHER_BASE_DIR . '/defaults.php');
     }
-
-  /* Then we override the defaults with the actual properties */
+    
+    /* Then we override the defaults with the actual properties */
     while (list($key, $value) = each($input)) {
       $this->properties[$key] = $value;
     }
+    /* We also set the verbosity. */
+    $this->set_verbosity($this->properties['verbosity']);
 
   /* And finally, we set the version. */
     $this->version = '#VERSION#';
@@ -64,30 +86,97 @@
   }
   
   /**
-   * Prints an error-message.
+   * Changed the verbosity level.
    *
-   * You should supply it with a string as the argument, and it will 
-   * then print the string, prefixed with the word 'Error' in bold.
+   * @param   integer  The new level of verbosity.
+   * @return  void     There's no need to return anything here.
+   * @see     get_verbosity(), $verbosity
+   */
+  function set_verbosity($new_verbosity) {
+    $this->verbosity = $new_verbosity;
+    return;
+  }
+
+  /**
+   * Get the level of verbosity.
    *
-   * @param  $msg  string  The error-message.
+   * @see  set_verbosity(), $verbosity
    */
-  function error($msg) {
-    echo "<p><b>Error</b>: $msg</p>\n";
+  function get_verbosity() {
+    return $this->verbosity;
   }
   
   /**
-   * Prints a notice.
+   * Prints an error-message and halts execution.
    *
-   * You should supply it with a string as the argument, and it will 
-   * then print the string, prefixed with the word 'Debug' in bold.
+   * If the first bit is set in $this->verbosity, this function will
+   * print the message, prefixed with the word 'Error:' in bold. If
+   * you supply it with the optional arguments $file and $line, these
+   * will also be printed.
    *
-   * @param  $msg  string  The notice.
+   * The script will be terminated after the message has been shown.
+   *
+   * @param  string  The error-message.
+   * @param  string  The name of the file where the error occurred.
+   * @param  string  The line where the error occurred.
    */
-  function debug($msg) {
-    if (defined('DEBUG')) {
-      echo "<p><b>Debug</b>: $msg</p>\n";
-    }
-  }  
+  function error($msg, $file = '', $line = '') {
+    if ($this->verbosity & 1) {
+      if (!empty($line)) {
+        echo "<p><b>Fatal error:</b> $msg.\n<br>Line <b>$line</b> in file 
+<b>$file</b>.</p>\n";
+      } else {
+        echo "<p><b>Fatal error:</b> $msg.</p>\n";
+      }
+      exit;
+    }  
+  }
+
+
+  /**
+   * Issues a warning.
+   *
+   * If the second bit is set in $this->verbosity, this function will
+   * print the message, prefixed with the word 'Warning:' in bold. If
+   * you supply it with the optional arguments $file and $line, these
+   * will also be printed.
+   *
+   * Execution of the script continues.
+   *
+   * @param  string  The warning.
+   * @param  string  The name of the file where the error occurred.
+   * @param  string  The line where the error occurred.
+   */
+  function warning($msg, $file = '', $line = '') {
+    if ($this->verbosity & 2) {
+      if (!empty($line)) {
+        die("<p><b>Warning:</b> $msg.\n<br>Line <b>$line</b> in file 
+<b>$file</b>.</p>\n");
+      } else {
+        die("<p><b>Warning:</b> $msg.</p>\n");
+      }
+    }  
+  }
+
+  
+  /**
+   * Prints a message for debugging.
+   *
+   * The message is only printed if the third bit is set in
+   * $this->verbosity. The word 'Debug:' in bold will be prefixed the
+   * message.
+   * 
+   * @param  string  The debug-message.
+   * @param  string  The name of the file where the message comes from.
+   * @param  string  The line where the message comes from.
+   */
+  function debug($msg, $file = '', $line = '') {
+    if ($this->verbosity & 4) {
+      if (!empty($line)) {
+        echo "<p><b>Debug:</b> $msg. Line <b>$line</b> in file <b>$file</b>.</p>\n";
+      } else {
+        echo "<p><b>Debug:</b> $msg.</p>\n";
+      }
+    }  
+  }
 
   /**
    * Prints properties.


_______________________________________________
PHPWeather-checkins mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/phpweather-checkins

Reply via email to