Skip to content

Commit

Permalink
Merge pull request #40 from baileylo/master
Browse files Browse the repository at this point in the history
Allow batch functionality from escape functions
  • Loading branch information
reinink committed Oct 21, 2014
2 parents 22ae882 + 5f26027 commit 10ce61b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Template/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,12 @@ protected function batch($var, $functions)
*/
protected function escape($string)
{
$functions = array_slice(func_get_args(), 1);

if ($functions) {
$string = $this->batch($string, implode('|', $functions));
}

return htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
}

Expand All @@ -278,7 +284,7 @@ protected function escape($string)
*/
protected function e($string)
{
return $this->escape($string);
return call_user_func_array(array($this, 'escape'), func_get_args());
}
}

Expand Down
11 changes: 11 additions & 0 deletions tests/Template/TemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,17 @@ public function testEscapeFunction()
$this->assertEquals($this->template->render(), '<strong>Jonathan</strong>');
}

public function testEscapeFunctionBatch()
{
vfsStream::create(
array(
'template.php' => '<?php echo $this->escape("<strong>Jonathan</strong>", "strtoupper", "strrev") ?>'
)
);

$this->assertEquals($this->template->render(), '&gt;GNORTS/&lt;NAHTANOJ&gt;GNORTS&lt;');
}

public function testEscapeShortcutFunction()
{
vfsStream::create(
Expand Down

0 comments on commit 10ce61b

Please sign in to comment.