一个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 ...
随机推荐
- SecureCRT for Linux突破30天使用限制
当然还有一种方法,就是当你试用点i agree到时候,在~/.vandyke/Config 会生成一个文件SecureCRT_eval.lic,删除以后就可以恢复30天试用
- Reset / Validate Buffer
AL12
- ImageLoader(多线程网络图片加载)+本地缓存 for windowsphone 7
搞了好长一阵子wp,做点好事. C/S手机app中应用最多的是 获取网络图片,缓存到本地,展示图片 本次主要对其中的delay:LowProfileImageLoader进行修改,在获取图片的时候, ...
- Java中的分代垃圾回收策略
一.分代GC的理论基础 分代的垃圾回收策略,是基于这样一个事实:不同的对象的生命周期是不一样的.因此,不同生命周期的对象可以采取不同的收集方式,以便提高回收效率. 在Java程序运行的过程中,会产生大 ...
- Jquery ajax basic
$.ajax({ url: "test.aspx?action=testaction", contentType: "application/json; charset= ...
- Think PHP 提示验证码输入错误
最近遇到一个项目中用的是Thinkphp这个框架开发的,其中在登录这块有验证码这个功能,其实这个功能是TP自带的,其中主要方法是buildImageVerify,位于ThinkPHP\Extend\L ...
- Kakfa揭秘 Day1 Kafka原理内幕
Spark Streaming揭秘 Day32 Kafka原理内幕 今天开始,会有几天的时间,和大家研究下Kafka.在大数据处理体系中,kafka的重要性不亚于SparkStreaming.可以认为 ...
- Pandas简易入门(二)
目录: 处理缺失数据 制作透视图 删除含空数据的行和列 多行索引 使用apply函数 本节主要介绍如何处理缺失的数据,可以参考原文:https://www. ...
- ARCGIS 10中添加excel点字段生产点shp文件的工具
菜单栏中——文件——添加数据——添加XY数据——选择excel。 选择x,y和投影(注意这里投影应该是原数据的本身投影,不能直接选择你要转换的投影)完成。
- WDC2106 iOS10新特性及开发者要注意什么
昨晚苹果在旧金山召开了WWDC,看了WWDC2016直播,我们发现变得谨慎而开放的苹果在新一版四大平台系统中展示了很多变化,当然重中之重还是伟大的iOS.通过试用iOS10beta版,除了长大了的更强 ...