Create Observer in the Mage_Core_Model_App class for the run

1

When looking at the class app\code\core\Mage\Core\Model\App.php , we have the following function:

public function run($params)
    {
        $options = isset($params['options']) ? $params['options'] : array();
        $this->baseInit($options);
        Mage::register('application_params', $params);

        if ($this->_cache->processRequest()) {
            $this->getResponse()->sendResponse();
        } else {
            $this->_initModules();
            $this->loadAreaPart(Mage_Core_Model_App_Area::AREA_GLOBAL, Mage_Core_Model_App_Area::PART_EVENTS);

            if ($this->_config->isLocalConfigLoaded()) {
                $scopeCode = isset($params['scope_code']) ? $params['scope_code'] : '';
                $scopeType = isset($params['scope_type']) ? $params['scope_type'] : 'store';
                $this->_initCurrentStore($scopeCode, $scopeType);
                $this->_initRequest();
                Mage_Core_Model_Resource_Setup::applyAllDataUpdates();
            }

            $this->getFrontController()->dispatch();
        }
        return $this;
    }

To add a event/observer we use the following code:

<events>
  <EVENT_TO_HOOK>
    <observers>
      <module>
        <type>singleton</type>
        <class>company_module_model_observer</class>
        <method>methodToCall</method>
      </module>
    </observers>
  </EVENT_TO_HOOK>     
</events>

What event should we add to observe the run function of class Mage_Core_Model_App ?

    
asked by anonymous 07.02.2014 / 19:37

1 answer

1

It is not possible to observe the run function of class Mage_Core_Model_App through an event.

The only event triggered in this class was application_clean_cache . Check out the full list at link

But the above listing is valid for version 1.8 - this event mentioned above no longer exists.

An event is triggered by the dispatchEvent method. For example:

Mage::dispatchEvent('application_clean_cache', array('tags' => $tags));

(source: link )

In the code of the function run in app\code\core\Mage\Core\Model\App.php , posted in the question, we see that there is no call to Mage::dispatchEvent . This means that no event is triggered and therefore there is no event to be observed and captured there.

The alternative is to extend the class and make an override of the function .

Or (although not recommended) change the function code in Magento, adding the trigger for an event with dispatchEvent ...

    
07.02.2014 / 21:02