<commit_before><?php
/**
 * Koowa Framework - http://developer.joomlatools.com/koowa
 *
 * @copyright	Copyright (C) 2007 - 2013 <NAME> and Timble CVBA. (http://www.timble.net)
 * @license		GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link		http://github.com/joomlatools/koowa for the canonical source repository
 */

/**
 * Exception Event Dispatcher
 *
 * @author  <NAME> <https://github.com/johanjanssens>
 * @package Koowa\Library\Exception
 */
class KEventDispatcherException extends KEventDispatcherAbstract
{
    /**
     * Error levels
     */
    const SYSTEM      = null;
    const DEVELOPMENT = -1; //E_ALL   | E_STRICT  | ~E_DEPRECATED
    const PRODUCTION  = 7;  //E_ERROR | E_WARNING | E_PARSE

    /**
     * The error level.
     *
     * @var int
     */
    protected $_error_level;

    /**
     * Constructor.
     *
     * @param KObjectConfig $config  An optional ObjectConfig object with configuration options
     */
    public function __construct(KObjectConfig $config)
    {
        parent::__construct($config);

        //Set the error level
        $this->setErrorLevel($config->error_level);

        if($config->catch_exceptions) {
            $this->catchExceptions();
        }

        if($config->catch_user_errors) {
            $this->catchUserErrors();
        }

        if($config->catch_fatal_errors) {
            $this->catchFatalErrors();
        }
    }

    /**
     * Initializes the default configuration for the object
     *
     * Called from {@link __construct()} as a first step of object instantiation.
     *
     * @param  KObjectConfig $config An optional ObjectConfig object with configuration options.
     * @return void
     */
    protected function _initialize(KObjectConfig $config)
    {
        $config->append(array(
            'catch_exceptions'   => true,
            'catch_user_errors'  => false,
            'catch_fatal_errors' => false,
            'error_level'        => self::SYSTEM,
        ));

        parent::_initialize($config);
    }

    /**
     * Dispatches an exception by dispatching arguments to all listeners that handle the event.
     *
     * Function will avoid a recursive loop when an exception is thrown during even dispatching and output a generic
     * exception instead.
     *
     * @link    http://www.php.net/manual/en/function.set-exception-handler.php#88082
     * @param   object|array   $event An array, a KObjectConfig or a KEventException object
     * @return  KEventException
     */
    public function dispatchException($event = array())
    {
        try
        {
            if (!$event instanceof KEventException) {
                $event = new KEventException($event);
            }<commit_msg>re #91 : Added ERROR_ prefix to error constants.<commit_after><?php
/**
 * Koowa Framework - http://developer.joomlatools.com/koowa
 *
 * @copyright	Copyright (C) 2007 - 2013 <NAME> and Timble CVBA. (http://www.timble.net)
 * @license		GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link		http://github.com/joomlatools/koowa for the canonical source repository
 */

/**
 * Exception Event Dispatcher
 *
 * @author  <NAME> <https://github.com/johanjanssens>
 * @package Koowa\Library\Exception
 */
class KEventDispatcherException extends KEventDispatcherAbstract
{
    /**
     * Error levels
     */
    const ERROR_SYSTEM       = null;
    const ERROR_DEVELOPMENT  = -1; //E_ALL   | E_STRICT  | ~E_DEPRECATED
    const ERROR_PRODUCTION   = 7;  //E_ERROR | E_WARNING | E_PARSE

    /**
     * The error level.
     *
     * @var int
     */
    protected $_error_level;

    /**
     * Constructor.
     *
     * @param KObjectConfig $config  An optional ObjectConfig object with configuration options
     */
    public function __construct(KObjectConfig $config)
    {
        parent::__construct($config);

        //Set the error level
        $this->setErrorLevel($config->error_level);

        if($config->catch_exceptions) {
            $this->catchExceptions();
        }

        if($config->catch_user_errors) {
            $this->catchUserErrors();
        }

        if($config->catch_fatal_errors) {
            $this->catchFatalErrors();
        }
    }

    /**
     * Initializes the default configuration for the object
     *
     * Called from {@link __construct()} as a first step of object instantiation.
     *
     * @param  KObjectConfig $config An optional ObjectConfig object with configuration options.
     * @return void
     */
    protected function _initialize(KObjectConfig $config)
    {
        $config->append(array(
            'catch_exceptions'   => true,
            'catch_user_errors'  => false,
            'catch_fatal_errors' => false,
            'error_level'        => self::ERROR_SYSTEM,
        ));

        parent::_initialize($config);
    }

    /**
     * Dispatches an exception by dispatching arguments to all listeners that handle the event.
     *
     * Function will avoid a recursive loop when an exception is thrown during even dispatching and output a generic
     * exception instead.
     *
     * @link    http://www.php.net/manual/en/function.set-exception-handler.php#88082
     * @param   object|array   $event An array, a KObjectConfig or a KEventException object
     * @return  KEventException
     */
    public function dispatchException($event = array())
    {
        try
        {
            if (!$event instanceof KEventException) {
                $event = new KEventException($event);
            }
{'fraction_non_alphanumeric': 0.10907441016333938, 'fraction_numerical': 0.006170598911070781, 'mean_word_length': 2.2901492537313435, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 37, 'https://': 2, 'lorem ipsum': 0, 'www.': 6, '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': '1461400', 'n_tokens_mistral': 1617, 'n_tokens_neox': 1544, 'n_words': 391}