Issues

ZF-5895: isDispatched() not checked after action helper preDispatch() in action dispatch()

Description

Current, the dispatched flag is only checked once both the helpers preDispatch and the actions preDispatch have been called.


    // summarized
    public function dispatch($action)
    {
        // Notify helpers of action preDispatch state
        $this->_helper->notifyPreDispatch();

        $this->preDispatch();
        if ($this->getRequest()->isDispatched()) {
                $this->$action();
                $this->postDispatch();
        }
        $this->_helper->notifyPostDispatch();
    }

This means that the controllers preDispatch() method is always called, even when $this->$action() may not be called. At the very least, this seems to be inefficient. At worst, a careless (ie me) programmer might write an action helper that sets dispatch to false and ends up chasing his tail for an hour trying to figure out why his preDispatch() is still being called.

It seems to me that the dispatch method should look something like this:


    // summarized
    public function dispatch($action)
    {
        // Notify helpers of action preDispatch state
        $this->_helper->notifyPreDispatch();

        if ($this->getRequest()->isDispatched()) {
            $this->preDispatch();
            if ($this->getRequest()->isDispatched()) {
                    $this->$action();
                    $this->postDispatch();
            }
        }
        $this->_helper->notifyPostDispatch();
    }

Comments

While I can see some use cases for this, changing it at this time would introduce a fairly significant BC break. Marking it as postponed.