• 一个php类 Autoloader


    php autoloader:

    This is a class for PHP that keeps the user from having to manually include classes by automatically including them on-the-fly as needed.

    This simple autoloader class is easy-to-use and features caching so it does not have to scan the file system for a given class more than once (unless the file is moved).

    Installation

    Simply include the class and configure it in your top-level/application config:

    <?php
    require(APP_PATH . 'classes/Autoloader.class.php');
    Autoloader::setCacheFilePath(APP_PATH . 'tmp/class_path_cache.txt');
    Autoloader::excludeFolderNamesMatchingRegex('/^CVS|..*$/');
    Autoloader::setClassPaths(array(
        APP_PATH . 'classes/',
        APP_PATH . 'models/'
    ));
    spl_autoload_register(array('Autoloader', 'loadClass'));

    The above example assumes there is an APP_PATH constant that points to the root of the application where you might have a classes and tmp directory, among other things.

    How It Works

    It scans all paths recursively, in the order in which they were given until the class is found. The class is loaded, and the path to the class is saved to the cache file. Next time the class ised, the process starts over for needed, its path is pulled directly from the cache file. If the class was moved or the cache file was remov that class.

    By default, it looks for files with exact name as the class with the suffix .class.php. For example, ifMyClassName is requested, it looks for MyClassName.class.php. The suffix can be changed by callingsetClassFileSuffix():

    Autoloader::setClassFileSuffix('-my_suffix.php');
    

     

  • 相关阅读:
    cf Round #764(Div. 3)
    查看w3wp.exe 进程
    CAML语法 Query写法
    InfoPaht 复选框
    性能工具MiniProfiler在Asp.Net WebForm跟踪EntityFramework
    CAML基础语法
    Moss 本机无法访问(转)
    STSADM 不是内部或外部命令
    spBodyOnLoadFunctionNames
    关于代码调用SSP获取UserProfile出错的解决方案(转)
  • 原文地址:https://www.cnblogs.com/youxin/p/3949457.html
Copyright © 2020-2023  润新知