<commit_before><?php
/**
 * OmniApp Framework
 *
 * @package   OmniApp
 * @author    <NAME> <<EMAIL>>
 * @copyright (c) 2011 - 2012 OmniApp Framework
 */

namespace OmniApp;

const VERSION = '0.2';

/*********************
 * core app
 ********************/

/**
 * App Class
 */
class App
{
    /**
     * @var Config
     * @todo protect
     */
    public static $config = array();

    /**
     * @var array Modules for the app
     */
    public static $modules = array();

    /**
     * @var Middleware[]
     */
    private static $middleware = array();

    /**
     * @var float App start time
     */
    private static $start_time = null;

    /**
     * @var bool Initialized?
     */
    private static $_init = false;

    /**
     * App init
     *
     * @static
     * @param array $config
     */
    public static function init($config = array())
    {
        Event::fire('init');

        // Record start time
        self::$start_time = microtime(true);

        // Add default middleware
        self::$middleware = array(new Middleware\RunTime());

        // handle autoload and shutdown
        spl_autoload_register(array(__CLASS__, '__autoload'));
        register_shutdown_function(array(__CLASS__, '__shutdown'));

        // Force use UTF-8 encoding
        iconv_set_encoding("internal_encoding", "UTF-8");
        mb_internal_encoding('UTF-8');

        // configure timezone
        App::config('timezone', function ($value) {
            date_default_timezone_set($value);
        });

        // configure debug
        App::config('debug', function ($value) {
            if ($value == true) {
                App::add(new \OmniApp\Middleware\Debug());
            }
        });

        App::config($config);

        self::$_init = true;
    }

    /**
     * Check if cli
     *
     * @static
     * @return bool
     */
    public static function isCli()
    {
        return PHP_SAPI == 'cli';
    }

    /**
     * Check if windows, if not, it must be *unix
     *
     * @static
     * @return bool
     */
    public static function isWin()
    {
        static $is_win = null;
        if ($is_win === null) {
            $is_win = substr(PHP_OS, 0, 3) == 'WIN';
        }
        return $is_win;
    }

    /**
     * Get app start time
     *
     * @static
     * @return int
     */
    public static function startTime()
    {
        return self::$start_time;
    }

    /**
     * Get run time
     *
     * @return string
     */
    public static function runTime()
    {
        return number_format(microtime(true) - self::startTime(), 6);
    }

    /**
     * Is init?
     *
     * @static
     * @return bool
     */
    public static function isInit()
    {
        return self::$_init;
    }

    /**
     * Config get or set after init
     *
     * @param      $key
     * @param null $value
     * @param bool $detect_callback
     * @param bool $only_trigger
     * @return mixed
     */
    public static function config($key = null, $value = null, $detect_callback = true, $only_trigger = false)
    {
        if ($key == null && $value == null) {
            // If not arguments, return config
            return self::$config;
        } elseif ($value === null) {
            if (is_array($key) || $key instanceof Config) {
                // First set config
                $_first = false;

                // Set config first
                if (empty(self::$config)) {
                    $_first = true;
                    if ($key instanceof Config) {
                        self::$config = $key;
                    } else {
                        self::$config = new Config\Dict($key);
                    }
                }

                // Convert Config to array
                if ($key instanceof Config) {
                    $key = $key->getArrayCopy();
                }

                // Loop config
                foreach ($key as $k => $v) {
                    self::config($k, $v, false, $_first);
                }
            } else {
                // When get config
                return self::$config->get($key);
            }
        } else {
            if ($detect_callback && $value instanceof \Closure) {
                // Auto attach event
                Event::on('config:' . $key, function (Event $e) use ($value) {
                    $value($e->value, $e->previous);
                });
            } else {
                // Set event name
                $_e_name = 'config:' . $key;

                // Check if event has listener
                if (Event::hasListener($_e_name)) {
                    // Fire event when listener exists
                    Event::fire($_e_name, Event::instance($_e_name)->set(array(
                        'value'    => $value,
                        'previous' => self::$config->get($key)
                    )));
                }<commit_msg>Change config param detect_callback to no_detect_callback<commit_after><?php
/**
 * OmniApp Framework
 *
 * @package   OmniApp
 * @author    <NAME> <<EMAIL>>
 * @copyright (c) 2011 - 2012 OmniApp Framework
 */

namespace OmniApp;

const VERSION = '0.2';

/*********************
 * core app
 ********************/

/**
 * App Class
 */
class App
{
    /**
     * @var Config
     * @todo protect
     */
    public static $config = array();

    /**
     * @var array Modules for the app
     */
    public static $modules = array();

    /**
     * @var Middleware[]
     */
    private static $middleware = array();

    /**
     * @var float App start time
     */
    private static $start_time = null;

    /**
     * @var bool Initialized?
     */
    private static $_init = false;

    /**
     * App init
     *
     * @static
     * @param array $config
     */
    public static function init($config = array())
    {
        Event::fire('init');

        // Record start time
        self::$start_time = microtime(true);

        // Add default middleware
        self::$middleware = array(new Middleware\RunTime());

        // handle autoload and shutdown
        spl_autoload_register(array(__CLASS__, '__autoload'));
        register_shutdown_function(array(__CLASS__, '__shutdown'));

        // Force use UTF-8 encoding
        iconv_set_encoding("internal_encoding", "UTF-8");
        mb_internal_encoding('UTF-8');

        // configure timezone
        App::config('timezone', function ($value) {
            date_default_timezone_set($value);
        });

        // configure debug
        App::config('debug', function ($value) {
            if ($value == true) {
                App::add(new \OmniApp\Middleware\Debug());
            }
        });

        App::config($config);

        self::$_init = true;
    }

    /**
     * Check if cli
     *
     * @static
     * @return bool
     */
    public static function isCli()
    {
        return PHP_SAPI == 'cli';
    }

    /**
     * Check if windows, if not, it must be *unix
     *
     * @static
     * @return bool
     */
    public static function isWin()
    {
        static $is_win = null;
        if ($is_win === null) {
            $is_win = substr(PHP_OS, 0, 3) == 'WIN';
        }
        return $is_win;
    }

    /**
     * Get app start time
     *
     * @static
     * @return int
     */
    public static function startTime()
    {
        return self::$start_time;
    }

    /**
     * Get run time
     *
     * @return string
     */
    public static function runTime()
    {
        return number_format(microtime(true) - self::startTime(), 6);
    }

    /**
     * Is init?
     *
     * @static
     * @return bool
     */
    public static function isInit()
    {
        return self::$_init;
    }

    /**
     * Config get or set after init
     *
     * @param      $key
     * @param null $value
     * @param bool $no_detect_callback
     * @param bool $only_trigger
     * @return mixed
     */
    public static function config($key = null, $value = null, $no_detect_callback = false, $only_trigger = false)
    {
        if ($key == null && $value == null) {
            // If not arguments, return config
            return self::$config;
        } elseif ($value === null) {
            if (is_array($key) || $key instanceof Config) {
                // First set config
                $_first = false;

                // Set config first
                if (empty(self::$config)) {
                    $_first = true;
                    if ($key instanceof Config) {
                        self::$config = $key;
                    } else {
                        self::$config = new Config\Dict($key);
                    }
                }

                // Convert Config to array
                if ($key instanceof Config) {
                    $key = $key->getArrayCopy();
                }

                // Loop config
                foreach ($key as $k => $v) {
                    self::config($k, $v, false, $_first);
                }
            } else {
                // When get config
                return self::$config->get($key);
            }
        } else {
            if (!$no_detect_callback && $value instanceof \Closure) {
                // Auto attach event
                Event::on('config:' . $key, function (Event $e) use ($value) {
                    $value($e->value, $e->previous);
                });
            } else {
                // Set event name
                $_e_name = 'config:' . $key;

                // Check if event has listener
                if (Event::hasListener($_e_name)) {
                    // Fire event when listener exists
                    Event::fire($_e_name, Event::instance($_e_name)->set(array(
                        'value'    => $value,
                        'previous' => self::$config->get($key)
                    )));
                }
{'fraction_non_alphanumeric': 0.1380812481004964, 'fraction_numerical': 0.003241819471178199, 'mean_word_length': 1.393792434529583, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2535036', 'n_tokens_mistral': 2804, 'n_tokens_neox': 2673, 'n_words': 691}