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


PHP Safe::stat方法代码示例

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


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

示例1: sprintf

 /**
  * get the gdiff as a single text string
  *
  * @param string a file name of the original content
  * @param string a file for the updated content
  * @return an ASCII string
  */
 public static function &gdiff($original, $updated)
 {
     global $context;
     // read the original file
     $stat = Safe::stat($context['path_to_root'] . $original);
     if (!is_array($stat)) {
         return sprintf(i18n::s('Impossible to read %s.'), $original);
     }
     $text = '--- ' . $original . "\t" . str_replace(' ', ' ', Skin::build_date($stat[9])) . "\n";
     $original_lines = Safe::file($context['path_to_root'] . $original);
     // read the updated file
     $stat = Safe::stat($context['path_to_root'] . $updated);
     if (!is_array($stat)) {
         return sprintf(i18n::s('Impossible to read %s.'), $updated);
     }
     $text .= '+++ ' . $updated . "\t" . str_replace(' ', ' ', Skin::build_date($stat[9])) . "\n";
     $updated_lines = Safe::file($context['path_to_root'] . $updated);
     // compare the two sequences
     $sequence = Scripts::compare($original_lines, $updated_lines);
     // format the result according to the gdiff specification
     $in_chunk = TRUE;
     $sync = 0;
     $chunk_start = $old_start = $old_current = $new_start = $new_current = 0;
     for ($index = 0; $index < count($sequence); $index++) {
         list($tag, $left, $right) = $sequence[$index];
         switch ($tag) {
             case '-':
                 $chunk[] = '-' . $left;
                 $sync = 0;
                 if (!$in_chunk) {
                     $old_start = $old_current - 3;
                     $new_start = $new_current - 3;
                     $in_chunk = TRUE;
                 }
                 $old_current++;
                 break;
             case '+':
                 $chunk[] = '+' . $right;
                 $sync = 0;
                 if (!$in_chunk) {
                     $old_start = $old_current - 3;
                     $new_start = $new_current - 3;
                     $in_chunk = TRUE;
                 }
                 $new_current++;
                 break;
             case '=':
                 $chunk[] = ' ' . $left;
                 if ($in_chunk) {
                     if ($sync++ >= 2) {
                         $in_chunk = FALSE;
                         $text .= '@@ -' . ($old_start + 1) . ',' . ($old_current - $old_start + 1) . ' +' . ($new_start + 1) . ',' . ($new_current - $new_start + 1) . ' @@' . "\n";
                         foreach ($chunk as $line) {
                             $text .= $line . "\n";
                         }
                         unset($chunk);
                     }
                 } elseif (count($chunk) > 3) {
                     array_shift($chunk);
                 }
                 $old_current++;
                 $new_current++;
                 break;
         }
     }
     if (is_array($chunk) && count($chunk) > 0) {
         $text .= '@@ -' . ($old_start + 1) . ',' . ($old_current - $old_start) . ' +' . ($new_start + 1) . ',' . ($new_current - $new_start) . ' @@' . "\n";
         foreach ($chunk as $line) {
             $text .= $line . "\n";
         }
     }
     // return the result of the whole comparison
     return $text;
 }
开发者ID:rair,项目名称:yacs,代码行数:81,代码来源:scripts.php


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