ZF-8222: isDispatchable does not formatClassName for class_exists - neccessary for when prefixDefaultModule is true

Description

{quote} class Zend_Controller_Dispatcher_Standard { public function isDispatchable(Zend_Controller_Request_Abstract $request) { $className = $this->getControllerClass($request); if (!$className) { return false; }

    if (class_exists($className, false)) {
        return true;
    }

{quote}

When prefixDefaultModule is true, $className needs to be formatted via formatClassName otherwise the module name is not prefixed and so the class will not exist - which for example when forwarding to another action causes Zend_Loader::isReadable to always be executed.

Alternative code {quote} class Zend_Controller_Dispatcher_Standard { public function isDispatchable(Zend_Controller_Request_Abstract $request) { $className = $this->getControllerClass($request); if (!$className) { return false; }

    $class = $this->getParam('prefixDefaultModule')
                    ? ucfirst($this->formatClassName($this->_curModule, $className))
                        : $className;

    if (class_exists($class, false)) {
        return true;
    }

{quote}

Comments

I can definitely confirm this issue.

One way to illustrate the problem is to set prefixDefaultModule to true and simply define a controller class for your default module somewhere (prefix it with the module name since we've set prefixDefaultModule) and give it a default action. Make sure you put the controller file somewhere not typical (so it cannot be autoloaded), and just require_once() it in yourself. Then try requesting that controller, and you'll get a invalid controller exception.

Also, Devosc's fix works great to mitigate this issue, without any adverse effects either.

See the attached patch which includes a fix, as well as a unit test with assertions to prove the issue. Patch is in GIT format, so you may have to use git-apply. Also, it is relative from /framework/standard/trunk.

Also, note that my patch is not the same fix as devosc has proposed. Upon looking closer, his fix does not completely solve the underlying issue, as his will only solve the issue for the default module, but any other modules will still experience the issue. The unit test I wrote above illustrates this, as simply running formatClassName() if the prefixDefaultModule parameter is true will not pass the test. You have to also say "or if the requested module is not the default module", since all controllers for non-default modules must have a prefix.

Perhaps a more accurate title for this issue might be: "isDispatchable does not formatClassName for class_exists - necessary for when prefixDefaultModule is true OR the request is for a non-default module"

Patch reviewed and applied to trunk and 1.10 release branch -- thanks!