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.

SVN:trunk[2262]
This commit is contained in:
Romain Quetiez
2012-10-16 14:07:21 +00:00
parent e454a12346
commit 020089b1d3

View File

@@ -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;