免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1556 | 回复: 0
打印 上一主题 下一主题

php 自动加载方法 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2015-06-24 09:57 |只看该作者 |倒序浏览
  1. <?php
  2. class inload
  3. {
  4. /**
  5.      * 类自动载入,不需要由开发者调用
  6.      *
  7.      * @param string $class 类文件
  8.      */
  9.     private function autoload( $class )
  10.     {
  11.         if( empty($class) )
  12.         {
  13.             throw new QException('加载文件不存在'.$class);
  14.         }
  15.         else
  16.         {   
  17.             require _SPRING_.'/_Core/SpringMap.php';  //框架地图
  18.             if(! file_exists( $source[$class]['file'] ) )
  19.             {
  20.                 throw new QException('加载文件不存在'.$class);
  21.             }
  22.             require $source[$class]['file'];
  23.         }
  24.     }
  25.      
  26.     /**
  27.      * 注册或取消注册一个自动类载入方法
  28.      *
  29.      * 该方法参考 Zend Framework
  30.      *
  31.      * @param string $class 提供自动载入服务的类
  32.      * @param boolean $enabled 启用或禁用该服务
  33.      */
  34.     private function registerAutoload($class = 'Interpreter' , $enabled = true)
  35.     {
  36.         if (!function_exists('spl_autoload_register'))
  37.         {
  38.             throw new QException('spl_autoload 不存在这个PHP的安装');
  39.         }
  40.         if ($enabled === true)
  41.         {
  42.             spl_autoload_register(array($class, 'autoload'));
  43.         }
  44.         else
  45.         {
  46.             spl_autoload_unregister(array($class, 'autoload'));
  47.         }
  48.     }
  49.      
  50.     /**
  51.     * 析构函数
  52.     */
  53.     public function __destruct()
  54.     {
  55.         self::registerAutoload('Interpreter' , false);
  56.     }   
  57. 举报
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP