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


PHP PHPTAL::getCodePath方法代码示例

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


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

示例1: executeMacro

 /**
  * Execute a template macro.
  * Should be used only from within generated template code!
  *
  * @param $path string Template macro path
  */
 public function executeMacro($path)
 {
     // extract macro source file from macro name, if not source file
     // found in $path, then the macro is assumed to be local
     if (preg_match('/^(.*?)\\/([a-z0-9_]*)$/i', $path, $m)) {
         list(, $file, $macroName) = $m;
         // TODO: stores a list of already prepared macro to avoid this
         // preparation on each call
         $tpl = new PHPTAL($file);
         $tpl->setConfigurationFrom($this);
         $tpl->prepare();
         // save current file
         $currentFile = $this->_context->__file;
         $this->_context->__file = $tpl->__file;
         // require PHP generated code and execute macro function
         require_once $tpl->getCodePath();
         $fun = $tpl->getFunctionName() . '_' . $macroName;
         if (!function_exists($fun)) {
             throw new PHPTAL_Exception("Macro '{$macroName}' is not defined in {$file}", $this->_source->getRealPath());
         }
         $fun($this, $this->_context);
         // restore current file
         $this->_context->__file = $currentFile;
     } else {
         // call local macro
         $fun = $this->getFunctionName() . '_' . trim($path);
         if (!function_exists($fun)) {
             throw new PHPTAL_Exception("Macro '{$macroName}' is not defined", $this->_source->getRealPath());
         }
         $fun($this, $this->_context);
     }
 }
开发者ID:nchiapol,项目名称:ecamp,代码行数:38,代码来源:PHPTAL.php

示例2: executeMacro

 /**
  * Execute a template macro.
  * Should be used only from within generated template code!
  *
  * @param $path string Template macro path
  */
 public function executeMacro($path)
 {
     // extract macro source file from macro name, if not source file
     // found in $path, then the macro is assumed to be local
     if (preg_match('/^(.*?)\\/([a-z0-9_]*)$/i', $path, $m)) {
         list(, $file, $macroName) = $m;
         if (isset($this->externalMacroTempaltesCache[$file])) {
             $tpl = $this->externalMacroTempaltesCache[$file];
         } else {
             $tpl = new PHPTAL($file);
             $tpl->setConfigurationFrom($this);
             $tpl->prepare();
             // require PHP generated code
             require_once $tpl->getCodePath();
             $this->externalMacroTempaltesCache[$file] = $tpl;
             if (count($this->externalMacroTempaltesCache) > 10) {
                 $this->externalMacroTempaltesCache = array();
             }
             // keep it small (typically only 1 or 2 external files are used)
         }
         // save current file
         $currentFile = $this->_context->__file;
         $this->_context->__file = $tpl->__file;
         $fun = $tpl->getFunctionName() . '_' . $macroName;
         if (!function_exists($fun)) {
             throw new PHPTAL_Exception("Macro '{$macroName}' is not defined in {$file}", $this->_source->getRealPath());
         }
         $fun($this, $this->_context);
         // restore current file
         $this->_context->__file = $currentFile;
     } else {
         // call local macro
         $fun = $this->getFunctionName() . '_' . trim($path);
         if (!function_exists($fun)) {
             throw new PHPTAL_Exception("Macro '{$path}' is not defined", $this->_source->getRealPath());
         }
         $fun($this, $this->_context);
     }
 }
开发者ID:alicam,项目名称:vanilla-theme,代码行数:45,代码来源:PHPTAL.php


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