Commit e7734ba8 by Jordi Boggiano

Fixes #74: Added support for static vars and methods access on namespaced classes

parent 68c813a5
......@@ -15,6 +15,7 @@
+ Added {return} plugin that allows any included template to return
variables into the one that included it, or to the main controller
code via $dwoo->getReturnValues()
+ Added support for static vars and methods access on namespaced classes
+ Moved Dwoo code to Dwoo_Core that is extended by Dwoo, so you can use
the Dwoo directory as an svn:externals without problems now and just
use Dwoo_Core in place of Dwoo in your code
......
......@@ -1360,7 +1360,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler
} elseif (($first==='"' || $first==="'") && !(is_array($parsingParams) && preg_match('#^([\'"])[a-z0-9_]+\1\s*=>?(?:\s+|[^=])#i', $substr))) {
// string
$out = $this->parseString($in, $from, $to, $parsingParams, $curBlock, $pointer);
} 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)) {
} 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);
$parsed = 'func';
......@@ -1412,7 +1412,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler
$parsingParams[] = $output;
return $parsingParams;
} elseif (preg_match('#^([a-z0-9_]+::\$[a-z0-9_]+)#i', $substr, $match)) {
} elseif (preg_match('#^(\\\\?[a-z_](?:\\\\?[a-z0-9_]+)*::\$[a-z0-9_]+)#i', $substr, $match)) {
// static member access
$parsed = 'var';
if (is_array($parsingParams)) {
......@@ -1573,7 +1573,7 @@ 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_]*(?:::[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 : '.substr($cmdstr, 0, 15));
......
......@@ -711,14 +711,35 @@ fail
$tpl->forceCompilation();
$this->assertEquals('testtest', $this->dwoo->get($tpl, array('obj'=>new PluginHelper()), $this->compiler));
}
public function testFunctionCanStartWithUnderscore()
{
$tpl = new Dwoo_Template_String('{_underscoreHelper("test", _underscoreHelper("bar", 10))|_underscoreModifierHelper}');
$tpl->forceCompilation();
$this->assertEquals('_--10bar-test-_', $this->dwoo->get($tpl, array(), $this->compiler));
}
public function testNamespaceStaticMethodAccess()
{
if (version_compare(phpversion(), '5.3.0', '<')) {
$this->markTestSkipped();
}
include_once __DIR__.'/resources/namespace.php';
$tpl = new Dwoo_Template_String('{\Dwoo\TestHelper::execute(foo)}');
$tpl->forceCompilation();
$this->assertEquals('foo', $this->dwoo->get($tpl, array()));
}
public function testNamespaceStaticVarAccess()
{
if (version_compare(phpversion(), '5.3.0', '<')) {
$this->markTestSkipped();
}
include_once __DIR__.'/resources/namespace.php';
$tpl = new Dwoo_Template_String('{\Dwoo\TestHelper::$var}');
$tpl->forceCompilation();
$this->assertEquals('foo', $this->dwoo->get($tpl, array()));
}
}
function excessArgsHelper($a) {
......@@ -837,11 +858,11 @@ class MethodCallsHelper
public static function staticFoo($bar, $baz) {
return "-$baz$bar-";
}
public function _foo($bar, $baz) {
return "-$baz$bar-";
}
public function _fooChain() {
return $this;
}
......
<?php
namespace Dwoo;
class TestHelper {
public static $var = 'foo';
public static function execute($arg) {
return $arg;
}
}
\ No newline at end of file
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