本文整理汇总了PHP中Dwoo_Compiler::addTemplatePlugin方法的典型用法代码示例。如果您正苦于以下问题:PHP Dwoo_Compiler::addTemplatePlugin方法的具体用法?PHP Dwoo_Compiler::addTemplatePlugin怎么用?PHP Dwoo_Compiler::addTemplatePlugin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dwoo_Compiler
的用法示例。
在下文中一共展示了Dwoo_Compiler::addTemplatePlugin方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Dwoo_Plugin_load_templates_compile
/**
* Loads sub-templates contained in an external file
* <pre>
* * file : the resource name of the file to load
* </pre>
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
*
* @author Jordi Boggiano <j.boggiano@seld.be>
* @copyright Copyright (c) 2008, Jordi Boggiano
* @license http://dwoo.org/LICENSE Modified BSD License
* @link http://dwoo.org/
* @version 1.1.0
* @date 2009-07-18
* @package Dwoo
*/
function Dwoo_Plugin_load_templates_compile(Dwoo_Compiler $compiler, $file)
{
$file = substr($file, 1, -1);
if ($file === '') {
return;
}
if (preg_match('#^([a-z]{2,}):(.*)$#i', $file, $m)) {
// resource:identifier given, extract them
$resource = $m[1];
$identifier = $m[2];
} else {
// get the current template's resource
$resource = $compiler->getDwoo()->getTemplate()->getResourceName();
$identifier = $file;
}
$tpl = $compiler->getDwoo()->templateFactory($resource, $identifier);
if ($tpl === null) {
throw new Dwoo_Compilation_Exception($compiler, 'Load Templates : Resource "' . $resource . ':' . $identifier . '" not found.');
} elseif ($tpl === false) {
throw new Dwoo_Compilation_Exception($compiler, 'Load Templates : Resource "' . $resource . '" does not support includes.');
}
$cmp = clone $compiler;
$cmp->compile($compiler->getDwoo(), $tpl);
foreach ($cmp->getTemplatePlugins() as $template => $args) {
$compiler->addTemplatePlugin($template, $args['params'], $args['uuid'], $args['body']);
}
foreach ($cmp->getUsedPlugins() as $plugin => $type) {
$compiler->addUsedPlugin($plugin, $type);
}
$out = '\'\';// checking for modification in ' . $resource . ':' . $identifier . "\r\n";
$modCheck = $tpl->getIsModifiedCode();
if ($modCheck) {
$out .= 'if (!(' . $modCheck . ')) { ob_end_clean(); return false; }';
} else {
$out .= 'try {
$tpl = $this->templateFactory("' . $resource . '", "' . $identifier . '");
} catch (Dwoo_Exception $e) {
$this->triggerError(\'Load Templates : Resource <em>' . $resource . '</em> was not added to Dwoo, can not extend <em>' . $identifier . '</em>\', E_USER_WARNING);
}
if ($tpl === null)
$this->triggerError(\'Load Templates : Resource "' . $resource . ':' . $identifier . '" was not found.\', E_USER_WARNING);
elseif ($tpl === false)
$this->triggerError(\'Load Templates : Resource "' . $resource . '" does not support extends.\', E_USER_WARNING);
if ($tpl->getUid() != "' . $tpl->getUid() . '") { ob_end_clean(); return false; }';
}
return $out;
}
示例2: postProcessing
public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
{
$paramstr = 'Dwoo $dwoo';
$init = 'static $_callCnt = 0;' . "\n" . '$dwoo->scope[\' ' . $params['uuid'] . '\'.$_callCnt] = array();' . "\n" . '$_scope = $dwoo->setScope(array(\' ' . $params['uuid'] . '\'.($_callCnt++)));' . "\n";
$cleanup = '/* -- template end output */ $dwoo->setScope($_scope, true);';
foreach ($params['*'] as $param => $defValue) {
if ($defValue === null) {
$paramstr .= ', $' . $param;
} else {
$paramstr .= ', $' . $param . ' = ' . $defValue;
}
$init .= '$dwoo->scope[\'' . $param . '\'] = $' . $param . ";\n";
}
$init .= '/* -- template start output */';
$funcName = 'Dwoo_Plugin_' . $params['name'] . '_' . $params['uuid'];
$body = 'if (!function_exists(\'' . $funcName . "')) {\nfunction " . $funcName . '(' . $paramstr . ') {' . "\n{$init}" . Dwoo_Compiler::PHP_CLOSE . $prepend . str_replace(array('$this->', '$this,'), array('$dwoo->', '$dwoo,'), $content) . $append . Dwoo_Compiler::PHP_OPEN . $cleanup . "\n}\n}";
$compiler->addTemplatePlugin($params['name'], $params['*'], $params['uuid'], $body);
}