本文整理汇总了PHP中Dwoo_Compiler类的典型用法代码示例。如果您正苦于以下问题:PHP Dwoo_Compiler类的具体用法?PHP Dwoo_Compiler怎么用?PHP Dwoo_Compiler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Dwoo_Compiler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: preProcessing
public static function preProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $type)
{
$params = $compiler->getCompiledParams($params);
$func = $params['__funcname'];
$pluginType = $params['__functype'];
$params = $params['*'];
if ($pluginType & Dwoo_Core::CUSTOM_PLUGIN) {
$customPlugins = $compiler->getDwoo()->getCustomPlugins();
$callback = $customPlugins[$func]['callback'];
if (is_array($callback)) {
if (is_object($callback[0])) {
$callback = '$this->customPlugins[\'' . $func . '\'][0]->' . $callback[1] . '(';
} else {
$callback = '' . $callback[0] . '::' . $callback[1] . '(';
}
} else {
$callback = $callback . '(';
}
} else {
$callback = 'smarty_block_' . $func . '(';
}
$paramsOut = '';
foreach ($params as $i => $p) {
$paramsOut .= var_export($i, true) . ' => ' . $p . ',';
}
$curBlock =& $compiler->getCurrentBlock();
$curBlock['params']['postOut'] = Dwoo_Compiler::PHP_OPEN . ' $_block_content = ob_get_clean(); $_block_repeat=false; echo ' . $callback . '$_tag_stack[count($_tag_stack)-1], $_block_content, $this, $_block_repeat); } array_pop($_tag_stack);' . Dwoo_Compiler::PHP_CLOSE;
return Dwoo_Compiler::PHP_OPEN . $prepend . ' if (!isset($_tag_stack)){ $_tag_stack = array(); } $_tag_stack[] = array(' . $paramsOut . '); $_block_repeat=true; ' . $callback . '$_tag_stack[count($_tag_stack)-1], null, $this, $_block_repeat); while ($_block_repeat) { ob_start();' . Dwoo_Compiler::PHP_CLOSE;
}
示例2: Dwoo_Plugin_extendsCheck_compile
/**
* Checks whether an extended file has been modified, and if so recompiles the current template. This is for internal use only, do not use.
*
* 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_extendsCheck_compile(Dwoo_Compiler $compiler, $file)
{
preg_match('#^["\']([a-z]{2,}):(.*?)["\']$#i', $file, $m);
$resource = $m[1];
$identifier = $m[2];
$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.');
}
$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;
}
示例3: paramsToAttributes
/**
* utility function that converts an array of compiled parameters (or rest array) to a string of xml/html tag attributes
*
* this is to be used in preProcessing or postProcessing functions, example :
* $p = $compiler->getCompiledParams($params);
* // get only the rest array as attributes
* $attributes = Dwoo_Plugin::paramsToAttributes($p['*']);
* // get all the parameters as attributes (if there is a rest array, it will be included)
* $attributes = Dwoo_Plugin::paramsToAttributes($p);
*
* @param array $params an array of attributeName=>value items that will be compiled to be ready for inclusion in a php string
* @param string $delim the string delimiter you want to use (defaults to ')
* @param Dwoo_Compiler $compiler the compiler instance (optional for BC, but recommended to pass it for proper escaping behavior)
* @return string
*/
public static function paramsToAttributes(array $params, $delim = '\'', Dwoo_Compiler $compiler = null)
{
if (isset($params['*'])) {
$params = array_merge($params, $params['*']);
unset($params['*']);
}
$out = '';
foreach ($params as $attr => $val) {
$out .= ' ' . $attr . '=';
if (trim($val, '"\'') == '' || $val == 'null') {
$out .= str_replace($delim, '\\' . $delim, '""');
} elseif (substr($val, 0, 1) === $delim && substr($val, -1) === $delim) {
$out .= str_replace($delim, '\\' . $delim, '"' . substr($val, 1, -1) . '"');
} else {
if (!$compiler) {
// disable double encoding since it can not be determined if it was encoded
$escapedVal = '.(is_string($tmp2=' . $val . ') ? htmlspecialchars($tmp2, ENT_QUOTES, $this->charset, false) : $tmp2).';
} elseif (!$compiler->getAutoEscape() || false === strpos($val, 'isset($this->scope')) {
// escape if auto escaping is disabled, or there was no variable in the string
$escapedVal = '.(is_string($tmp2=' . $val . ') ? htmlspecialchars($tmp2, ENT_QUOTES, $this->charset) : $tmp2).';
} else {
// print as is
$escapedVal = '.' . $val . '.';
}
$out .= str_replace($delim, '\\' . $delim, '"') . $delim . $escapedVal . $delim . str_replace($delim, '\\' . $delim, '"');
}
}
return ltrim($out);
}
示例4: testSmartyCompat
public function testSmartyCompat()
{
$tpl = new Dwoo_Template_String('{ldelim}{$smarty.version}{rdelim}');
$tpl->forceCompilation();
$cmp = new Dwoo_Compiler();
$cmp->addPreProcessor('smarty_compat', true);
$this->assertEquals('{' . Dwoo::VERSION . '}', $this->dwoo->get($tpl, array(), $cmp));
}
示例5: postProcessing
public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
{
if (!isset($params['initialized'])) {
return '';
}
$block =& $compiler->getCurrentBlock();
$block['params']['hasElse'] = Dwoo_Compiler::PHP_OPEN . "else {\n" . Dwoo_Compiler::PHP_CLOSE . $content . Dwoo_Compiler::PHP_OPEN . "\n}" . Dwoo_Compiler::PHP_CLOSE;
return '';
}
示例6: postProcessing
public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
{
$rparams = $compiler->getRealParams($params);
$cparams = $compiler->getCompiledParams($params);
$compiler->setScope($rparams['var']);
$pre = Dwoo_Compiler::PHP_OPEN . 'if (' . $cparams['var'] . ')' . "\n{\n" . '$_with' . self::$cnt . ' = $this->setScope("' . $rparams['var'] . '");' . "\n/* -- start with output */\n" . Dwoo_Compiler::PHP_CLOSE;
$post = Dwoo_Compiler::PHP_OPEN . "\n/* -- end with output */\n" . '$this->setScope($_with' . self::$cnt++ . ', true);' . "\n}\n" . Dwoo_Compiler::PHP_CLOSE;
if (isset($params['hasElse'])) {
$post .= $params['hasElse'];
}
return $pre . $content . $post;
}
示例7: __construct
public function __construct()
{
parent::__construct();
$compiler = new Dwoo_Compiler();
$compiler->setDelimiters('<?', '?>');
// add preprocessor
// add custom plugins, functions, blocks, etc
$this->setCompiler($compiler);
$this->setCompileDir(PROJECT_RUNTIME . '/' . $type . '_c');
$this->assign('this', $page);
$this->assign('context', $context);
}
示例8: postProcessing
public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
{
$params = $compiler->getCompiledParams($params);
$params = isset($params['*']) ? $params['*'] : array();
$params_php = array();
foreach ($params as $key => $val) {
$params_php[] = var_export($key, true) . ' => ' . $val;
}
$params_php = 'array(' . implode(', ', $params_php) . ')';
$pre = Dwoo_Compiler::PHP_OPEN . 'ob_start();' . Dwoo_Compiler::PHP_CLOSE;
$post = Dwoo_Compiler::PHP_OPEN . __CLASS__ . '::_process(ob_get_clean(), ' . $params_php . ');' . Dwoo_Compiler::PHP_CLOSE;
return $pre . $content . $post;
}
示例9: testAutoEscape
public function testAutoEscape()
{
$cmp = new Dwoo_Compiler();
$cmp->setAutoEscape(true);
$tpl = new Dwoo_Template_String('{$foo}{auto_escape off}{$foo}{/}');
$tpl->forceCompilation();
$this->assertEquals("a<b>ca<b>c", $this->dwoo->get($tpl, array('foo' => 'a<b>c'), $cmp));
$tpl = new Dwoo_Template_String('{$foo}{auto_escape true}{$foo}{/}');
$tpl->forceCompilation();
$this->assertEquals("a<b>ca<b>c", $this->dwoo->get($tpl, array('foo' => 'a<b>c')));
// fixes the init call not being called (which is normal)
$fixCall = new Dwoo_Plugin_auto_escape($this->dwoo);
$fixCall->init('');
}
示例10: postProcessing
public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
{
$params = $compiler->getCompiledParams($params);
$mode = trim($params['mode'], '"\'');
switch ($mode) {
case 'js':
case 'javascript':
$content = preg_replace('#(?<!:)//\\s[^\\r\\n]*|/\\*.*?\\*/#', '', $content);
case 'default':
default:
}
$content = preg_replace(array("/\n/", "/\r/", '/(<\\?(?:php)?|<%)\\s*/'), array('', '', '$1 '), preg_replace('#^\\s*(.+?)\\s*$#m', '$1', $content));
return $content;
}
示例11: postProcessing
public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
{
$p = $compiler->getCompiledParams($params);
// no content was provided so use the url as display text
if ($content == "") {
// merge </a> into the href if href is a string
if (substr($p['href'], -1) === '"' || substr($p['href'], -1) === '\'') {
return Dwoo_Compiler::PHP_OPEN . 'echo ' . substr($p['href'], 0, -1) . '</a>' . substr($p['href'], -1) . ';' . Dwoo_Compiler::PHP_CLOSE;
}
// otherwise append
return Dwoo_Compiler::PHP_OPEN . 'echo ' . $p['href'] . '.\'</a>\';' . Dwoo_Compiler::PHP_CLOSE;
}
// return content
return $content . '</a>';
}
示例12: postProcessing
public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
{
$params = $compiler->getCompiledParams($params);
$out = $content . Dwoo_Compiler::PHP_OPEN . $prepend . "\n" . '$tmp = ob_get_clean();';
if ($params['trim'] !== 'false' && $params['trim'] !== 0) {
$out .= "\n" . '$tmp = trim($tmp);';
}
if ($params['cat'] === 'true' || $params['cat'] === 1) {
$out .= "\n" . '$tmp = $this->readVar(\'dwoo.capture.\'.' . $params['name'] . ') . $tmp;';
}
if ($params['assign'] !== 'null') {
$out .= "\n" . '$this->scope[' . $params['assign'] . '] = $tmp;';
}
return $out . "\n" . '$this->globals[\'capture\'][' . $params['name'] . '] = $tmp;' . $append . Dwoo_Compiler::PHP_CLOSE;
}
示例13: postProcessing
public static function postProcessing(Dwoo_Compiler $compiler, array $params, $prepend, $append, $content)
{
if (!isset($params['initialized'])) {
return '';
}
$params = $compiler->getCompiledParams($params);
$pre = Dwoo_Compiler::PHP_OPEN . "elseif (" . implode(' ', self::replaceKeywords($params['*'], $compiler)) . ") {\n" . Dwoo_Compiler::PHP_CLOSE;
$post = Dwoo_Compiler::PHP_OPEN . "\n}" . Dwoo_Compiler::PHP_CLOSE;
if (isset($params['hasElse'])) {
$post .= $params['hasElse'];
}
$block =& $compiler->getCurrentBlock();
$block['params']['hasElse'] = $pre . $content . $post;
return '';
}
示例14: compilerFactory
public static function compilerFactory()
{
if (!isset(static::$_instance_compiler)) {
static::$_instance_compiler = \Dwoo_Compiler::compilerFactory();
}
return static::$_instance_compiler;
}
示例15: Dwoo_Plugin_tif_compile
/**
* Ternary if operation
*
* It evaluates the first argument and returns the second if it's true, or the third if it's false
* <pre>
* * rest : you can not use named parameters to call this, use it either with three arguments in the correct order (expression, true result, false result) or write it as in php (expression ? true result : false result)
* </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.0.0
* @date 2008-10-23
* @package Dwoo
*/
function Dwoo_Plugin_tif_compile(Dwoo_Compiler $compiler, array $rest)
{
// load if plugin
if (!class_exists('Dwoo_Plugin_if', false)) {
try {
$compiler->getDwoo()->getLoader()->loadPlugin('if');
} catch (Exception $e) {
throw new Dwoo_Compilation_Exception($compiler, 'Tif: the if plugin is required to use Tif');
}
}
if (count($rest) == 1) {
return $rest[0];
}
// fetch false result and remove the ":" if it was present
$falseResult = array_pop($rest);
if (trim(end($rest), '"\'') === ':') {
// remove the ':' if present
array_pop($rest);
} elseif (trim(end($rest), '"\'') === '?' || count($rest) === 1) {
if ($falseResult === '?' || $falseResult === ':') {
throw new Dwoo_Compilation_Exception($compiler, 'Tif: incomplete tif statement, value missing after ' . $falseResult);
}
// there was in fact no false result provided, so we move it to be the true result instead
$trueResult = $falseResult;
$falseResult = "''";
}
// fetch true result if needed
if (!isset($trueResult)) {
$trueResult = array_pop($rest);
// no true result provided so we use the expression arg
if ($trueResult === '?') {
$trueResult = true;
}
}
// remove the '?' if present
if (trim(end($rest), '"\'') === '?') {
array_pop($rest);
}
// check params were correctly provided
if (empty($rest) || $trueResult === null || $falseResult === null) {
throw new Dwoo_Compilation_Exception($compiler, 'Tif: you must provide three parameters serving as <expression> ? <true value> : <false value>');
}
// parse condition
$condition = Dwoo_Plugin_if::replaceKeywords($rest, $compiler);
return '((' . implode(' ', $condition) . ') ? ' . ($trueResult === true ? implode(' ', $condition) : $trueResult) . ' : ' . $falseResult . ')';
}