[xoops-cvslog 3386] CVS update: xoops2jp/html/kernel

Back to archive index

NobuNobu nobun****@users*****
2006年 6月 28日 (水) 18:11:26 JST


Index: xoops2jp/html/kernel/XCube_Delegate.class.php
diff -u xoops2jp/html/kernel/XCube_Delegate.class.php:1.1.2.5 xoops2jp/html/kernel/XCube_Delegate.class.php:1.1.2.6
--- xoops2jp/html/kernel/XCube_Delegate.class.php:1.1.2.5	Wed Jun 28 14:45:27 2006
+++ xoops2jp/html/kernel/XCube_Delegate.class.php	Wed Jun 28 18:11:26 2006
@@ -1,6 +1,6 @@
 <?php
 /**
- * @version $Id: XCube_Delegate.class.php,v 1.1.2.5 2006/06/28 05:45:27 minahito Exp $
+ * @version $Id: XCube_Delegate.class.php,v 1.1.2.6 2006/06/28 09:11:26 nobunobu Exp $
  */
  
 
@@ -47,13 +47,6 @@
 	var $_mSignatures = array();
 	
 	/**
-	 * This is ID for $_mCallbacks and $_mPriorities, and counted up at add().
-	 * 
-	 * @var int
-	 */
-	var $_mCurrentID = 0;
-	
-	/**
 	 * This is Array for callback type data.
 	 * 
 	 * @var array
@@ -61,21 +54,6 @@
 	var $_mCallbacks = array();
 	
 	/**
-	 * This is Array that has priorities for _mCallbacks. The key is the key of 
-	 * _mCallbacks. The value is priority.
-	 * 
-	 * @var array for int
-	 */
-	var $_mPriorities = array();
-
-	/**
-	 * This is Array that has file path for _mCallbacks.
-	 * 
-	 * @var array for string
-	 */	
-	var $_mCallbackPaths = array();
-
-	/**
 	 * @var bool
 	 */	
 	var $_mHasCheckSignatures = false;
@@ -177,11 +155,8 @@
 			$filepath = $param2;
 		}
 		
-		$this->_mCallbacks[$this->_mCurrentID] = $callback;
-		$this->_mPriorities[$this->_mCurrentID] = $priority;
-		$this->_mCallbackPaths[$this->_mCurrentID] = $filepath;
-		
-		$this->_mCurrentID++;
+		$this->_mCallbacks[$priority][] = array($callback, $filepath);
+        ksort($this->_mCallbacks);
 	}
 	
 	/**
@@ -189,28 +164,33 @@
 	 * @access public
 	 * @return void
 	 */
-	function delete($callback)
+	function delete($delcallback)
 	{
-        $count = count($this->_mCallbacks);
-        ksort($this->_mPriorities);
-        foreach(array_keys($this->_mCallbacks) as $key) {
-            if ((!is_array($callback)&&($this->_mCallbacks[$key] === $callback))||(is_array($callback)&&((gettype($this->_mCallbacks[$key][0]) === gettype($callback[0]))&&((!is_object($callback[0])&&($this->_mCallbacks[$key][0] === $callback[0])))||((is_object($callback[0])&&(get_class($this->_mCallbacks[$key][0]) === get_class($callback[0])))))&&($this->_mCallbacks[$key][1] === $callback[1]))) {
-                $this->_mCallbacks = 
-                    array_merge(array_slice($this->_mCallbacks, 0, $key),
-                                array_slice($this->_mCallbacks, $key+1));
-
-                $this->_mPriorities = 
-                    array_merge(array_slice($this->_mPriorities, 0, $key),
-                                array_slice($this->_mPriorities, $key+1));
-
-                $this->_mCallbackPaths = 
-                    array_merge(array_slice($this->_mCallbackPaths, 0, $key),
-                                array_slice($this->_mCallbackPaths, $key+1));
+		foreach (array_keys($this->_mCallbacks) as $priority) {
+            foreach (array_keys($this->_mCallbacks[$priority]) as $idx) {
+                $callback = $this->_mCallbacks[$priority][$idx][0];
+                if (XCube_DelegateUtils::_compareCallback($callback, $delcallback)) {
+                    unset($this->_mCallbacks[$priority][$idx]);
+                }
+                if (count($this->_mCallbacks[$priority])==0) {
+                    unset($this->_mCallbacks[$priority]);
+                }
             }
         }
     }
 
 	/**
+	 * Reset all delegate functions from this object.
+	 * @access public
+	 * @return void
+	 */
+	function reset()
+	{
+	    unset($this->_mCallbacks);
+	    $this->_mCallbacks = array();
+    }
+
+	/**
 	 * Call connected functions.
 	 *
 	 * @access public
@@ -285,32 +265,31 @@
 			$argstr = "()";
 		}
 
-		asort($this->_mPriorities, SORT_NUMERIC);
-
 		//
 		// We have to use eval in the case of an instance method because 
 		// call_user_func() can't handle references rightly.
-		//		
-		foreach (array_keys($this->_mPriorities) as $id) {
-			$callback =& $this->_mCallbacks[$id];
-			
-			$staticFlag = true;
-			
-			if (is_array($callback) && count($callback) == 2) {
-				if (is_object($callback[0]) && method_exists($callback[0], $callback[1])) {
-					eval('$callback[0]->' . $callback[1] . $argstr);
-					$staticFlag = false;
-				}
-			}
-			
-			if ($staticFlag) {
-				if ($this->_mCallbackPaths[$id] != null && file_exists($this->_mCallbackPaths[$id])) {
-					require_once $this->_mCallbackPaths[$id];
-				}
-				if (is_callable($callback)) {
-					call_user_func_array($callback, $args);
-				}
-			}
+		//
+		foreach ($this->_mCallbacks as $callback_arrays) {
+            foreach ($callback_arrays as $callback_array) {
+                $callback = $callback_array[0];
+                $staticFlag = true;
+
+                if (is_array($callback) && count($callback) == 2) {
+                	if (is_object($callback[0]) && method_exists($callback[0], $callback[1])) {
+                		eval('$callback[0]->' . $callback[1] . $argstr);
+                		$staticFlag = false;
+                	}
+                }
+
+                if ($staticFlag) {
+                	if ($callback_array[1] != null && file_exists($callback_array[1])) {
+                		require_once $callback_array[1];
+                	}
+                	if (is_callable($callback)) {
+                		call_user_func_array($callback, $args);
+                	}
+                }
+            }
 		}
 	}
 }
@@ -350,7 +329,7 @@
 		if (!isset($this->_mDelegates[$name])) {
 			$this->_mDelegates[$name] =& $delegate;
 			
-			if (count($this->_mCallbacks[$name]) > 0) {
+			if (isset($this->_mCallbacks[$name]) && count($this->_mCallbacks[$name]) > 0) {
 				foreach (array_keys($this->_mCallbacks[$name]) as $key) {
 					$delegate->add($this->_mCallbacks[$name][$key], $this->_mCallbackParameters[$name][$key][0], $this->_mCallbackParameters[$name][$key][1]);
 				}
@@ -396,28 +375,42 @@
 	 * 
 	 * @see XCube_NewDelegate::delete()
 	 */
-	function delete($name, $callback)
+	function delete($name, $delcallback)
 	{
 		if (isset($this->_mDelegates[$name])) {
-			$this->_mDelegates[$name]->delete($callback);
-		}
-		else {
+			$this->_mDelegates[$name]->delete($delcallback);
+		} else {
 		    if (isset($this->_mCallbacks[$name])) {
-		        $count = count($this->_mCallbacks[$name]);
 		        foreach(array_keys($this->_mCallbacks[$name]) as $key) {
-                    if ((!is_array($callback)&&($this->_mCallbacks[$name][$key] === $callback))||(is_array($callback)&&((gettype($this->_mCallbacks[$key][$name][0]) === gettype($callback[0]))&&((!is_object($callback[0])&&($this->_mCallbacks[$key][$name][0] === $callback[0])))||((is_object($callback[0])&&(get_class($this->_mCallbacks[$key][$name][0]) === get_class($callback[0])))))&&($this->_mCallbacks[$key][$name][1] === $callback[1]))) {
-		                $this->_mCallbacks[$name] = 
-		                    array_merge(array_slice($this->_mCallbacks[$name], 0, $key),
-		                                array_slice($this->_mCallbacks[$name], $key+1));
-		                $this->_mCallbackParameters[$name] = 
-		                    array_merge(array_slice($this->_mCallbackParameters[$name], 0, $key),
-		                                array_slice($this->_mCallbackParameters[$name], $key+1));
-		            }
+                    $callback = $this->_mCallbacks[$name][$key];
+                    if (XCube_DelegateUtils::_compareCallback($callback, $delcallback)) {
+                        unset($this->_mCallbacks[$name][$key]);
+                        unset($this->_mCallbackParameters[$name][$key]);
+                    }
 		        }
 		    }
 		}
 	}
 	
+	/**
+	 * Reset all functions off the delegate that have the specified name.
+	 *
+	 * @access public
+	 * 
+	 * @see XCube_NewDelegate::reset()
+	 */
+	function reset($name)
+	{
+		if (isset($this->_mDelegates[$name])) {
+			$this->_mDelegates[$name]->reset();
+		} else {
+		    if (isset($this->_mCallbacks[$name])) {
+		        unset($this->_mCallbacks[$name]);
+		        unset($this->_mCallbackParameters[$name]);
+		    }
+		}
+	}
+	
 	
    /**
     * 
@@ -515,5 +508,27 @@
             return "";
         }
     }
+    
+    function _compareCallback($callback1, $callback2) {
+    /**
+     * Comparing two callback (PHP4 cannot compare Object exactly)
+     *
+     * @access file
+     * @param $callback1  : callback
+     * @param $callback2  : callback
+     * @return bool
+     */
+        if (!is_array($callback1) && !is_array($callback2) && ($callback1 === $callback2)) {
+            return true;
+        } elseif (is_array($callback1) && is_array($callback2) && (gettype($callback1[0]) === gettype($callback2[0])) 
+                                                               && ($callback1[1] === $callback2[1])) {
+            if (!is_object($callback1[0]) && ($callback1[0] === $callback2[0])) {
+                return true;
+            } elseif (is_object($callback1[0]) && (get_class($callback1[0]) === get_class($callback2[0]))) {
+                return true;
+            }
+        }
+        return false;
+    }
 }
 ?>
\ No newline at end of file


xoops-cvslog メーリングリストの案内
Back to archive index