1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Fixed XenForo_Model_DataRegistry can never be extended

Discussion in 'Resolved Bug Reports' started by Jon W, Aug 17, 2013.

  1. Jon W

    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: Aug 17, 2013
    tyteen4a03 likes this.
  2. Mike

    Mike XenForo Developer Staff Member

    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.
     
    Jon W likes this.
  3. Jon W

    Jon W Well-Known Member

    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();
     
  4. Mike

    Mike XenForo Developer Staff Member

    Fixed now, good catch.
     
    Jon W likes this.

Share This Page