本文整理汇总了PHP中PHPTAL::prepare方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPTAL::prepare方法的具体用法?PHP PHPTAL::prepare怎么用?PHP PHPTAL::prepare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPTAL
的用法示例。
在下文中一共展示了PHPTAL::prepare方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testFile
/**
* @return int - one of TEST_* constants
*/
function testFile($fullpath)
{
try {
$this->checked++;
$phptal = new PHPTAL($fullpath);
$phptal->setForceReparse(true);
$phptal->prepare();
return self::TEST_OK;
} catch (PHPTAL_UnknownModifierException $e) {
if ($this->skipUnknownModifiers && is_callable(array($e, 'getModifierName'))) {
$this->warnings[] = array(dirname($fullpath), basename($fullpath), "Unknown expression modifier: " . $e->getModifierName() . " (use -i to include your custom modifier functions)", $e->getLine());
return self::TEST_SKIPPED;
}
$log_exception = $e;
} catch (Exception $e) {
$log_exception = $e;
}
// Takes exception from either of the two catch blocks above
$this->errors[] = array(dirname($fullpath), basename($fullpath), $log_exception->getMessage(), $log_exception->getLine());
return self::TEST_ERROR;
}
示例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;
// 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);
}
}
示例3: testFile
function testFile($fullpath)
{
try {
$this->checked++;
$phptal = new PHPTAL($fullpath);
$phptal->setForceReparse(true);
$phptal->prepare();
echo '.';
} catch (PHPTAL_UnknownModifierException $e) {
if ($this->skipUnknownModifiers && is_callable(array($e, 'getModifierName'))) {
echo 'S';
$this->warnings[] = array(dirname($fullpath), basename($fullpath), "Unknown expression modifier: " . $e->getModifierName() . " (use -i to include your custom modifier functions)", $e->getLine());
return;
}
} catch (Exception $e) {
echo 'E';
}
$this->errors[] = array(dirname($fullpath), basename($fullpath), $e->getMessage(), $e->getLine());
}
示例4: _executeMacroOfTempalte
/**
* This is PHPTAL's internal function that handles
* execution of macros from templates.
*
* $this is caller's context (the file where execution had originally started)
* @param $local_tpl is PHPTAL instance of the file in which macro is defined (it will be different from $this if it's external macro call)
* @access private
*/
public final function _executeMacroOfTempalte($path, PHPTAL $local_tpl)
{
// extract macro source file from macro name, if macro path does not
// contain filename, 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();
// keep it small (typically only 1 or 2 external files are used)
if (count($this->externalMacroTempaltesCache) > 10) {
$this->externalMacroTempaltesCache = array();
}
$this->externalMacroTempaltesCache[$file] = $tpl;
}
// save current file
$currentFile = $this->_context->_file;
$this->_context->_file = $tpl->_file;
$fun = $tpl->getFunctionName() . '_' . strtr($macroName, "-", "_");
if (!function_exists($fun)) {
throw new PHPTAL_MacroMissingException("Macro '{$macroName}' is not defined in {$file}", $this->_source->getRealPath());
}
try {
$fun($tpl, $this);
} catch (PHPTAL_TemplateException $e) {
$e->hintSrcPosition($tpl->_context->_file . '/' . $macroName, $tpl->_context->_line);
$this->_context->_file = $currentFile;
throw $e;
}
// restore current file
$this->_context->_file = $currentFile;
} else {
// call local macro
$fun = $local_tpl->getFunctionName() . '_' . strtr($path, "-", "_");
if (!function_exists($fun)) {
throw new PHPTAL_MacroMissingException("Macro '{$path}' is not defined", $local_tpl->_source->getRealPath());
}
$fun($local_tpl, $this);
}
}
示例5: 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);
}
}