Very Light Weight Frame work "Typon" Ver20200629 | TheoryOfContraints official blog

Very Light Weight Frame work "Typon" Ver20200629

とりあえず、今の状況。本体のみ

 

-------

<?php
    /**
     * Very light framework is the "Typon".
     * Ver.20200629.
     * @author kubohisa at pdbrec.com.
     */
    
    // Requires.
    require_once('../lib/typon/stdio.phl');
    require_once('../lib/typon/setting.phl');
    require_once('../lib/smarty/Smarty.class.php'); // Smarty3.
    
    /**
     * Start Typoon IPL.
     */

    // null.
    function sanitizer($arr) {
        if (is_array($arr) ){
            return array_map('sanitizer', $arr);    
        }
        return str_replace("\0", "", $arr);
    }
    $_POST = sanitizer($_POST);
    $_COOKIE = sanitizer($_COOKIE);
    $_SERVER = sanitizer($_SERVER);
    $_GET = array(); // Delete gets.
    
    // Domain check.
    if ($_SERVER['SERVER_NAME'] != Ty\TyponReg::$DomeinName) {
        Ty\STDIO::ErrorCode(500);
        exit;        
    }
    
    // Https check.
    // テスト環境ではhttpなので外してます
/*    if (empty($_SERVER['HTTPS'])) {
        Ty\STDIO::ErrorCode(500);
        exit;        
    }
*/
    // Longer Url Check.
    if (strlen($_SERVER["REQUEST_URI"]) > 1000) {
        Ty\STDIO::ErrorCode(500);
        exit;        
    }
    
    // md Setting.
    mb_language("Japanese");
    mb_internal_encoding("UTF-8");
    
    // セッションIDリセット
    session_name(Ty\TyponReg::$SessionName);
    session_start();
    session_regenerate_id(true);
    
    // Get Get.
    $UrlGet = preg_split("/\//", $_SERVER["REQUEST_URI"]);
    array_shift($UrlGet);
    
    // Trim Get.
    foreach ($UrlGet as $key => $value){
        $UrlGet[$key] = Ty\Strings::Trim($value);
    }
    
    // ヘルスチェック(仮)
    if ($UrlGet['0'] == "health") {
        echo("Clean.");
        exit;
    }
    
    // adtionがあるか?
    if ($UrlGet['0'] == "" || $UrlGet['0'] == "index") {
        $UrlGet['0'] = "index";
    }
    $ExecName = array_shift($UrlGet);

    if (! preg_match('/\A[a-zA-Z0-9\-\_]++\z/i', $ExecName)) {
        Ty\STDIO::ErrorCode(505);
        exit;
    }
    
    $Statename = "";
    if (! empty($_POST['state'])) {
        $_POST['state'] = Ty\Strings::Trim($_POST['state']);
        
        if (! preg_match('/\A[a-zA-Z0-9\-\_]++\z/i', $_POST['state'])) {
            Ty\STDIO::ErrorCode(505);
            exit;
        }
        
        $Statename = $_POST['state'];
    } else {
        $Statename = "index";
    }
    
    $PresentName = "../scripts/".$ExecName."/".$Statename.".action";
    
    if (! file_exists($PresentName)) {
        Ty\STDIO::ErrorCode(505);
        exit;
    }
    
    // responseがあるか?
    $ResponceName = "../scripts/".$ExecName."/".$Statename.".responce";
    if (! file_exists($ResponceName)) {
        $ResponceName = "";
    }
    
    // Seting Smarty.
    $smarty = new Smarty();
    $smarty->loadFilter('variable', 'htmlspecialchars');
    $smarty->template_dir = '../html';
    $smarty->compile_dir  = '../lib/templates_c';

    // 実行
    require_once($PresentName);
    
    if ($ResponceName != "") {
        require_once($ResponceName);
    }
    
    exit;