Fixed XenForo_Model_DataRegistry can never be extended

Jon W

Well-known member
Because XenForo_Model_DataRegistry is created before code event listeners are enabled, it is impossible to extend XenForo_Model_DataRegistry.

It is called immediately before the listeners are created in XenForo_Dependencies_Abstract:
PHP:
        $data = XenForo_Model::create('XenForo_Model_DataRegistry')->getMulti($required);

        if (XenForo_Application::get('config')->enableListeners)
        {
            if (!is_array($data['codeEventListeners']))
            {
                $data['codeEventListeners'] = XenForo_Model::create('XenForo_Model_CodeEvent')->rebuildEventListenerCache();
            }
            XenForo_CodeEvent::setListeners($data['codeEventListeners']);
        }

The first line should be changed to the following:
PHP:
        $dataRegistryModel = new XenForo_Model_DataRegistry();
        $data = $dataRegistryModel->getMulti($required);

This ensures that the model class name is not cached, so any subsequent calls to create XenForo_Model_DataRegistry will check for listeners first.
 
Last edited:
Just to clarify, as I was about to tag this as not a bug...

It's not that XenForo_Model::create() caches anything itself. It's that dynamic class resolution caches its results for each class it comes across.
 
That's what I meant, sorry.

Am having to use this really horrible workaround at the moment:
PHP:
        eval('class Some_Random_Class_Name extends XenForo_Application
        {
            public static function removeDataRegistryFromClassCache()
            {
                unset(self::$_classCache[\'XenForo_Model_DataRegistry\']);
            }
        }');
        Some_Random_Class_Name::removeDataRegistryFromClassCache();
 
Back
Top Bottom