一个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');
一个php类 Autoloader的更多相关文章
- PHP用单例模式实现一个数据库类
使用单例模式的出发点: 1.php的应用主要在于数据库应用, 所以一个应用中会存在大量的数据库操作, 使用单例模式, 则可以避免大量的new 操作消耗的资源. 2.如果系统中需要有一个类来全局控制某些 ...
- 使用代码向一个普通的类注入Spring的实例
转载请在页首注明作者与原文地址 一:应用场景 什么是普通的类,就是没有@Controller,@Service,@Repository,@Component等注解修饰的类,同时xml文件中,也没有相应 ...
- 一个Java文件至多包含一个公共类
编写一个java源文件时,该源文件又称为编译单元.一个java文件可以包含多个类,但至多包含一个公共类,作为编译时该java文件的公用接口,公共类的名字和源文件的名字要相同,源文件名字的格式为[公共类 ...
- 一个java源文件中为什么只能有一个public类。
我们都遇到过一个源文件中有多个java类,但当第一个类使用public修饰时,如果下面还有类使用public修饰,会报错.也就是是说一个java源文件最多只能有一个public类. 当有一个publi ...
- 很久以前写的一个 ShareRestrictedSD 类
代码中一开始的 几个 USES 单元,可能是多余的. unit ShareRestrictedSD; interface uses Windows, Messages, SysUtils, Class ...
- 22.编写一个类A,该类创建的对象可以调用方法showA输出小写的英文字母表。然后再编写一个A类的子类B,子类B创建的对象不仅可以调用方法showA输出小写的英文字母表,而且可以调用子类新增的方法showB输出大写的英文字母表。最后编写主类C,在主类的main方法 中测试类A与类B。
22.编写一个类A,该类创建的对象可以调用方法showA输出小写的英文字母表.然后再编写一个A类的子类B,子类B创建的对象不仅可以调用方法showA输出小写的英文字母表,而且可以调用子类新增的方法sh ...
- 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 ...
- Java基础-继承-编写一个Java应用程序,设计一个汽车类Vehicle,包含的属性有车轮个数 wheels和车重weight。小车类Car是Vehicle的子类,其中包含的属性有载人数 loader。卡车类Truck是Car类的子类,其中包含的属性有载重量payload。每个 类都有构造方法和输出相关数据的方法。最后,写一个测试类来测试这些类的功 能。
#29.编写一个Java应用程序,设计一个汽车类Vehicle,包含的属性有车轮个数 wheels和车重weight.小车类Car是Vehicle的子类,其中包含的属性有载人数 loader.卡车类T ...
- java基础—继承题目:编写一个Animal类,具有属性:种类;具有功能:吃、睡。定义其子类Fish
编写一个Animal类,具有属性:种类:具有功能:吃.睡.定义其子类Fish package zhongqiuzuoye; public class Animal { //属性 private Str ...
随机推荐
- 使用git的正确姿势
1.Windows上安装git:从https://git-for-windows.github.io下载msysgit. 2.linux(Debian或Ubuntu)安装git:sudo apt-ge ...
- gulp 不是内部或者外部命令 或者 webpack 不是内部或者外部命令
gulp安装也正常,但是就是查看gulp -v的时候报错,原因:缺少系统变量PATH或者PATH变量错误 提示:这个系统变量PATH,直接追加就好(多个变量值用分号;隔开),不要删除已经有的系统变量P ...
- 为什么Facebook要将视频从Flash全面迁移到HTML5?
英文原文:Why we chose to move to HTML5 video 编者按:Facebook 前端高级工程师 Daniel Baulig 解释了 Facebook 为什么要将视频全面迁移 ...
- 在asp.net mvc中如何使用Grid++ Report (锐浪报表)
在asp.net mvc中如何使用Grid++ Report (锐浪报表) 在cshtml,razor中的处理方法 以官方的asp.net(csharp)中的第一个示例"1a.简单表格&qu ...
- Beaglebone Back学习七(URAT串口测试)
URAT串口测试
- 使用bootstrap+asp.net mvc4+IBatis.Net实现的小程序
这个项目用到了三个技术点 1.bootstap 3.0 2.asp.net mvc4 3.IBatis.Net 这个三个技术点分别解决前端界面展示.中间mvc路由控制.实体框架映射数据访问 重点分页问 ...
- poj 2947 Widget Factory
Widget Factory 题意:有n件装饰品,有m组信息.(1 <= n ,m<= 300)每组信息有开始的星期和结束的星期(是在mod 7范围内的)并且还包括num种装饰品的种类(1 ...
- git操作技巧(转载)
转载自:https://segmentfault.com/q/1010000000181403 git支持很多种工作流程,我们采用的一般是这样,远程创建一个主分支,本地每人创建功能分支,日常工作流程如 ...
- 【BZOJ 1877】 [SDOI2009]晨跑
Description Elaxia最近迷恋上了空手道,他为自己设定了一套健身计划,比如俯卧撑.仰卧起坐等 等,不过到目前为止,他坚持下来的只有晨跑. 现在给出一张学校附近的地图,这张地图中包含N个十 ...
- CLSID {91493441-5A91-11CF-8700-00AA0060263B}错误
最近遇到一个棘手的问题,在C#中处理PPT转HTML的过程中需要用到COM组件,按照往常的设置如下: 1. Start->Run->DCOMCNFG->Component Servi ...