[limb-svn] r6504 - in 3.x/trunk/limb/macro: src src/filters tests/cases
svn at limb-project.com
svn at limb-project.com
Thu Nov 8 13:53:24 MSK 2007
Author: serega
Date: 2007-11-08 13:53:24 +0300 (Thu, 08 Nov 2007)
New Revision: 6504
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6504
Added:
3.x/trunk/limb/macro/src/filters/strtoupper.filter.php
Modified:
3.x/trunk/limb/macro/src/lmbMacroExpression.class.php
3.x/trunk/limb/macro/tests/cases/lmbMacroOutputExpressionTest.class.php
Log:
-- better analizer in lmbMacroExpression. Now we use token_get_all instead of regular expressions.
-- since we use token_get_all, now we can use any php-code in function calls in expressions
-- strtoupper filter added
Added: 3.x/trunk/limb/macro/src/filters/strtoupper.filter.php
===================================================================
--- 3.x/trunk/limb/macro/src/filters/strtoupper.filter.php (rev 0)
+++ 3.x/trunk/limb/macro/src/filters/strtoupper.filter.php 2007-11-08 10:53:24 UTC (rev 6504)
@@ -0,0 +1,15 @@
+<?php
+/**
+ * class lmbMacroStrToUpperFilter.
+ *
+ * @filter strtoupper
+ * @package macro
+ * @version $Id$
+ */
+class lmbMacroStrToUpperFilter extends lmbMacroFilter
+{
+ function getValue()
+ {
+ return 'strtoupper(' . $this->base->getValue() . ')';
+ }
+}
Modified: 3.x/trunk/limb/macro/src/lmbMacroExpression.class.php
===================================================================
--- 3.x/trunk/limb/macro/src/lmbMacroExpression.class.php 2007-11-08 10:05:03 UTC (rev 6503)
+++ 3.x/trunk/limb/macro/src/lmbMacroExpression.class.php 2007-11-08 10:53:24 UTC (rev 6504)
@@ -18,10 +18,6 @@
{
protected $tmp;
- // used for parsing expression path items
- protected $text;
- protected $position;
-
function __construct($expression_str)
{
$this->expression_str = $expression_str;
@@ -40,6 +36,7 @@
}
$expr = '';
+
$items = $this->_extractExpressionPathItems($this->expression_str);
//first item is variable itself
@@ -65,42 +62,38 @@
protected function _extractExpressionPathItems($text)
{
- $this->text = $text;
- $length = strlen($text);
+ $tokens = token_get_all('<?php ' . $text . '?>');
+ // removing first and last tokens since we just added them with the line above
+ array_shift($tokens);
+ array_pop($tokens);
$path_items = array();
- do
+ $in_function = false;
+
+ $item = '';
+ foreach($tokens as $token)
{
- $token = $this->_getToken('/\G("|\'|\.|[^\'"\.]+)/u');
- if ($token === FALSE)
+ if(is_scalar($token))
{
- $path_items[] = $this->text;
- break;
+ if($token == '(')
+ $in_function = true;
+ if($token == ')')
+ $in_function = false;
+ if($token == '.' && !$in_function)
+ {
+ $path_items[] = $item;
+ $item = '';
+ continue;
+ }
+
+ $item .= $token;
}
-
- if ($token == '"' || $token == "'")
- {
- $string = $this->_getToken('/\G([^' . $token . ']*)' . $token . ',?/u');
-
- if ($string === FALSE)
- $this->context->raise("Expecting a closing quote in expression path item: " . $text);
- }
- elseif($token == '.')
- {
- $path_items[] = substr($this->text, 0, $this->position - 1);
- $this->text = substr($this->text, $this->position);
- $length = strlen($this->text);
- $this->position = 0;
- }
+ else
+ $item .= $token[1];
}
- while($this->position < $length);
-
- //ensures the last filter expression added
- $path_items[] = substr($this->text, 0, $this->position );
- $this->text = substr($this->text, $this->position);
- $length = strlen($this->text);
- $this->position = 0;
-
+
+ $path_items[] = $item;
+
return $path_items;
}
@@ -108,16 +101,5 @@
{
return $this->tmp;
}
-
- protected function _getToken($pattern)
- {
- if (preg_match($pattern, $this->text, $match, PREG_OFFSET_CAPTURE, $this->position))
- {
- $this->position += strlen($match[0][0]);
- return $match[1][0];
- }
- else
- return FALSE;
- }
}
Modified: 3.x/trunk/limb/macro/tests/cases/lmbMacroOutputExpressionTest.class.php
===================================================================
--- 3.x/trunk/limb/macro/tests/cases/lmbMacroOutputExpressionTest.class.php 2007-11-08 10:05:03 UTC (rev 6503)
+++ 3.x/trunk/limb/macro/tests/cases/lmbMacroOutputExpressionTest.class.php 2007-11-08 10:53:24 UTC (rev 6504)
@@ -187,24 +187,26 @@
$this->assertEqual($out, '<h1>}</h1>');
}
- function ToDo_testComplexVariableWithPathsInInFuncParamsInOutputExpression()
+ // Test that concat operation in function call is just concat operation
+ function testComplexFuncParamsWithConcatOperationInOutputExpression()
{
- $code = '<h1>{$#bar->func2($#foo.var1, $#foo.var2).extra}</h1>';
+ $code = '<h1>{$#bar->func3($#foo["var1.var3"]["var"] . $#foo["var2"]).extra}</h1>';
$tpl = $this->_createMacroTemplate($code, 'tpl.html');
$tpl->set('bar', new lmbMacroOutputExpressionTestClass());
- $tpl->set('foo', array('var1' => 10, 'var2' => 20));
+ $tpl->set('foo', $var = array('var1.var3' => 10, 'var2' => 20));
+
$out = $tpl->render();
- $this->assertEqual($out, '<h1>10 - 20</h1>');
+ $this->assertEqual($out, '<h1>20</h1>');
}
- function ToDo_testNestedExpressionPaths()
+ function testNestedExpressionPaths()
{
- $code = '<h1>{$#bar->func2($#foo.func2(10, 20), "aaa")}</h1>';
+ $code = '<h1>{$#bar->func2($#foo->func2(10, 20), "aaa")}</h1>';
$tpl = $this->_createMacroTemplate($code, 'tpl.html');
$tpl->set('bar', new lmbMacroOutputExpressionTestClass());
$tpl->set('foo', new lmbMacroOutputExpressionTestClass());
$out = $tpl->render();
- $this->assertEqual($out, '<h1>10 - 20 - "aaa"</h1>');
+ $this->assertEqual($out, '<h1>10 - 20 - aaa</h1>');
}
}
More information about the limb-svn
mailing list