Revision: 1857
Author: olavmrk
Date: Fri Oct 16 04:04:08 2009
Log: Add support for masking error messages.
http://code.google.com/p/simplesamlphp/source/detail?r=1857

Modified:
  /trunk/lib/SimpleSAML/Utilities.php
  /trunk/www/_include.php

=======================================
--- /trunk/lib/SimpleSAML/Utilities.php Tue Sep 22 03:01:58 2009
+++ /trunk/lib/SimpleSAML/Utilities.php Fri Oct 16 04:04:08 2009
@@ -9,6 +9,25 @@
   */
  class SimpleSAML_Utilities {

+       /**
+        * List of log levels.
+        *
+        * This list is used to restore the log levels after some log levels 
are  
disabled.
+        *
+        * @var array
+        */
+       private static $logLevelStack = array();
+
+
+       /**
+        * The current mask of disabled log levels.
+        *
+        * Note: This mask is not directly related to the PHP error reporting  
level.
+        *
+        * @var int
+        */
+       public static $logMask = 0;
+

        /**
         * Will return sp.example.org
@@ -2061,6 +2080,38 @@

                return $tempDir;
        }
+
+
+       /**
+        * Disable reporting of the given log levels.
+        *
+        * Every call to this function must be followed by a call to  
popErrorMask();
+        *
+        * @param int $mask  The log levels that should be masked.
+        */
+       public static function maskErrors($mask) {
+               assert('is_int($mask)');
+
+               $currentEnabled = error_reporting();
+               self::$logLevelStack[] = array($currentEnabled, self::$logMask);
+
+               $currentEnabled &= ~$mask;
+               error_reporting($currentEnabled);
+               self::$logMask |= $mask;
+       }
+
+
+       /**
+        * Pop an error mask.
+        *
+        * This function restores the previous error mask.
+        */
+       public static function popErrorMask() {
+
+               $lastMask = array_pop(self::$logLevelStack);
+               error_reporting($lastMask[0]);
+               self::$logMask = $lastMask[1];
+       }

  }

=======================================
--- /trunk/www/_include.php     Mon Aug 24 01:39:57 2009
+++ /trunk/www/_include.php     Fri Oct 16 04:04:08 2009
@@ -32,6 +32,11 @@
  /* Log full backtrace on errors and warnings. */
  function SimpleSAML_error_handler($errno, $errstr, $errfile = NULL,  
$errline = 0, $errcontext = NULL) {

+       if ($errno & SimpleSAML_Utilities::$logMask) {
+               /* Masked error. */
+               return FALSE;
+       }
+
        static $limit = 5;
        $limit -= 1;
        if ($limit < 0) {

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"simpleSAMLphp commits" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/simplesamlphp-commits?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to