<commit_before><?php
/**
 * Created by PhpStorm.
 * User: luoxiaojun
 * Date: 15/11/6
 * Time: 上午11:26
 * Lb framework base bootstrap file
 */

namespace lb;

use lb\components\Request;
use lb\components\Route;
use lb\components\containers\Config;

class BaseLb
{
    protected static $app;

    public $config = []; // App Configuration
    protected $is_single = false;
    protected $route_info = [];

    public function __construct($is_single = false)
    {
        if ($is_single) {
            $this->is_single = $is_single;
        } else {
            // Init Config
            if (defined('CONFIG_FILE') && file_exists(CONFIG_FILE)) {
                $this->config = include(CONFIG_FILE);
            }

            // Route
            $this->route_info = Route::getInfo();

            // Auto Load
            spl_autoload_register(['self', 'autoload'], true, false);

            // Container Register
            // Set Configuration
            $config_container = Config::component();
            foreach ($this->config as $config_name => $config_content) {
                $config_container->set($config_name, $config_content);
            }
            $this->config = [];
        }
    }

    // Singleton App
    public static function app()
    {
        if (self::$app instanceof self) {
            return self::$app;
        } else {
            return (self::$app = new self(true));
        }
    }

    // Get App Root Directory
    public function getRootDir()
    {
        return Config::component()->get('root_dir');
    }

    // Get Client IP Address
    public function getClientAddress()
    {
        return Request::getClientAddress();
    }

    // Get Host
    public function getHost()
    {
        return Request::getHost();
    }

    // Get Request URI
    public function getUri()
    {
        return Request::getUri();
    }

    // Ger Host IP Address
    public function getHostAddress()
    {
        return Request::getHostAddress();
    }

    // Get User Agent
    public function getUserAgent()
    {
        return Request::getUserAgent();
    }

    // Get App Name
    public function getName()
    {
        return Config::component()->get('name');
    }

    // Autoloader
    protected static function autoload($className)
    {
        $root_dir = Lb::app()->getRootDir();
        if ($root_dir) {
            // Auto Load Controllers
            if (strpos($className, 'app\controllers\\') === 0) {
                $controllers_dir = $root_dir . DIRECTORY_SEPARATOR . 'controllers';
                if (is_dir($controllers_dir)) {
                    $class_file_path = $controllers_dir . DIRECTORY_SEPARATOR . str_replace('app\controllers\\', '', $className) . 'Controller.php';
                    if (file_exists($class_file_path)) {
                        include_once($class_file_path);
                    }
                }
            }

            // Auto Load Models
            if (strpos($className, 'app\models\\') === 0) {
                $models_dir = $root_dir . DIRECTORY_SEPARATOR . 'models';
                if (is_dir($models_dir)) {
                    $class_file_path = $models_dir . DIRECTORY_SEPARATOR . str_replace('app\models\\', '', $className) . '.php';
                    if (file_exists($class_file_path)) {
                        include_once($class_file_path);
                    }
                }
            }

            // Auto Load Components
            if (strpos($className, 'app\components\\') === 0) {
                $components_dir = $root_dir . DIRECTORY_SEPARATOR . 'components';
                if (is_dir($components_dir)) {
                    $class_file_path = $components_dir . DIRECTORY_SEPARATOR . str_replace('app\components\\', '', $className) . '.php';
                    if (file_exists($class_file_path)) {
                        include_once($class_file_path);
                    }
                }
            }
        }
    }

    // Stop App
    public function stop()
    {
        die();
    }

    // Start App
    public function run()
    {
        if (!$this->is_single) {
            if ($this->route_info['controller'] && $this->route_info['action']) {
                Route::redirect($this->route_info);
            }
        }
    }
}
<commit_msg>error<commit_after><?php
/**
 * Created by PhpStorm.
 * User: luoxiaojun
 * Date: 15/11/6
 * Time: 上午11:26
 * Lb framework base bootstrap file
 */

namespace lb;

use lb\components\Request;
use lb\components\Route;
use lb\components\containers\Config;

class BaseLb
{
    protected static $app;

    public $config = []; // App Configuration
    protected $is_single = false;
    protected $route_info = [];

    public function __construct($is_single = false)
    {
        if ($is_single) {
            $this->is_single = $is_single;
        } else {
            // Init
            $this->init();

            // Init Config
            if (defined('CONFIG_FILE') && file_exists(CONFIG_FILE)) {
                $this->config = include(CONFIG_FILE);
            }

            // Route
            $this->route_info = Route::getInfo();

            // Auto Load
            spl_autoload_register(['self', 'autoload'], true, false);

            // Container Register
            // Set Configuration
            $config_container = Config::component();
            foreach ($this->config as $config_name => $config_content) {
                $config_container->set($config_name, $config_content);
            }
            $this->config = [];
        }
    }

    // Singleton App
    public static function app()
    {
        if (self::$app instanceof self) {
            return self::$app;
        } else {
            return (self::$app = new self(true));
        }
    }

    // Get App Root Directory
    public function getRootDir()
    {
        return Config::component()->get('root_dir');
    }

    // Get Client IP Address
    public function getClientAddress()
    {
        return Request::getClientAddress();
    }

    // Get Host
    public function getHost()
    {
        return Request::getHost();
    }

    // Get Request URI
    public function getUri()
    {
        return Request::getUri();
    }

    // Ger Host IP Address
    public function getHostAddress()
    {
        return Request::getHostAddress();
    }

    // Get User Agent
    public function getUserAgent()
    {
        return Request::getUserAgent();
    }

    // Get App Name
    public function getName()
    {
        return Config::component()->get('name');
    }

    // Autoloader
    protected static function autoload($className)
    {
        $root_dir = Lb::app()->getRootDir();
        if ($root_dir) {
            // Auto Load Controllers
            if (strpos($className, 'app\controllers\\') === 0) {
                $controllers_dir = $root_dir . DIRECTORY_SEPARATOR . 'controllers';
                if (is_dir($controllers_dir)) {
                    $class_file_path = $controllers_dir . DIRECTORY_SEPARATOR . str_replace('app\controllers\\', '', $className) . 'Controller.php';
                    if (file_exists($class_file_path)) {
                        include_once($class_file_path);
                    }
                }
            }

            // Auto Load Models
            if (strpos($className, 'app\models\\') === 0) {
                $models_dir = $root_dir . DIRECTORY_SEPARATOR . 'models';
                if (is_dir($models_dir)) {
                    $class_file_path = $models_dir . DIRECTORY_SEPARATOR . str_replace('app\models\\', '', $className) . '.php';
                    if (file_exists($class_file_path)) {
                        include_once($class_file_path);
                    }
                }
            }

            // Auto Load Components
            if (strpos($className, 'app\components\\') === 0) {
                $components_dir = $root_dir . DIRECTORY_SEPARATOR . 'components';
                if (is_dir($components_dir)) {
                    $class_file_path = $components_dir . DIRECTORY_SEPARATOR . str_replace('app\components\\', '', $className) . '.php';
                    if (file_exists($class_file_path)) {
                        include_once($class_file_path);
                    }
                }
            }
        }
    }

    // Stop App
    public function stop()
    {
        die();
    }

    // Init
    public function init()
    {
        if (defined('LB_ENV') && strtolower(LB_ENV) == 'production') {
            //报告运行时错误
            error_reporting(E_ERROR | E_WARNING | E_PARSE);
        }
    }

    // Start App
    public function run()
    {
        if (!$this->is_single) {
            if ($this->route_info['controller'] && $this->route_info['action']) {
                Route::redirect($this->route_info);
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.12710428200203366, 'fraction_numerical': 0.002711558016043385, 'mean_word_length': 1.626706231454006, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 32, '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': '588037', 'n_tokens_mistral': 2527, 'n_tokens_neox': 2420, 'n_words': 500}