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


PHP Haanga::has_compiled方法代码示例

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


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

示例1: Load

 /**
  *  Load
  *
  *  Load template. If the template is already compiled, just the compiled
  *  PHP file will be included an used. If the template is new, or it 
  *  had changed, the Haanga compiler is loaded in memory, and the template
  *  is compiled.
  *
  *
  *  @param string $file
  *  @param array  $vars 
  *  @param bool   $return
  *  @param array  $blocks   
  *
  *  @return string|NULL
  */
 public static function Load($file, $vars = array(), $return = FALSE, $blocks = array())
 {
     if (empty(self::$cache_dir)) {
         throw new Haanga_Exception("Cache dir or template dir is missing");
     }
     self::$has_compiled = FALSE;
     $tpl = self::$templates_dir . '/' . $file;
     $fnc = sha1($tpl);
     $callback = "haanga_" . $fnc;
     if (is_callable($callback)) {
         return $callback($vars, $return, $blocks);
     }
     $php = self::$hash_filename ? $fnc : $file;
     $php = self::$cache_dir . '/' . $php . '.php';
     $check = TRUE;
     if (self::$check_ttl && self::$check_get && self::$check_set) {
         /* */
         if (call_user_func(self::$check_get, $callback)) {
             /* disable checking for the next $check_ttl seconds */
             $check = FALSE;
         } else {
             $result = call_user_func(self::$check_set, $callback, TRUE, self::$check_ttl);
         }
     }
     if (!is_file($php) || $check && filemtime($tpl) > filemtime($php)) {
         if (!is_file($tpl)) {
             /* There is no template nor compiled file */
             throw new Exception("View {$file} doesn't exists");
         }
         if (!is_dir(dirname($php))) {
             $old = umask(0);
             mkdir(dirname($php), 0777, TRUE);
             umask($old);
         }
         $fp = fopen($php, "a+");
         /* try to block PHP file */
         if (!flock($fp, LOCK_EX | LOCK_NB)) {
             /* couldn't block, another process is already compiling */
             fclose($fp);
             if (is_file($php)) {
                 /*
                  ** if there is an old version of the cache 
                  ** load it 
                  */
                 require $php;
                 if (is_callable($callback)) {
                     return $callback($vars, $return, $blocks);
                 }
             }
             /*
              ** no luck, probably the template is new
              ** the compilation will be done, but we won't
              ** save it (we'll use eval instead)
              */
             unset($fp);
         }
         /* recompile */
         $compiler = self::getCompiler();
         if (self::$debug) {
             $compiler->setDebug($php . ".dump");
         }
         try {
             $code = $compiler->compile_file($tpl, FALSE, $vars);
         } catch (Exception $e) {
             if (isset($fp)) {
                 /*
                  ** set the $php file as old (to force future
                  ** recompilation)
                  */
                 touch($php, 300, 300);
                 chmod($php, 0777);
             }
             /* re-throw exception */
             throw $e;
         }
         if (isset($fp)) {
             ftruncate($fp, 0);
             // truncate file
             fwrite($fp, "<?php" . $code);
             flock($fp, LOCK_UN);
             // release the lock
             fclose($fp);
         } else {
             /* local eval */
//.........这里部分代码省略.........
开发者ID:narock,项目名称:lodspeakr,代码行数:101,代码来源:Haanga.php

示例2: Load

 /**
  *  Load
  *
  *  Load template. If the template is already compiled, just the compiled
  *  PHP file will be included an used. If the template is new, or it 
  *  had changed, the Haanga compiler is loaded in memory, and the template
  *  is compiled.
  *
  *
  *  @param string $file
  *  @param array  $vars 
  *  @param bool   $return
  *  @param array  $blocks   
  *
  *  @return string|NULL
  */
 public static function Load($file, $vars = array(), $return = FALSE, $blocks = array())
 {
     static $compiler;
     if (empty(self::$cache_dir)) {
         throw new Haanga_Exception("Cache dir or template dir is missing");
     }
     self::$has_compiled = FALSE;
     $tpl = self::$templates_dir . '/' . $file;
     $fnc = sha1($tpl);
     $callback = "haanga_" . $fnc;
     if (is_callable($callback)) {
         return $callback($vars, $return, $blocks);
     }
     $php = self::$hash_filename ? $fnc : $file;
     $php = self::$cache_dir . '/' . $php . '.php';
     $check = TRUE;
     if (self::$check_ttl && self::$check_get && self::$check_set) {
         /* */
         if (call_user_func(self::$check_get, $callback)) {
             /* disable checking for the next $check_ttl seconds */
             $check = FALSE;
         } else {
             $result = call_user_func(self::$check_set, $callback, TRUE, self::$check_ttl);
         }
     }
     if (!is_file($php) || $check && filemtime($tpl) > filemtime($php)) {
         if (!is_file($tpl)) {
             /* There is no template nor compiled file */
             throw new Exception("View {$file} doesn't exists");
         }
         if (!is_dir(dirname($php))) {
             $old = umask(0);
             mkdir(dirname($php), 0777, TRUE);
             umask($old);
         }
         $fp = fopen($php, "a+");
         /* try to block PHP file */
         if (!flock($fp, LOCK_EX | LOCK_NB)) {
             /* couldn't block, another process is already compiling */
             fclose($fp);
             if (is_file($php)) {
                 /*
                  ** if there is an old version of the cache 
                  ** load it 
                  */
                 require $php;
                 return $callback($vars, $return, $blocks);
             }
             /*
              ** no luck, probably the template is new
              ** the compilation will be done, but we won't
              ** save
              */
             unset($fp);
         }
         /* recompile */
         if (!$compiler) {
             self::checkCacheDir();
             /* Load needed files (to avoid autoload as much as possible) */
             $dir = dirname(__FILE__);
             require_once "{$dir}/Haanga/AST.php";
             require_once "{$dir}/Haanga/Compiler.php";
             require_once "{$dir}/Haanga/Compiler/Runtime.php";
             require_once "{$dir}/Haanga/Compiler/Parser.php";
             require_once "{$dir}/Haanga/Compiler/Lexer.php";
             require_once "{$dir}/Haanga/Generator/PHP.php";
             require_once "{$dir}/Haanga/Extension.php";
             require_once "{$dir}/Haanga/Extension/Filter.php";
             require_once "{$dir}/Haanga/Extension/Tag.php";
             /* load compiler (done just once) */
             if (self::$use_autoload) {
                 spl_autoload_register(array(__CLASS__, 'AutoLoad'));
             }
             $compiler = new Haanga_Compiler_Runtime();
             if (self::$bootstrap) {
                 /* call bootstrap hook, just the first time */
                 call_user_func(self::$bootstrap);
             }
             if (count(self::$compiler) != 0) {
                 foreach (self::$compiler as $opt => $value) {
                     Haanga_Compiler::setOption($opt, $value);
                 }
             }
         }
//.........这里部分代码省略.........
开发者ID:rolando-archive,项目名称:haanga-benchs,代码行数:101,代码来源:Haanga.php


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