mirror of
https://github.com/Mibew/handlebars.php.git
synced 2024-11-15 08:44:12 +03:00
Merge pull request #45 from Mibew/safe_string
Add \Handlebars\SafeString class
This commit is contained in:
commit
0d90d4e294
78
src/Handlebars/BaseString.php
Normal file
78
src/Handlebars/BaseString.php
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of Handlebars-php
|
||||
*
|
||||
* PHP version 5.3
|
||||
*
|
||||
* @category Xamin
|
||||
* @package Handlebars
|
||||
* @author fzerorubigd <fzerorubigd@gmail.com>
|
||||
* @author Behrooz Shabani <everplays@gmail.com>
|
||||
* @author Dmitriy Simushev <simushevds@gmail.com>
|
||||
* @copyright 2013 Authors
|
||||
* @license MIT <http://opensource.org/licenses/MIT>
|
||||
* @version GIT: $Id$
|
||||
* @link http://xamin.ir
|
||||
*/
|
||||
|
||||
namespace Handlebars;
|
||||
|
||||
/**
|
||||
* Handlebars base string
|
||||
*
|
||||
* @category Xamin
|
||||
* @package Handlebars
|
||||
* @author fzerorubigd <fzerorubigd@gmail.com>
|
||||
* @copyright 2013 Authors
|
||||
* @license MIT <http://opensource.org/licenses/MIT>
|
||||
* @version Release: @package_version@
|
||||
* @link http://xamin.ir
|
||||
*/
|
||||
|
||||
class BaseString
|
||||
{
|
||||
private $_string;
|
||||
|
||||
/**
|
||||
* Create new string
|
||||
*
|
||||
* @param string $string input source
|
||||
*/
|
||||
public function __construct($string)
|
||||
{
|
||||
$this->_string = $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* To String
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->getString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getString()
|
||||
{
|
||||
return $this->_string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new string
|
||||
*
|
||||
* @param string $string input source
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setString($string)
|
||||
{
|
||||
$this->_string = $string;
|
||||
}
|
||||
|
||||
}
|
33
src/Handlebars/SafeString.php
Normal file
33
src/Handlebars/SafeString.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of Handlebars-php
|
||||
*
|
||||
* PHP version 5.3
|
||||
*
|
||||
* @category Xamin
|
||||
* @package Handlebars
|
||||
* @author Dmitriy Simushev <simushevds@gmail.com>
|
||||
* @copyright 2014 Authors
|
||||
* @license MIT <http://opensource.org/licenses/MIT>
|
||||
* @version GIT: $Id$
|
||||
* @link http://xamin.ir
|
||||
*/
|
||||
|
||||
namespace Handlebars;
|
||||
|
||||
/**
|
||||
* Handlebars safe string. Can be used in line helpers as wrapper for result to
|
||||
* indicate that there is no need to escape the result.
|
||||
*
|
||||
* @category Xamin
|
||||
* @package Handlebars
|
||||
* @author Dmitriy Simushev <simushevds@gmail.com>
|
||||
* @copyright 2014 Authors
|
||||
* @license MIT <http://opensource.org/licenses/MIT>
|
||||
* @version Release: @package_version@
|
||||
* @link http://xamin.ir
|
||||
*/
|
||||
|
||||
class SafeString extends BaseString
|
||||
{
|
||||
}
|
49
src/Handlebars/String.php
Executable file → Normal file
49
src/Handlebars/String.php
Executable file → Normal file
@ -8,6 +8,7 @@
|
||||
* @package Handlebars
|
||||
* @author fzerorubigd <fzerorubigd@gmail.com>
|
||||
* @author Behrooz Shabani <everplays@gmail.com>
|
||||
* @author Dmitriy Simushev <simushevds@gmail.com>
|
||||
* @copyright 2013 Authors
|
||||
* @license MIT <http://opensource.org/licenses/MIT>
|
||||
* @version GIT: $Id$
|
||||
@ -28,50 +29,6 @@ namespace Handlebars;
|
||||
* @link http://xamin.ir
|
||||
*/
|
||||
|
||||
class String
|
||||
class String extends BaseString
|
||||
{
|
||||
private $_string;
|
||||
|
||||
/**
|
||||
* Create new string
|
||||
*
|
||||
* @param string $string input source
|
||||
*/
|
||||
public function __construct($string)
|
||||
{
|
||||
$this->_string = $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* To String
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->getString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getString()
|
||||
{
|
||||
return $this->_string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new string
|
||||
*
|
||||
* @param string $string input source
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setString($string)
|
||||
{
|
||||
$this->_string = $string;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -408,7 +408,7 @@ class Template
|
||||
$current[Tokenizer::ARGS] = implode(' ', $args);
|
||||
$result = $this->_section($context, $current);
|
||||
|
||||
if ($escaped) {
|
||||
if ($escaped && !($result instanceof SafeString)) {
|
||||
$escape_args = $this->handlebars->getEscapeArgs();
|
||||
array_unshift($escape_args, $result);
|
||||
$result = call_user_func_array(
|
||||
|
@ -246,6 +246,11 @@ class HandlebarsTest extends \PHPUnit_Framework_TestCase
|
||||
});
|
||||
$this->assertEquals('<strong>Test</strong>', $engine->render('{{{markupHelper}}}', array()));
|
||||
$this->assertEquals('<strong>Test</strong>', $engine->render('{{markupHelper}}', array()));
|
||||
|
||||
$engine->addHelper('safeStringTest', function() {
|
||||
return new \Handlebars\SafeString('<strong>Test</strong>');
|
||||
});
|
||||
$this->assertEquals('<strong>Test</strong>', $engine->render('{{safeStringTest}}', array()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user