mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-29 20:59:23 +02:00
ENHANCEMENT Added support for two arguments when calling object-methods with dot notation in templates (see #3292)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@69601 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
11d0491abf
commit
57f31fb09f
@ -395,6 +395,7 @@ class SSViewer extends Object {
|
|||||||
'/{\\$([A-Za-z_][A-Za-z0-9_]*)}/' => '<?= {dlr}item->XML_val("\\1",null,true) ?>\\2',
|
'/{\\$([A-Za-z_][A-Za-z0-9_]*)}/' => '<?= {dlr}item->XML_val("\\1",null,true) ?>\\2',
|
||||||
|
|
||||||
'/\\$([A-Za-z_][A-Za-z0-9_]*)\\.([A-Za-z0-9_]+)\\(([^),]+)\\)([^A-Za-z0-9]|$)/' => '<?= {dlr}item->obj("\\1")->XML_val("\\2",array("\\3"),true) ?>\\4',
|
'/\\$([A-Za-z_][A-Za-z0-9_]*)\\.([A-Za-z0-9_]+)\\(([^),]+)\\)([^A-Za-z0-9]|$)/' => '<?= {dlr}item->obj("\\1")->XML_val("\\2",array("\\3"),true) ?>\\4',
|
||||||
|
'/\\$([A-Za-z_][A-Za-z0-9_]*)\\.([A-Za-z0-9_]+)\\(([^),]+), *([^),]+)\\)([^A-Za-z0-9]|$)/' => '<?= {dlr}item->obj("\\1")->XML_val("\\2",array("\\3", "\\4"),true) ?>\\5',
|
||||||
|
|
||||||
'/\\$([A-Za-z_][A-Za-z0-9_]*)\\(([^),]+), *([^),]+)\\)\\.([A-Za-z0-9_]+)\\.([A-Za-z0-9_]+)([^A-Za-z0-9]|$)/' => '<?= {dlr}item->obj("\\1",array("\\2","\\3"),true)->obj("\\4",null,true)->XML_val("\\5",null,true) ?>\\6',
|
'/\\$([A-Za-z_][A-Za-z0-9_]*)\\(([^),]+), *([^),]+)\\)\\.([A-Za-z0-9_]+)\\.([A-Za-z0-9_]+)([^A-Za-z0-9]|$)/' => '<?= {dlr}item->obj("\\1",array("\\2","\\3"),true)->obj("\\4",null,true)->XML_val("\\5",null,true) ?>\\6',
|
||||||
'/\\$([A-Za-z_][A-Za-z0-9_]*)\\(([^),]+), *([^),]+)\\)\\.([A-Za-z0-9_]+)([^A-Za-z0-9]|$)/' => '<?= {dlr}item->obj("\\1",array("\\2","\\3"),true)->XML_val("\\4",null,true) ?>\\5',
|
'/\\$([A-Za-z_][A-Za-z0-9_]*)\\(([^),]+), *([^),]+)\\)\\.([A-Za-z0-9_]+)([^A-Za-z0-9]|$)/' => '<?= {dlr}item->obj("\\1",array("\\2","\\3"),true)->XML_val("\\4",null,true) ?>\\5',
|
||||||
|
@ -43,4 +43,40 @@ SS
|
|||||||
|
|
||||||
$this->assertEquals("This is my templateThis is some contentThis is the final content", preg_replace("/\n?<!--.*-->\n?/U",'',$output));
|
$this->assertEquals("This is my templateThis is some contentThis is the final content", preg_replace("/\n?<!--.*-->\n?/U",'',$output));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testObjectDotArguments() {
|
||||||
|
// one argument
|
||||||
|
$viewer = SSViewer::fromString(<<<SS
|
||||||
|
\$TestObject.methodWithOneArgument(one)
|
||||||
|
SS
|
||||||
|
);
|
||||||
|
$obj = new SSViewerTest_ViewableData();
|
||||||
|
$this->assertEquals(
|
||||||
|
$viewer->process(new ArrayData(array('TestObject'=>$obj))),
|
||||||
|
"arg1:one",
|
||||||
|
"Object method calls in dot notation work with one argument"
|
||||||
|
);
|
||||||
|
|
||||||
|
// two arguments
|
||||||
|
$viewer = SSViewer::fromString(<<<SS
|
||||||
|
\$TestObject.methodWithTwoArguments(one,two)
|
||||||
|
SS
|
||||||
|
);
|
||||||
|
$obj = new SSViewerTest_ViewableData();
|
||||||
|
$this->assertEquals(
|
||||||
|
$viewer->process(new ArrayData(array('TestObject'=>$obj))),
|
||||||
|
"arg1:one,arg2:two",
|
||||||
|
"Object method calls in dot notation work with two arguments"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class SSViewerTest_ViewableData extends ViewableData implements TestOnly {
|
||||||
|
function methodWithOneArgument($arg1) {
|
||||||
|
return "arg1:{$arg1}";
|
||||||
|
}
|
||||||
|
|
||||||
|
function methodWithTwoArguments($arg1, $arg2) {
|
||||||
|
return "arg1:{$arg1},arg2:{$arg2}";
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user