<commit_before><?php
/**
 * KumbiaPHP web & app Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://wiki.kumbiaphp.com/Licencia
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to <EMAIL> so we can send you a copy immediately.
 *
 * @category   Kumbia
 * @package    Core
 * @copyright  Copyright (c) 2005-2015 Kumbia Team (http://www.kumbiaphp.com)
 * @license    http://wiki.kumbiaphp.com/Licencia     New BSD License
 */

/**
 * Clase principal para el manejo de excepciones
 *
 * @category   Kumbia
 * @package    Core
 */
class KumbiaException extends Exception
{

    /**
     * View de error de la Excepción
     *
     * @var string
     */
    protected $_view;
    
    /**
     * Error 404 para los siguientes views
     *
     * @var array
     */
    protected static $view404 = array('no_controller', 'no_action', 'num_params');

    /**
     * Path del template de exception
     *
     * @var string
     */
    protected $template = 'views/templates/exception.phtml';
    
    /**
     * Constructor de la clase;
     *
     * @param string $message mensaje
     * @param string $view vista que se mostrara
     */
    public function __construct($message, $view = 'exception')
    {
        $this->_view = $view;
        parent::__construct($message);
    }

    /**
     * Maneja las excepciones no capturadas
     *
     * @param Exception $e
     * */
    public static function handleException($e)
    {
        self::setHeader($e);
        extract(Router::get(), EXTR_OVERWRITE);

        $Controller = Util::camelcase($controller);
        ob_start();
        if (PRODUCTION) { //TODO: añadir error 500.phtml
            include APP_PATH . 'views/_shared/errors/404.phtml';
            return;
        }

        include CORE_PATH . "views/errors/{$e->_view}.phtml";
 
        $content = ob_get_clean();

        // termina los buffers abiertos
        while (ob_get_level ()) {
            ob_end_clean();
        }

        include CORE_PATH . $e->template;
    }

    /**
     * Añade la cabezera de error http
     * */
    private static function setHeader($e)
    {
        if (isset($e->_view) && in_array($e->_view, self::$view404)){
            header('HTTP/1.1 404 Not Found');
        } else {
            header('HTTP/1.1 500 Internal Server Error');
        } //TODO: mover a los views
    }
}<commit_msg>Some Exception don't have $_view or $template param This change adds default values for them<commit_after><?php
/**
 * KumbiaPHP web & app Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://wiki.kumbiaphp.com/Licencia
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to <EMAIL> so we can send you a copy immediately.
 *
 * @category   Kumbia
 * @package    Core
 * @copyright  Copyright (c) 2005-2015 Kumbia Team (http://www.kumbiaphp.com)
 * @license    http://wiki.kumbiaphp.com/Licencia     New BSD License
 */

/**
 * Clase principal para el manejo de excepciones
 *
 * @category   Kumbia
 * @package    Core
 */
class KumbiaException extends Exception
{

    /**
     * View de error de la Excepción
     *
     * @var string
     */
    protected $_view;
    
    /**
     * Error 404 para los siguientes views
     *
     * @var array
     */
    protected static $view404 = array('no_controller', 'no_action', 'num_params');

    /**
     * Path del template de exception
     *
     * @var string
     */
    protected $template = 'views/templates/exception.phtml';
    
    /**
     * Constructor de la clase;
     *
     * @param string $message mensaje
     * @param string $view vista que se mostrara
     */
    public function __construct($message, $view = 'exception')
    {
        $this->_view = $view;
        parent::__construct($message);
    }

    /**
     * Maneja las excepciones no capturadas
     *
     * @param Exception $e
     * */
    public static function handleException($e)
    {
        self::setHeader($e);
        extract(Router::get(), EXTR_OVERWRITE);

        $Controller = Util::camelcase($controller);
        ob_start();
        if (PRODUCTION) { //TODO: añadir error 500.phtml
            include APP_PATH . 'views/_shared/errors/404.phtml';
            return;
        }
        $view = isset($e->_view) ? $e->_view : 'exception';
        include CORE_PATH . "views/errors/{$view}.phtml";
 
        $content = ob_get_clean();

        // termina los buffers abiertos
        while (ob_get_level ()) {
            ob_end_clean();
        }
        /*No todas las exceptiones tienen la propiedad "template"
        * TODO: siempre debe ir el CORE_PATH?
        */
        $tpl = isset($e->template) ? $e->template : 'views/templates/exception.phtml';
        include CORE_PATH . $tpl;
    }

    /**
     * Añade la cabezera de error http
     * */
    private static function setHeader($e)
    {
        if (isset($e->_view) && in_array($e->_view, self::$view404)){
            header('HTTP/1.1 404 Not Found');
        } else {
            header('HTTP/1.1 500 Internal Server Error');
        } //TODO: mover a los views
    }
}
{'fraction_non_alphanumeric': 0.11808452748050063, 'fraction_numerical': 0.011971703246871033, 'mean_word_length': 2.1762672811059907, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7368967', 'n_tokens_mistral': 1742, 'n_tokens_neox': 1666, 'n_words': 496}