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');

一个php类 Autoloader的更多相关文章

  1. PHP用单例模式实现一个数据库类

    使用单例模式的出发点: 1.php的应用主要在于数据库应用, 所以一个应用中会存在大量的数据库操作, 使用单例模式, 则可以避免大量的new 操作消耗的资源. 2.如果系统中需要有一个类来全局控制某些 ...

  2. 使用代码向一个普通的类注入Spring的实例

    转载请在页首注明作者与原文地址 一:应用场景 什么是普通的类,就是没有@Controller,@Service,@Repository,@Component等注解修饰的类,同时xml文件中,也没有相应 ...

  3. 一个Java文件至多包含一个公共类

    编写一个java源文件时,该源文件又称为编译单元.一个java文件可以包含多个类,但至多包含一个公共类,作为编译时该java文件的公用接口,公共类的名字和源文件的名字要相同,源文件名字的格式为[公共类 ...

  4. 一个java源文件中为什么只能有一个public类。

    我们都遇到过一个源文件中有多个java类,但当第一个类使用public修饰时,如果下面还有类使用public修饰,会报错.也就是是说一个java源文件最多只能有一个public类. 当有一个publi ...

  5. 很久以前写的一个 ShareRestrictedSD 类

    代码中一开始的 几个 USES 单元,可能是多余的. unit ShareRestrictedSD; interface uses Windows, Messages, SysUtils, Class ...

  6. 22.编写一个类A,该类创建的对象可以调用方法showA输出小写的英文字母表。然后再编写一个A类的子类B,子类B创建的对象不仅可以调用方法showA输出小写的英文字母表,而且可以调用子类新增的方法showB输出大写的英文字母表。最后编写主类C,在主类的main方法 中测试类A与类B。

    22.编写一个类A,该类创建的对象可以调用方法showA输出小写的英文字母表.然后再编写一个A类的子类B,子类B创建的对象不仅可以调用方法showA输出小写的英文字母表,而且可以调用子类新增的方法sh ...

  7. Java集合-5. (List)已知有一个Worker 类如下: 完成下面的要求 1) 创建一个List,在List 中增加三个工人,基本信息如下: 姓名 年龄 工资 zhang3 18 3000 li4 25 3500 wang5 22 3200 2) 在li4 之前插入一个工人,信息为:姓名:zhao6,年龄:24,工资3300 3) 删除wang5 的信息 4) 利用for 循

    第六题 5. (List)已知有一个Worker 类如下: public class Worker { private int age; private String name; private do ...

  8. Java基础-继承-编写一个Java应用程序,设计一个汽车类Vehicle,包含的属性有车轮个数 wheels和车重weight。小车类Car是Vehicle的子类,其中包含的属性有载人数 loader。卡车类Truck是Car类的子类,其中包含的属性有载重量payload。每个 类都有构造方法和输出相关数据的方法。最后,写一个测试类来测试这些类的功 能。

    #29.编写一个Java应用程序,设计一个汽车类Vehicle,包含的属性有车轮个数 wheels和车重weight.小车类Car是Vehicle的子类,其中包含的属性有载人数 loader.卡车类T ...

  9. java基础—继承题目:编写一个Animal类,具有属性:种类;具有功能:吃、睡。定义其子类Fish

    编写一个Animal类,具有属性:种类:具有功能:吃.睡.定义其子类Fish package zhongqiuzuoye; public class Animal { //属性 private Str ...

随机推荐

  1. ubuntu启动慢

    http://blog.sina.com.cn/s/blog_4cc9ffbc0100rxhh.html 参考 笔记本装的是ubuntu12.04,最近发现开机启动特别慢,至少3分钟,总担心系统会启动 ...

  2. Linux各发行版本 优缺点 简介

    2008.01.21 13:43 Linux最早由Linus Benedict Torvalds在1991年开始编写.在这之前,RichardStallman创建了Free SoftwareFound ...

  3. ASP.NET文件上传

    <asp:FileUpload ID="FileUpload" runat="server" /> private string upLoad() ...

  4. Battle Over Cities (25)(DFS、连通图)

    It is vitally important to have all the cities connected by highways in a war. If a city is occupied ...

  5. 【socket】Socket的三个功能类TCPClient、TCPListener 和 UDPClient

    Socket的三个功能类TCPClient.TCPListener 和 UDPClient (转) 应用程序可以通过 TCPClient.TCPListener 和 UDPClient 类使用传输控制 ...

  6. C# 使用winForm的TreeView显示中国城镇四级联动

    直接上代码吧,这里 MySql.Data.MySqlClient;需要到mysql官网下载mysql-connector-net-6.9.8-noinstall.zip   访问密码 6073 usi ...

  7. WebApi中帮助页Description的中文显示

    转自:http://edi.wang/post/2013/10/28/auto-generate-help-document-aspnet-webapi 我选择Web API的一个重要原因就是因为可以 ...

  8. json分别算出元素的个数和最多的元素

    个数: var str = 'aaafsdsaaasasasasaa'; var json = {}; for (var i = 0; i < str.length; i++) { if(!js ...

  9. cmp比较指令对标志寄存器的影响

    比如: mov ax,x mov bx,y cmp ax,bx cmp ax,bx的逻辑含义是比较ax,bx中的值.如果执行后: ZF=1则AX=BX ZF=0则AX!=BX CF=1则AX<B ...

  10. PAT-乙级-1019. 数字黑洞 (20)

    1019. 数字黑洞 (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 给定任一个各位数字不完全相同的4位 ...