فهرست منبع

N.740 Error when attempting to disable the logs. Took the opportunity to refactor, relying on late static bindings (requires PHP 5.3). The refactoring avoided the fix to be duplicated in three places.

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@4628 a333f486-631f-4898-b8df-5754b55c2be0
romainq 8 سال پیش
والد
کامیت
50122f8588
1فایلهای تغییر یافته به همراه29 افزوده شده و 56 حذف شده
  1. 29 56
      core/log.class.inc.php

+ 29 - 56
core/log.class.inc.php

@@ -1,5 +1,5 @@
 <?php
-// Copyright (C) 2010-2012 Combodo SARL
+// Copyright (C) 2010-2017 Combodo SARL
 //
 //   This file is part of iTop.
 //
@@ -19,7 +19,7 @@
 /**
  * File logging
  *
- * @copyright   Copyright (C) 2010-2012 Combodo SARL
+ * @copyright   Copyright (C) 2010-2017 Combodo SARL
  * @license     http://opensource.org/licenses/AGPL-3.0
  */
 
@@ -69,81 +69,54 @@ class FileLog
 	}
 }
 
-class SetupLog
+abstract class LogAPI
 {
-	protected static $m_oFileLog; 
-
 	public static function Enable($sTargetFile)
 	{
-		self::$m_oFileLog = new FileLog($sTargetFile);
+		static::$m_oFileLog = new FileLog($sTargetFile);
 	}
+
 	public static function Error($sText)
 	{
-		self::$m_oFileLog->Error($sText);
+		if (static::$m_oFileLog)
+		{
+			static::$m_oFileLog->Error($sText);
+		}
 	}
 	public static function Warning($sText)
 	{
-		self::$m_oFileLog->Warning($sText);
+		if (static::$m_oFileLog)
+		{
+			static::$m_oFileLog->Warning($sText);
+		}
 	}
 	public static function Info($sText)
 	{
-		self::$m_oFileLog->Info($sText);
+		if (static::$m_oFileLog)
+		{
+			static::$m_oFileLog->Info($sText);
+		}
 	}
 	public static function Ok($sText)
 	{
-		self::$m_oFileLog->Ok($sText);
+		if (static::$m_oFileLog)
+		{
+			static::$m_oFileLog->Ok($sText);
+		}
 	}
 }
 
-class IssueLog
+class SetupLog extends LogAPI
 {
-	protected static $m_oFileLog; 
-
-	public static function Enable($sTargetFile)
-	{
-		self::$m_oFileLog = new FileLog($sTargetFile);
-	}
-	public static function Error($sText)
-	{
-		self::$m_oFileLog->Error($sText);
-	}
-	public static function Warning($sText)
-	{
-		self::$m_oFileLog->Warning($sText);
-	}
-	public static function Info($sText)
-	{
-		self::$m_oFileLog->Info($sText);
-	}
-	public static function Ok($sText)
-	{
-		self::$m_oFileLog->Ok($sText);
-	}
+	protected static $m_oFileLog = null;
 }
 
-class ToolsLog
+class IssueLog extends LogAPI
 {
-	protected static $m_oFileLog; 
+	protected static $m_oFileLog = null;
+}
 
-	public static function Enable($sTargetFile)
-	{
-		self::$m_oFileLog = new FileLog($sTargetFile);
-	}
-	public static function Error($sText)
-	{
-		self::$m_oFileLog->Error($sText);
-	}
-	public static function Warning($sText)
-	{
-		self::$m_oFileLog->Warning($sText);
-	}
-	public static function Info($sText)
-	{
-		self::$m_oFileLog->Info($sText);
-	}
-	public static function Ok($sText)
-	{
-		self::$m_oFileLog->Ok($sText);
-	}
+class ToolsLog extends LogAPI
+{
+	protected static $m_oFileLog = null;
 }
-?>