首页 / PHP / 一个php类 Autoloader
一个php类 Autoloader
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了一个php类 Autoloader,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1605字,纯文字阅读大概需要3分钟。
内容图文
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‘);
原文:http://www.cnblogs.com/youxin/p/3949457.html
内容总结
以上是互联网集市为您收集整理的一个php类 Autoloader全部内容,希望文章能够帮你解决一个php类 Autoloader所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。