扫描目录中的特定文件

时间:2016-12-11 05:21:54

标签: php function class web

如何在不指定特定路径的情况下扫描目录中的特定文件?

我需要它为spl_autoload_register,所以我不需要指定我的所有文件夹。

我需要指定所有3个路径,以便该函数将搜索那些给定路径" server_global_script_path"," server_login_script_path"和" server_plugin_script_path"。但我想要的是函数只搜索我的所有目录来搜索脚本吗?

示例:

spl_autoload_register( function ( $class_name ) {
    $configurations            = $GLOBALS[ 'configurations' ];

    $root_path                 = $configurations[ 'root_path' ];
    $server_global_script_path = $configurations[ 'server_global_script_path' ];
    $server_login_script_path  = $configurations[ 'server_login_script_path' ];
    $server_plugin_path        = $configurations[ 'server_plugin_path' ];

    $class_files[]             = "{$root_path}{$server_global_script_path}{$class_name}.php";
    $class_files[]             = "{$root_path}{$server_login_script_path}{$class_name}.php";
    $class_files[]             = "{$root_path}{$server_plugin_path}{$class_name}.php";
    $class_file_included       = false;

    foreach ( $class_files as $class_file ) {
        if ( file_exists( $class_file ) ) {
            if ( require_once( $class_file ) ) {
                $class_file_included = true;
            }
        }
    }

    if ( $class_file_included == false ) {
        shutdown_application();
    }
} );

0 个答案:

没有答案