当前位置: 首页>>代码示例>>PHP>>正文


PHP Autoload::_cache方法代码示例

本文整理汇总了PHP中Autoload::_cache方法的典型用法代码示例。如果您正苦于以下问题:PHP Autoload::_cache方法的具体用法?PHP Autoload::_cache怎么用?PHP Autoload::_cache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Autoload的用法示例。


在下文中一共展示了Autoload::_cache方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _getClassPath

 /**
  * Get correct file to include from a class name
  * Used by __autoload()
  * 
  * @param string $className     Input class name
  * @param string $ext           [optional] Class file extension to use. Default is 'class.php'
  * @return string|false         Return a path or false if no file is found
  */
 private static function _getClassPath($className, $ext = 'class.php')
 {
     if (isset(self::$_cache[$className])) {
         return self::$_cache[$className];
     }
     $mustCache = Config::get('cache.autoload');
     $cache = CACHE_DIR . DS . 'autoload.cache';
     if ($mustCache && is_file($cache)) {
         self::$_cache = unserialize(file_get_contents($cache));
         if (isset(self::$_cache[$className])) {
             return self::$_cache[$className];
         }
     }
     $r = array('f' => HOOKS_DIR, 'm' => WEBAPP_MODULES_DIR);
     $path = explode('_', $className);
     // replace by folder
     if (in_array($path[0], array_keys($r))) {
         $path[0] = $r[$path[0]];
     }
     // get last path
     $lastPath = lcfirst(end($path)) . DS;
     // get file name
     $fileName = lcfirst(array_pop($path)) . '.' . $ext;
     // set path in string
     $fpath = join(DS, $path) . DS;
     // file is in the right folder corresponding to the name
     if (is_file($fpath . $fileName)) {
         self::$_cache[$className] = $fpath . $fileName;
         if ($mustCache) {
             file_put_contents($cache, serialize(self::$_cache), LOCK_EX);
         }
         return $fpath . $fileName;
     }
     // file is in the framework
     if ($className[0] === 'f') {
         $possibilities = array();
         // hooks path
         $possibilities[] = $fpath . 'core' . DS . $fileName;
         // f_Session => /hooks/core/session.class.php
         $possibilities[] = $fpath . $lastPath . $fileName;
         // f_Session => /hooks/session/session.class.php
         // original path
         $path[0] = FW_DIR;
         $fpath = join(DS, $path) . DS;
         $possibilities[] = $fpath . $fileName;
         // f_Session => /oxygen/session.class.php
         $possibilities[] = $fpath . 'core' . DS . $fileName;
         // f_Session => /oxygen/core/session.class.php
         $possibilities[] = $fpath . $lastPath . $fileName;
         // f_Session => /oxygen/session/session.class.php
         // testing possibilities
         foreach ($possibilities as $possibility) {
             if (is_file($possibility)) {
                 self::$_cache[$className] = $possibility;
                 if ($mustCache) {
                     file_put_contents($cache, serialize(self::$_cache), LOCK_EX);
                 }
                 return $possibility;
             }
         }
     }
     // file is module in webapp
     if ($className[0] === 'm') {
         $path[0] = MODULES_DIR;
         $fpath = join(DS, $path) . DS;
         if (is_file($fpath . $fileName)) {
             self::$_cache[$className] = $fpath . $fileName;
             if ($mustCache) {
                 file_put_contents($cache, serialize(self::$_cache), LOCK_EX);
             }
             return $fpath . $fileName;
         }
     }
     // returns false if file not found
     return false;
 }
开发者ID:salomalo,项目名称:php-oxygen,代码行数:84,代码来源:autoload.php


注:本文中的Autoload::_cache方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。