<commit_before><?php

//error_reporting(E_ALL);
//ini_set('display_errors', 1);

class Yaoi {
    const MODE_CLI = 'cli';
    const MODE_HTTP = 'http';

    public $host;
    public $path;
    public $mode;

    public $logPath = 'logs/';
    public $logErrors = true;

    /**
     * @var Yaoi_Conf
     */
    protected $conf;

    public static function init($conf = null) {
        self::$instance = new static;
        self::$instance->conf = $conf;

        if ($conf instanceof Closure) {
            $conf = $conf();
        }

        if (null === $conf) {
            $conf = new Yaoi_Conf();
        }
        elseif (!$conf instanceof Yaoi_Conf) {
            throw new Exception('Yaoi_Conf or null required');
        }

        $conf->register();

        // TODO properly detect CLI mode and show "Usage" message by default
        if (isset($_SERVER['HTTP_HOST']) && isset($_SERVER['REQUEST_URI'])) {
            self::$instance->path = $_SERVER['REQUEST_URI'];
            self::$instance->host = $_SERVER['HTTP_HOST'];
            self::$instance->mode = self::MODE_HTTP;
        }
        elseif (isset($_SERVER['argv'][1])) {
            self::$instance->path = $_SERVER['argv'][1];
            if (isset($_SERVER['argv'][2])) {
                self::$instance->host = $_SERVER['argv'][2];
            }
            self::$instance->mode = self::MODE_CLI;
        }

        return self::$instance;
    }


    function route($path = null, $host = null) {
        throw new Exception('No routes');
    }


    protected static $instance;

    /**
     * @return static
     * @throws Exception
     */
    static function instance() {
        if (is_null(self::$instance)) {
            throw new Exception('Application is not initialized');
        }

        return self::$instance;
    }


    private static $resources = array();

    /**
     * @param string $id
     * @return Database
     */
    static function db($id = 'default') {
        return Database::getInstance($id);
    }

    static function cache($id = 'default') {
        return Storage::getInstance($id);
    }

    /**
     * @param string $id
     * @return Date_Source
     */
    static function time($id = 'default') {
        $resource = &self::$resources['time_' . $id];
        if (!isset($resource)) {
            $resource = new Date_Source();
        }
        return $resource;
    }


    /**
     * @param string $id
     * @return Log
     */
    static function log($id = 'default') {
        return Log::getInstance($id);
    }

}

class Yaoi_Conf {
    public $modulesPath;
    public $yaoiPath;
    public $librariesPath;
    public $errorLogPath;


    public function register() {
        if (null === $this->modulesPath) {
            $this->modulesPath = __DIR__ . '\..\..\modules';
        }

        if (null === $this->yaoiPath) {
            $this->yaoiPath = __DIR__;
        }

        $includePath = get_include_path()
            . PATH_SEPARATOR . $this->modulesPath
            . PATH_SEPARATOR . $this->yaoiPath;

        if ($this->librariesPath) {
            $includePath .= PATH_SEPARATOR . $this->librariesPath;
        }

        set_include_path($includePath);

        spl_autoload_register(function($class){
            $path = explode('_', $class);
            $path2 = ($path ? implode('/', $path) . '/' : '') . $class . '.php';<commit_msg>default bootstrapping<commit_after><?php

//error_reporting(E_ALL);
//ini_set('display_errors', 1);

class Yaoi {
    const MODE_CLI = 'cli';
    const MODE_HTTP = 'http';

    public $host;
    public $path;
    public $mode;

    public $logPath = 'logs/';
    public $logErrors = true;

    /**
     * @var Yaoi_Conf
     */
    protected $conf;

    public static function init($conf = null) {
        self::$instance = new static;
        self::$instance->conf = $conf;

        if ($conf instanceof Closure) {
            $conf = $conf();
        }

        if (null === $conf) {
            $conf = new Yaoi_Conf();
        }
        elseif (!$conf instanceof Yaoi_Conf) {
            throw new Exception('Yaoi_Conf or null required');
        }

        $conf->register();

        // TODO properly detect CLI mode and show "Usage" message by default
        if (isset($_SERVER['HTTP_HOST']) && isset($_SERVER['REQUEST_URI'])) {
            self::$instance->path = $_SERVER['REQUEST_URI'];
            self::$instance->host = $_SERVER['HTTP_HOST'];
            self::$instance->mode = self::MODE_HTTP;
        }
        elseif (isset($_SERVER['argv'][1])) {
            self::$instance->path = $_SERVER['argv'][1];
            if (isset($_SERVER['argv'][2])) {
                self::$instance->host = $_SERVER['argv'][2];
            }
            self::$instance->mode = self::MODE_CLI;
        }

        return self::$instance;
    }


    function route($path = null, $host = null) {
        throw new Exception('No routes');
    }


    protected static $instance;

    /**
     * @return static
     * @throws Exception
     */
    static function instance() {
        if (is_null(self::$instance)) {
            throw new Exception('Application is not initialized');
        }

        return self::$instance;
    }


    private static $resources = array();

    /**
     * @param string $id
     * @return Database
     */
    static function db($id = 'default') {
        return Database::getInstance($id);
    }

    static function cache($id = 'default') {
        return Storage::getInstance($id);
    }

    /**
     * @param string $id
     * @return Date_Source
     */
    static function time($id = 'default') {
        $resource = &self::$resources['time_' . $id];
        if (!isset($resource)) {
            $resource = new Date_Source();
        }
        return $resource;
    }


    /**
     * @param string $id
     * @return Log
     */
    static function log($id = 'default') {
        return Log::getInstance($id);
    }

}

class Yaoi_Conf {
    public $modulesPath;
    public $yaoiPath;
    public $librariesPath;
    public $errorLogPath;


    public function register() {
        if (null === $this->modulesPath) {
            $this->modulesPath = __DIR__ . '/../../modules';
        }

        if (null === $this->yaoiPath) {
            $this->yaoiPath = __DIR__;
        }

        $includePath = get_include_path()
            . PATH_SEPARATOR . $this->modulesPath
            . PATH_SEPARATOR . $this->yaoiPath;

        if ($this->librariesPath) {
            $includePath .= PATH_SEPARATOR . $this->librariesPath;
        }

        set_include_path($includePath);

        spl_autoload_register(function($class){
            $path = explode('_', $class);
            $path2 = ($path ? implode('/', $path) . '/' : '') . $class . '.php';
{'fraction_non_alphanumeric': 0.15459651197162283, 'fraction_numerical': 0.0017735737511084836, 'mean_word_length': 1.9576048951048952, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, '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': '5064085', 'n_tokens_mistral': 1993, 'n_tokens_neox': 1967, 'n_words': 438}