<?php
/**
 * The Application error controller.
 *
 * @package koubel homepage
 * @author Miroslav Kubelik (koubel@volny.cz)
 * @copyright Copyright (c) 2007-2009 Miroslav Kubelik
 * @license http://opensource.org/licenses/gpl-license.php GNU GPL
 */

/**
 * The application error controller, which is responsible for MVC exceptions
 * 
 * This controller and its actions are called through ZF ErrorHandler plugin.
 *
 * @package koubel homepage
 * @author Miroslav Kubelik (koubel@volny.cz)
 * @copyright Copyright (c) 2007-2009 Miroslav Kubelik
 * @license http://opensource.org/licenses/gpl-license.php GNU GPL
 */
class ErrorController extends Zend_Controller_Action
{
    /**
     * main MVC error handler
     * @return void
     */
    public function errorAction()
    {
        $errors = $this->_getParam('error_handler');
        switch ($errors->type) {
        case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
        case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
            //404 error -- controller or action not found
            $this->getResponse()->setRawHeader('HTTP/1.1 404 Not Found');
            $this->view->errorType=404;
            $this->view->pageTitle=$this->view->trans("Nonexistent page");
            break;
        default:
            //application error; display error page, but don't change
            //status code
            $this->view->pageTitle=$this->view->trans("Application error");
            $this->view->errorType=505;
            // Log the exception:
            $exception = $errors->exception;
            error_log("Application error: " . $exception->getMessage(). " "
                . $exception->getTraceAsString(),0);
            break;
        }

        //Clear previous content
        $this->getResponse()->clearBody();
    }

}
