Commit e7f5d5b4 by Jordi Boggiano

Fixes #61: Allowing variable property reads

parent e7734ba8
......@@ -2097,11 +2097,6 @@ class Dwoo_Compiler implements Dwoo_ICompiler
// replace useless brackets by dot accessed vars and strip enclosing quotes if present
$key = preg_replace('#\[(["\']?)([^$%\[.>-]+)\1\]#', '.$2', $key);
// prevent $foo->$bar calls because it doesn't seem worth the trouble
if (strpos($key, '->$') !== false) {
throw new Dwoo_Compilation_Exception($this, 'You can not access an object\'s property using a variable name.');
}
if ($this->debug) {
if ($hasMethodCall) {
echo 'METHOD CALL FOUND : $'.$key.substr($methodCall, 0, 30).'<br />';
......
......@@ -23,6 +23,14 @@ class CompilerTests extends PHPUnit_Framework_TestCase
$this->assertEquals('bar', $this->dwoo->get($tpl, array('foo'=>'bar'), $this->compiler));
}
public function testVariableObjectPropertyAccess()
{
$tpl = new Dwoo_Template_String('{$obj->$var}');
$tpl->forceCompilation();
$this->assertEquals('yay', $this->dwoo->get($tpl, array('obj'=>new PluginHelper, 'var' => 'moo'), $this->compiler));
}
public function testComplexVarReplacement()
{
$tpl = new Dwoo_Template_String('{$_root[$a].0}{$_[$a][0]}{$_[$c.d].0}{$_.$a.0}{$_[$c[$x.0]].0}{$_[$c.$y.0].0}');
......
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