浏览代码

Internal: MetaModel to ignore classes declared only with the purpose of implementing behaviors (missing function Init). Note: declaring such a class as abstract is recommended, though it seems enough to omit the Init method. Perfs: benchmarked as an additional 1ms out of 1s for the whole page.

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2262 a333f486-631f-4898-b8df-5754b55c2be0
romainq 12 年之前
父节点
当前提交
9a762789a3
共有 1 个文件被更改,包括 16 次插入6 次删除
  1. 16 6
      core/metamodel.class.php

+ 16 - 6
core/metamodel.class.php

@@ -1348,7 +1348,8 @@ abstract class MetaModel
 
 		// Initialize the classes (declared attributes, etc.)
 		//
-		foreach(get_declared_classes() as $sPHPClass) {
+		foreach(get_declared_classes() as $sPHPClass)
+		{
 			if (is_subclass_of($sPHPClass, 'DBObject'))
 			{
 				$sParent = get_parent_class($sPHPClass);
@@ -1357,14 +1358,22 @@ abstract class MetaModel
 					// Inherit info about attributes to ignore
 					self::$m_aIgnoredAttributes[$sPHPClass] = self::$m_aIgnoredAttributes[$sParent];
 				}
-				if (method_exists($sPHPClass, 'Init'))
+				try
 				{
-					call_user_func(array($sPHPClass, 'Init'));
-					foreach (MetaModel::EnumPlugins('iOnClassInitialization') as $sPluginClass => $oClassInit)
+					$oMethod = new ReflectionMethod($sPHPClass, 'Init');
+					if ($oMethod->getDeclaringClass()->name == $sPHPClass)
 					{
-						$oClassInit->OnAfterClassInitialization($sPHPClass);
+						call_user_func(array($sPHPClass, 'Init'));
+						foreach (MetaModel::EnumPlugins('iOnClassInitialization') as $sPluginClass => $oClassInit)
+						{
+							$oClassInit->OnAfterClassInitialization($sPHPClass);
+						}
 					}
 				}
+				catch (ReflectionException $e)
+				{
+					// This class is only implementing methods, ignore it from the MetaModel perspective
+				}
 			}
 		}
 
@@ -1991,7 +2000,8 @@ abstract class MetaModel
 	{
 		self::_check_subclass($sClass);	
 		$aSubClasses = array();
-		foreach(get_declared_classes() as $sSubClass) {
+		foreach(self::$m_aClassParams as $sSubClass => $foo)
+		{
 			if (is_subclass_of($sSubClass, $sClass))
 			{
 				$aSubClasses[] = $sSubClass;