<commit_before><?php
Zend_Controller_Action_HelperBroker::removeHelper('viewRenderer');
Zend_Controller_Action_HelperBroker::addHelper(new Kwf_Controller_Action_Helper_ViewRenderer());

class Kwf_Controller_Front extends Zend_Controller_Front
{
    private $_webRouter;

    protected function _init()
    {
        $this->setDispatcher(new Kwf_Controller_Dispatcher());

        $this->setControllerDirectory('controllers');
        $this->returnResponse(true);
        $this->setParam('disableOutputBuffering', true);

        $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Welcome',
                                        'kwf_controller_action_welcome');
        $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/User',
                                        'kwf_controller_action_user');
        $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Error',
                                        'kwf_controller_action_error');
        $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Pool',
                                'kwf_controller_action_pool');
        $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Debug',
                                'kwf_controller_action_debug');
        $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Cli',
                                'kwf_controller_action_cli');
        $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Cli/Web',
                                'kwf_controller_action_cli_web');
        $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Media',
                                'kwf_controller_action_media');
        $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Spam',
                                        'kwf_controller_action_spam');
        $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Enquiries',
                                        'kwf_controller_action_enquiries');
        $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Redirects',
                                        'kwf_controller_action_redirects');
        $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Maintenance',
                                        'kwf_controller_action_maintenance');
        $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Ext4',
                                        'kwf_controller_action_ext4');
        $this->addControllerDirectory(KWF_PATH . '/tests', 'kwf_test');
        $this->addControllerDirectory('tests', 'web_test');
        $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Trl',
                                'kwf_controller_action_trl');
        if (file_exists('controllers/Cli')) {
            $this->addControllerDirectory('controllers/Cli', 'cli');
        }
        $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Component',
                                        'kwf_controller_action_component');

        if (is_dir('controllers')) {
            //automatically add controller directories from web based on existing directories in filesystem in web
            $iterator = new DirectoryIterator('controllers');
            $filter = new Zend_Filter_Word_CamelCaseToDash();
            foreach($iterator as $fileinfo) {
                if (!$fileinfo->isDot() && $fileinfo->isDir() && $fileinfo->getBasename() != 'Cli') {
                    $this->addControllerDirectory($fileinfo->getPathname(), strtolower($filter->filter($fileinfo->getBasename())));
                }
            }
        }


        $plugin = new Zend_Controller_Plugin_ErrorHandler();
        $plugin->setErrorHandlerModule('kwf_controller_action_error');
        if (php_sapi_name() == 'cli') {
            $plugin->setErrorHandlerController('cli');
        }
        $this->registerPlugin($plugin);

        $this->setBaseUrl(Kwf_Setup::getBaseUrl());
    }

    public static function getInstance()
    {
        if (null === self::$_instance) {
            $class = Kwf_Config::getValue('frontControllerClass');
            if (!$class) {
                $validCommands = array('shell', 'export', 'copy-to-test'); //für ältere branches
                if (php_sapi_name() != 'cli' || !isset($_SERVER['argv'][1]) || !in_array($_SERVER['argv'][1], $validCommands)) {
                    throw new Kwf_Exception("frontControllerClass must be set in config.ini");
                }
                $class = 'Kwf_Controller_Front';
            }
            self::$_instance = new $class();
            self::$_instance->_init();
        }

        return self::$_instance;
    }

    public final function getRouter()
    {
        if (null == $this->_router) {
            if (php_sapi_name() == 'cli') {
                $this->setRouter($this->_getDefaultCliRouter());
            } else {
                $this->setRouter($this->getWebRouter());
            }
        }

        return $this->_router;
    }

    protected function _getDefaultCliRouter()
    {
        return new Kwf_Controller_Router_Cli();
    }

    public function getWebRouter()
    {
        if (isset($this->_webRouter)) {
            return $this->_webRouter;
        } else {
            return $this->_getDefaultWebRouter();
        }
    }

    protected function _getDefaultWebRouter()
    {
        return new Kwf_Controller_Router('');
    }

    public function setWebRouter(Zend_Controller_Router_Interface $router)
    {
        $this->_webRouter = $router;
    }

    public function dispatch(Zend_Controller_Request_Abstract $request = null, Zend_Controller_Response_Abstract $response = null)
    {
        if ($request === null) {
            if (php_sapi_name() == 'cli') {
                $request = new Kwf_Controller_Request_Cli();
            } else {
                $request = new Kwf_Controller_Request_Http();
            }
        }
        if ($response === null) {
            $response = new Kwf_Controller_Response_Http();
        }
        $ret = parent::dispatch($request, $response);
        Kwf_Benchmark::shutDown();
        return $ret;
    }
}
<commit_msg>Zend_Controller: When route doesn't match show 404 page instead of 500<commit_after><?php
Zend_Controller_Action_HelperBroker::removeHelper('viewRenderer');
Zend_Controller_Action_HelperBroker::addHelper(new Kwf_Controller_Action_Helper_ViewRenderer());

class Kwf_Controller_Front extends Zend_Controller_Front
{
    private $_webRouter;

    protected function _init()
    {
        $this->setDispatcher(new Kwf_Controller_Dispatcher());

        $this->setControllerDirectory('controllers');
        $this->returnResponse(true);
        $this->setParam('disableOutputBuffering', true);

        $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Welcome',
                                        'kwf_controller_action_welcome');
        $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/User',
                                        'kwf_controller_action_user');
        $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Error',
                                        'kwf_controller_action_error');
        $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Pool',
                                'kwf_controller_action_pool');
        $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Debug',
                                'kwf_controller_action_debug');
        $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Cli',
                                'kwf_controller_action_cli');
        $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Cli/Web',
                                'kwf_controller_action_cli_web');
        $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Media',
                                'kwf_controller_action_media');
        $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Spam',
                                        'kwf_controller_action_spam');
        $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Enquiries',
                                        'kwf_controller_action_enquiries');
        $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Redirects',
                                        'kwf_controller_action_redirects');
        $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Maintenance',
                                        'kwf_controller_action_maintenance');
        $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Ext4',
                                        'kwf_controller_action_ext4');
        $this->addControllerDirectory(KWF_PATH . '/tests', 'kwf_test');
        $this->addControllerDirectory('tests', 'web_test');
        $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Trl',
                                'kwf_controller_action_trl');
        if (file_exists('controllers/Cli')) {
            $this->addControllerDirectory('controllers/Cli', 'cli');
        }
        $this->addControllerDirectory(KWF_PATH . '/Kwf/Controller/Action/Component',
                                        'kwf_controller_action_component');

        if (is_dir('controllers')) {
            //automatically add controller directories from web based on existing directories in filesystem in web
            $iterator = new DirectoryIterator('controllers');
            $filter = new Zend_Filter_Word_CamelCaseToDash();
            foreach($iterator as $fileinfo) {
                if (!$fileinfo->isDot() && $fileinfo->isDir() && $fileinfo->getBasename() != 'Cli') {
                    $this->addControllerDirectory($fileinfo->getPathname(), strtolower($filter->filter($fileinfo->getBasename())));
                }
            }
        }


        $plugin = new Zend_Controller_Plugin_ErrorHandler();
        $plugin->setErrorHandlerModule('kwf_controller_action_error');
        if (php_sapi_name() == 'cli') {
            $plugin->setErrorHandlerController('cli');
        }
        $this->registerPlugin($plugin);

        $this->setBaseUrl(Kwf_Setup::getBaseUrl());
    }

    public static function getInstance()
    {
        if (null === self::$_instance) {
            $class = Kwf_Config::getValue('frontControllerClass');
            if (!$class) {
                $validCommands = array('shell', 'export', 'copy-to-test'); //für ältere branches
                if (php_sapi_name() != 'cli' || !isset($_SERVER['argv'][1]) || !in_array($_SERVER['argv'][1], $validCommands)) {
                    throw new Kwf_Exception("frontControllerClass must be set in config.ini");
                }
                $class = 'Kwf_Controller_Front';
            }
            self::$_instance = new $class();
            self::$_instance->_init();
        }

        return self::$_instance;
    }

    public final function getRouter()
    {
        if (null == $this->_router) {
            if (php_sapi_name() == 'cli') {
                $this->setRouter($this->_getDefaultCliRouter());
            } else {
                $this->setRouter($this->getWebRouter());
            }
        }

        return $this->_router;
    }

    protected function _getDefaultCliRouter()
    {
        return new Kwf_Controller_Router_Cli();
    }

    public function getWebRouter()
    {
        if (isset($this->_webRouter)) {
            return $this->_webRouter;
        } else {
            return $this->_getDefaultWebRouter();
        }
    }

    protected function _getDefaultWebRouter()
    {
        return new Kwf_Controller_Router('');
    }

    public function setWebRouter(Zend_Controller_Router_Interface $router)
    {
        $this->_webRouter = $router;
    }

    public function dispatch(Zend_Controller_Request_Abstract $request = null, Zend_Controller_Response_Abstract $response = null)
    {
        if ($request === null) {
            if (php_sapi_name() == 'cli') {
                $request = new Kwf_Controller_Request_Cli();
            } else {
                $request = new Kwf_Controller_Request_Http();
            }
        }
        if ($response === null) {
            $response = new Kwf_Controller_Response_Http();
        }
        try {
            $ret = parent::dispatch($request, $response);
        } catch (Zend_Controller_Router_Exception $e) {
            if ($e->getCode() == 404) {
                //fired by Zend_Controller_Router_Rewrite::route, transform into proper 404
                throw new Kwf_Exception_NotFound();
            } else {
                throw $e;
            }
        }

        Kwf_Benchmark::shutDown();
        return $ret;
    }
}

{'fraction_non_alphanumeric': 0.12094187592896816, 'fraction_numerical': 0.0015645779550966126, 'mean_word_length': 2.1089494163424125, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 92, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7356767', 'n_tokens_mistral': 3479, 'n_tokens_neox': 3314, 'n_words': 492}