<commit_before><?php
/**
 * @var global loadpath and classpath
 */
global $_LOADPATH,$_CLASSPATH;

/**
 * default loadpath and classpath
 */
$_LOADPATH = $_CLASSPATH = str_replace("\\", "/", __DIR__);

/**
 * Layload autoload class
 * 加载优先级：类全名映射->命名空间文件夹查找->纯类名映射->正则匹配前缀类全名映射查找->正则匹配文件夹顺序查找
 * @author <NAME>
 */
final class Layload {
    /**
     * @staticvar debug
     */
    public static $debug = false;
    /**
     * @staticvar all class mappings
     */
    public static $classes = array('_prefixes'=>array());
    
    /**
     * initialize autoload function
     * @return void
     */
    public static function initialize($debug = false) {
        spl_autoload_register('Layload::autoload');
        Layload::$debug = $debug;
    }
    
    /**
     * set class path
     * @param $classpath class directory path,default is empty
     * @return void
     */
    public static function classpath($classpath = '') {
        global $_CLASSPATH;
        $_CLASSPATH = str_replace("\\", "/", is_dir($classpath)?$classpath:$_CLASSPATH);
    }
    /**
     * set load path
     * @param $loadpath class mapping config load directory path,default is empty
     * @return void
     */
    public static function loadpath($loadpath = '') {
        global $_LOADPATH;
        $_LOADPATH = str_replace("\\", "/", is_dir($loadpath)?$loadpath:$_LOADPATH);
    }
    
    /**
     * class autoload function
     * @param $classname autoload class name
     * @return void
     */
    public static function autoload($classname) {
        global $_CLASSPATH;
        $classes = &Layload::$classes;
        $prefixes = &Layload::$classes['_prefixes'];
        $suffixes = array('.php','.class.php','.inc');
        if(array_key_exists($classname, $classes)) {//全名映射
            if(is_file($classes[$classname])) {
                if(Layload::$debug) echo 'require_once '.$classes[$classname].'<br>';
                require_once $classes[$classname];
            } else if(is_file($_CLASSPATH.$classes[$classname])) {
                if(Layload::$debug) echo 'require_once '.$_CLASSPATH.$classes[$classname].'<br>';
                require_once $_CLASSPATH.$classes[$classname];
            } else {
                //TODO mapping is error
            }
        } else {
            $tmparr = explode("\\",$classname);
            if(count($tmparr) > 1) {//if is namespace
                $name = array_pop($tmparr);
                $path = $_CLASSPATH.'/'.implode('/', $tmparr);
                $required = false;
                //命名空间文件夹查找
                if(is_dir($path)) {
                    $tmppath = $path.'/'.$name;
                    foreach($suffixes as $i=>$suffix) {
                        if(is_file($tmppath.$suffix)) {
                            if(Layload::$debug) echo 'require_once '.$tmppath.$suffix.'<br>';
                            require_once $tmppath.$suffix;
                            $required = true;
                            break;
                        }
                    }
                /*}
                //纯类名映射
                if(!$unrequired && array_key_exists($name,$classes)) {
                    if(is_file($classes[$name])) {
                        if(Layload::$debug) echo 'require_once '.$classes[$name].'<br>';
                        require_once $classes[$name];
                    } else if(is_file($_CLASSPATH.$classes[$name])) {
                        if(Layload::$debug) echo 'require_once '.$_CLASSPATH.$classes[$name].'<br>';
                        require_once $_CLASSPATH.$classes[$name];
                    } else {
                        //TODO mapping is error
                    }*/
                } else {
                    //TODO not found by namespace dir or not found by class basename
                }
            } else if(preg_match_all('/([A-Z]{1,}[a-z0-9]{0,}|[a-z0-9]{1,})_{0,1}/', $classname, $matches) > 0) {
                //TODO autoload class by regular
                $tmparr = array_values($matches[1]);
                $prefix = array_shift($tmparr);
                //正则匹配前缀查找
                if(array_key_exists($prefix,$prefixes)) {
                    if(is_file($prefixes[$prefix][$classname])) {
                        if(Layload::$debug) echo 'require_once '.$prefixes[$prefix][$classname].'<br>';
                        require_once $prefixes[$prefix][$classname];
                    } else if(is_file($_CLASSPATH.$prefixes[$prefix][$classname])) {
                        if(Layload::$debug) echo 'require_once '.$_CLASSPATH.$prefixes[$prefix][$classname].'<br>';
                        require_once $_CLASSPATH.$prefixes[$prefix][$classname];
                    } else {
                        //TODO mapping is error by regular match
                    }
                } else {
                    $path = $_CLASSPATH;
                    foreach($matches[1] as $index=>$item) {
                        $path .= '/'.$item;
                        if(is_dir($path)) {//顺序文件夹查找
                            $tmppath = $path.'/'.substr($classname, strpos($classname, $item) + strlen($item));
                            echo $tmppath.'<br>';
                            foreach($suffixes as $i=>$suffix) {
                                if(is_file($tmppath.$suffix)) {
                                    if(Layload::$debug) echo 'require_once '.$tmppath.$suffix.'<br>';
                                    require_once $tmppath.$suffix;
                                    break 2;
                                }
                            }
                            continue;
                        } else if($index == count($matches[1]) - 1) {
                            foreach($suffixes as $i=>$suffix) {
                                if(is_file($path.$suffix)) {
                                    if(Layload::$debug) echo 'require_once '.$path.$suffix.'<br>';
                                    require_once $path.$suffix;
                                    break 2;
                                }
                            }
                            break;
                        } else {
                            //TODO not found by regular match
                        }
                    }<commit_msg>add class autoload by classname directly<commit_after><?php
/**
 * @var global loadpath and classpath
 */
global $_LOADPATH,$_CLASSPATH;

/**
 * default loadpath and classpath
 */
$_LOADPATH = $_CLASSPATH = str_replace("\\", "/", __DIR__);

/**
 * Layload autoload class
 * 加载优先级：类全名映射->命名空间文件夹查找->纯类名映射->正则匹配前缀类全名映射查找->正则匹配文件夹顺序查找
 * @author <NAME>
 */
final class Layload {
    /**
     * @staticvar debug
     */
    public static $debug = false;
    /**
     * @staticvar all class mappings
     */
    public static $classes = array('_prefixes'=>array());
    
    /**
     * initialize autoload function
     * @return void
     */
    public static function initialize($debug = false) {
        spl_autoload_register('Layload::autoload');
        Layload::$debug = $debug === true;
    }
    
    /**
     * set class path
     * @param $classpath class directory path,default is empty
     * @return void
     */
    public static function classpath($classpath = '') {
        global $_CLASSPATH;
        $_CLASSPATH = str_replace("\\", "/", is_dir($classpath)?$classpath:$_CLASSPATH);
    }
    /**
     * set load path
     * @param $loadpath class mapping config load directory path,default is empty
     * @return void
     */
    public static function loadpath($loadpath = '') {
        global $_LOADPATH;
        $_LOADPATH = str_replace("\\", "/", is_dir($loadpath)?$loadpath:$_LOADPATH);
    }
    
    /**
     * class autoload function
     * @param $classname autoload class name
     * @return void
     */
    public static function autoload($classname) {
        global $_CLASSPATH;
        $classes = &Layload::$classes;
        $prefixes = &Layload::$classes['_prefixes'];
        $suffixes = array('.php','.class.php','.inc');
        if(array_key_exists($classname, $classes)) {//全名映射
            if(is_file($classes[$classname])) {
                if(Layload::$debug) echo 'require_once '.$classes[$classname].'<br>';
                require_once $classes[$classname];
            } else if(is_file($_CLASSPATH.$classes[$classname])) {
                if(Layload::$debug) echo 'require_once '.$_CLASSPATH.$classes[$classname].'<br>';
                require_once $_CLASSPATH.$classes[$classname];
            } else {
                //TODO mapping is error
            }
        } else {
            $tmparr = explode("\\",$classname);
            if(count($tmparr) > 1) {//if is namespace
                $name = array_pop($tmparr);
                $path = $_CLASSPATH.'/'.implode('/', $tmparr);
                $required = false;
                //命名空间文件夹查找
                if(is_dir($path)) {
                    $tmppath = $path.'/'.$name;
                    foreach($suffixes as $i=>$suffix) {
                        if(is_file($tmppath.$suffix)) {
                            if(Layload::$debug) echo 'require_once '.$tmppath.$suffix.'<br>';
                            require_once $tmppath.$suffix;
                            $required = true;
                            break;
                        }
                    }
                /*}
                //纯类名映射
                if(!$unrequired && array_key_exists($name,$classes)) {
                    if(is_file($classes[$name])) {
                        if(Layload::$debug) echo 'require_once '.$classes[$name].'<br>';
                        require_once $classes[$name];
                    } else if(is_file($_CLASSPATH.$classes[$name])) {
                        if(Layload::$debug) echo 'require_once '.$_CLASSPATH.$classes[$name].'<br>';
                        require_once $_CLASSPATH.$classes[$name];
                    } else {
                        //TODO mapping is error
                    }*/
                } else {
                    //TODO not found by namespace dir or not found by class basename
                }
            } else if(preg_match_all('/([A-Z]{1,}[a-z0-9]{0,}|[a-z0-9]{1,})_{0,1}/', $classname, $matches) > 0) {
                //TODO autoload class by regular
                $tmparr = array_values($matches[1]);
                $prefix = array_shift($tmparr);
                //正则匹配前缀查找
                if(array_key_exists($prefix,$prefixes)) {
                    if(is_file($prefixes[$prefix][$classname])) {
                        if(Layload::$debug) echo 'require_once '.$prefixes[$prefix][$classname].'<br>';
                        require_once $prefixes[$prefix][$classname];
                    } else if(is_file($_CLASSPATH.$prefixes[$prefix][$classname])) {
                        if(Layload::$debug) echo 'require_once '.$_CLASSPATH.$prefixes[$prefix][$classname].'<br>';
                        require_once $_CLASSPATH.$prefixes[$prefix][$classname];
                    } else {
                        //TODO mapping is error by regular match
                    }
                } else {
                    $path = $_CLASSPATH;
                    //直接以类名作为文件名查找
                    foreach($suffixes as $i=>$suffix) {
                        $tmppath = $path.'/'.$classname;
                        if(is_file($tmppath.$suffix)) {
                            if(Layload::$debug) echo 'require_once '.$tmppath.$suffix.'<br>';
                            require_once $tmppath.$suffix;
                        } else {
                            //TODO not found by classname directly
                        }
                    }
                    //如果以上没有匹配，则递归文件夹查找
                    if(!class_exists($classname) && !interface_exists($classname)) {
                        foreach($matches[1] as $index=>$item) {
                            $path .= '/'.$item;
                            if(is_dir($path)) {//顺序文件夹查找
                                $tmppath = $path.'/'.substr($classname, strpos($classname, $item) + strlen($item));
                                foreach($suffixes as $i=>$suffix) {
                                    if(is_file($tmppath.$suffix)) {
                                        if(Layload::$debug) echo 'require_once '.$tmppath.$suffix.'<br>';
                                        require_once $tmppath.$suffix;
                                        break 2;
                                    }
                                }
                                continue;
                            } else if($index == count($matches[1]) - 1) {
                                foreach($suffixes as $i=>$suffix) {
                                    if(is_file($path.$suffix)) {
                                        if(Layload::$debug) echo 'require_once '.$path.$suffix.'<br>';
                                        require_once $path.$suffix;
                                        break 2;
                                    }
                                }
                                break;
                            } else {
                                //TODO not found by regular recursive
                            }
                        }
                    }
                    if(!class_exists($classname) && !interface_exists($classname)) {
                        //TODO warning no class mapping by layload class autoload function
                    }
{'fraction_non_alphanumeric': 0.1354120267260579, 'fraction_numerical': 0.002524127691165553, 'mean_word_length': 1.3094462540716612, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1006276', 'n_tokens_mistral': 3745, 'n_tokens_neox': 3717, 'n_words': 645}