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


PHP Safe::realpath方法代码示例

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


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

示例1: link_file

 /**
  * prepare a link to .js or .css file for declare in final template
  * will search of a minified version in production mode
  *
  * @global type $context
  * @param string $path, relative from yacs root, or external url
  * @param string $forced_type = 'js' or 'css', if path does not end by .js or .css.
  * @param string $forced_position = 'header', 'defer' of 'footer' to specify where to
  * load a js file (defer always before footer).
  * @param boolean $straitnow to get the link without adding it to stack
  * @return false if unsucceed
  */
 public static function link_file($path, $forced_type = '', $forced_position = '', $straitnow = false)
 {
     global $context;
     // enable shorter function call
     if (strtolower($forced_type) === 'now') {
         $straitnow = true;
         $forced_type = '';
     }
     // avoid linking twice the same file
     $key = md5($path);
     if (isset($context['linked_files'][$key])) {
         return Js_Css::link_exit(true, $path, $straitnow);
     } else {
         $context['linked_files'][$key] = $path;
     }
     // gather info on file
     $path_parts = pathinfo($path);
     // just to avoid warnings
     if (!isset($path_parts['extension'])) {
         $path_parts['extension'] = '';
     }
     // how the script will be considered ?
     $ext = $forced_type ? $forced_type : $path_parts['extension'];
     // we need a extension
     if (!isset($ext)) {
         return Js_Css::link_exit(false, $path, $straitnow);
     }
     // if path is a local file
     if (strncmp($path, 'http', 4) != 0) {
         // check if file exists
         if (!file_exists(Safe::realpath($path))) {
             return Js_Css::link_exit(false, $path, $straitnow);
         }
         // and we are in production mode
         // and file not already minified
         if ($context['with_debug'] == 'N' && !preg_match('/\\.min\\./', $path_parts['filename'])) {
             // minified version path
             $min_v = $path_parts['dirname'] . '/' . $path_parts['filename'] . '.min.' . $path_parts['extension'];
             if (file_exists(Safe::realpath($min_v))) {
                 $path = $min_v;
             }
             // TODO : warning case exept if .core. ;
         }
         // get last revision date
         $revision = Js_css::get_revision(Safe::realpath($path));
         // add root url
         if (isset($context['static_subdom']) && $context['static_subdom']) {
             $path = $context['static_subdom'] . $path;
         } else {
             $path = $context['url_to_master'] . $context['url_to_root'] . $path;
         }
     } else {
         // we can't know the revision date of external files
         $revision = '';
     }
     // css or js ?
     switch ($ext) {
         case 'css':
             $tag = Js_css::build_css_declaration($path . $revision);
             if ($straitnow) {
                 return $tag;
             }
             Js_css::add_css($tag);
             break;
         case 'js':
             $tag = Js_css::build_js_declaration($path . $revision);
             if ($straitnow) {
                 return $tag;
             }
             // target is header if .head. is part of filename
             if (!$forced_position && preg_match('/\\.head\\./', $path_parts['filename'])) {
                 $forced_position = 'header';
             }
             // by default .js goes to page footer
             $target = $forced_position ? $forced_position : 'defer';
             Js_css::add_js($tag, $target);
             break;
         default:
             // error
             return Js_Css::link_exit(false, $path, $straitnow);
     }
     // count files calls over time
     if ($context['with_debug'] == 'Y' && !defined('NO_MODEL_PRELOAD')) {
         $query = 'INSERT INTO ' . SQL::table_name('js_css_calls') . ' SET' . ' id = "' . $key . '",' . ' path = "' . $path . '",' . ' calls = 1' . ' ON DUPLICATE KEY UPDATE calls=calls+1';
         SQL::query($query, TRUE);
     }
     return Js_Css::link_exit(true, $path, $straitnow);
 }
开发者ID:rair,项目名称:yacs,代码行数:100,代码来源:js_css.php

示例2: unlink

 /**
  * remove a file
  *
  * @param string path to file to delete
  * @return TRUE on success, FALSE on failure
  */
 public static function unlink($file)
 {
     // translate the path
     $file = Safe::realpath($file);
     // maybe node has been already removed
     if (!file_exists($file)) {
         return TRUE;
     }
     // ensure call is allowed
     if (is_callable('unlink')) {
         return @unlink($file);
     }
     // tough luck
     return FALSE;
 }
开发者ID:rair,项目名称:yacs,代码行数:21,代码来源:safe.php

示例3: hash

 /**
  * hash the content of one file
  *
  * @param string the path of the target file
  * @return an array of ($lines, $hash), or NULL if not part of the reference set
  */
 public static function hash($file)
 {
     global $context;
     // only process php scripts
     if (!strpos(basename($file), '.php')) {
         return NULL;
     }
     // check file content
     if (!($handle = Safe::fopen($file, 'rb'))) {
         return NULL;
     }
     // count lines
     $reference = FALSE;
     $count = 0;
     while ($line = fgets($handle)) {
         $count++;
         if (strpos($line, '@reference')) {
             $reference = TRUE;
         }
     }
     fclose($handle);
     // only accept reference scripts
     if (!$reference) {
         return NULL;
     }
     // compute md5 signature
     if (!($hash = md5_file(Safe::realpath($file)))) {
         return NULL;
     }
     // return the result
     return array($count, $hash);
 }
开发者ID:rair,项目名称:yacs,代码行数:38,代码来源:scripts.php


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