Commit e3eb1b76 by Seldaek

+ Syntax: Static methods can be called using {Class::method()}

git-svn-id: svn://dwoo.org/dwoo/trunk@122 0598d79b-80c4-4d41-97ba-ac86fbbd088b
parent 5fc48230
......@@ -4,10 +4,13 @@
{if $foo}> {$foo}{$bar}{/} - This also allow block operations such as:
{a http://url.com; "Text" /} which equals to {a http://url.com}Text{/}
+ Syntax: Block plugins that you want to call without content can be
self-closed just like XML tags (e.g. {a "http://url.com" /} )
self-closed just like XML tags (e.g. {a "http://url.com" /} ). Be careful not
to close a non-block plugin like that however, since it will close it's
parent block
+ Plugins: Added the {a} block plugin to generate <a> tags
+ API: Added Dwoo_Plugin::paramsToAttributes() utility function to help
with the creation of compilable xml/html-related plugins
+ Syntax: Static methods can be called using {Class::method()}
* Syntax: Math expressions in strings are now only allowed when the entire
expression is delimited, e.g. {"/$foo/$bar"} evaluates as just that while
{"/`$foo/$bar`"} will result in "/".($foo/$bar), therefore processing the /
......
-----------------------------------------------------------------------------
-- 0.9.2
-- Upgrading to Dwoo v0.9.2
-----------------------------------------------------------------------------
1. Block plugins
......
......@@ -1105,7 +1105,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler
} elseif ($first==='"' || $first==="'") {
// string
$out = $this->parseString($in, $from, $to, $parsingParams, $curBlock, $pointer);
} elseif (preg_match('/^[a-z][a-z0-9_]*('.(is_array($parsingParams)||$curBlock!='root'?'':'\s+[^(]|').'\s*\(|\s*'.$this->rdr.'|\s*;)/i', $substr)) {
} elseif (preg_match('/^[a-z][a-z0-9_]*(?:::[a-z][a-z0-9_]*)?('.(is_array($parsingParams)||$curBlock!='root'?'':'\s+[^(]|').'\s*\(|\s*'.$this->rdr.'|\s*;)/i', $substr)) {
// func
$out = $this->parseFunction($in, $from, $to, $parsingParams, $curBlock, $pointer);
} elseif ($first === ';') {
......@@ -1178,13 +1178,19 @@ class Dwoo_Compiler implements Dwoo_ICompiler
protected function parseFunction($in, $from, $to, $parsingParams = false, $curBlock='', &$pointer = null)
{
$cmdstr = substr($in, $from, $to-$from);
preg_match('/^([a-z][a-z0-9_]*)(\s*'.$this->rdr.'|\s*;)?/i', $cmdstr, $match);
preg_match('/^([a-z][a-z0-9_]*(?:::[a-z][a-z0-9_]*)?)(\s*'.$this->rdr.'|\s*;)?/i', $cmdstr, $match);
if (empty($match[1])) {
throw new Dwoo_Compilation_Exception($this, 'Parse error, invalid function name');
}
$func = $match[1];
if (!empty($match[2])) {
$cmdstr = $match[1];
}
if ($this->debug) echo 'FUNC FOUND<br />';
if ($this->debug) echo 'FUNC FOUND ('.$func.')<br />';
$paramsep = '';
......@@ -1210,18 +1216,12 @@ class Dwoo_Compiler implements Dwoo_ICompiler
$state = 0;
if ($paramspos === false) {
if (strpos($cmdstr, ' ')) {
$func = substr($cmdstr, 0, strpos($cmdstr, ' '));
} else {
$func = $cmdstr;
}
$params = array();
if ($curBlock !== 'root') {
return $this->parseOthers($in, $from, $to, $parsingParams, $curBlock, $pointer);
}
} else {
$func = rtrim(substr($cmdstr, 0, $paramspos));
$whitespace = strlen(substr($cmdstr, strlen($func), $paramspos-strlen($func)));
$paramstr = substr($cmdstr, $paramspos+1);
if (substr($paramstr, -1, 1) === $paramsep) {
......@@ -1300,7 +1300,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler
if ($this->debug) echo 'FUNC ADDS '.((isset($paramstr) ? strlen($paramstr) : 0) + (')' === $paramsep ? 2 : ($paramspos === false ? 0 : 1)) + strlen($func)).' TO POINTER<br/>';
}
if ($curBlock === 'method' || $func === 'do') {
if ($curBlock === 'method' || $func === 'do' || strstr($func, '::') !== false) {
$pluginType = Dwoo::NATIVE_PLUGIN;
} else {
$pluginType = $this->getPluginType($func);
......
......@@ -527,6 +527,14 @@ replace="BAR"
$this->assertEquals('a <?php echo "foo"; ?>', $this->dwoo->get($tpl, array('foo'=>'a <?php echo "foo"; ?>'), $this->compiler));
}
public function testStaticMethodCall()
{
$tpl = new Dwoo_Template_String('{upper MethodCallsHelper::staticFoo(bar "baz")}');
$tpl->forceCompilation();
$this->assertEquals('-BAZBAR-', $this->dwoo->get($tpl, array(), $this->compiler));
}
}
class MethodCallsHelper {
......@@ -551,4 +559,8 @@ class MethodCallsHelper {
return ($int+5).$str;
}
public function __toString() { return 'obj'; }
public static function staticFoo($bar, $baz) {
return "-$baz$bar-";
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment