Commit e7734ba8 by Jordi Boggiano

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

parent 68c813a5
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
+ Added {return} plugin that allows any included template to return + Added {return} plugin that allows any included template to return
variables into the one that included it, or to the main controller variables into the one that included it, or to the main controller
code via $dwoo->getReturnValues() 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 + 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 the Dwoo directory as an svn:externals without problems now and just
use Dwoo_Core in place of Dwoo in your code use Dwoo_Core in place of Dwoo in your code
......
...@@ -1360,7 +1360,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler ...@@ -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))) { } elseif (($first==='"' || $first==="'") && !(is_array($parsingParams) && preg_match('#^([\'"])[a-z0-9_]+\1\s*=>?(?:\s+|[^=])#i', $substr))) {
// string // string
$out = $this->parseString($in, $from, $to, $parsingParams, $curBlock, $pointer); $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 // func
$out = $this->parseFunction($in, $from, $to, $parsingParams, $curBlock, $pointer); $out = $this->parseFunction($in, $from, $to, $parsingParams, $curBlock, $pointer);
$parsed = 'func'; $parsed = 'func';
...@@ -1412,7 +1412,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler ...@@ -1412,7 +1412,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler
$parsingParams[] = $output; $parsingParams[] = $output;
return $parsingParams; 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 // static member access
$parsed = 'var'; $parsed = 'var';
if (is_array($parsingParams)) { if (is_array($parsingParams)) {
...@@ -1573,7 +1573,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler ...@@ -1573,7 +1573,7 @@ class Dwoo_Compiler implements Dwoo_ICompiler
protected function parseFunction($in, $from, $to, $parsingParams = false, $curBlock='', &$pointer = null) protected function parseFunction($in, $from, $to, $parsingParams = false, $curBlock='', &$pointer = null)
{ {
$cmdstr = substr($in, $from, $to-$from); $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])) { if (empty($match[1])) {
throw new Dwoo_Compilation_Exception($this, 'Parse error, invalid function name : '.substr($cmdstr, 0, 15)); throw new Dwoo_Compilation_Exception($this, 'Parse error, invalid function name : '.substr($cmdstr, 0, 15));
......
...@@ -719,6 +719,27 @@ fail ...@@ -719,6 +719,27 @@ fail
$this->assertEquals('_--10bar-test-_', $this->dwoo->get($tpl, array(), $this->compiler)); $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) { function excessArgsHelper($a) {
......
<?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