mirror of
https://github.com/Mibew/handlebars.php.git
synced 2025-05-03 10:33:08 +03:00
Replace String class with StringWrapper one
This commit is contained in:
parent
a47d7e0fb2
commit
33ec96a1b4
@ -155,26 +155,26 @@ class Arguments
|
|||||||
/**
|
/**
|
||||||
* Prepares argument's value to add to arguments list.
|
* Prepares argument's value to add to arguments list.
|
||||||
*
|
*
|
||||||
* The method unescapes value and wrap it into \Handlebars\String class if
|
* The method unescapes value and wrap it into \Handlebars\StringWrapper
|
||||||
* needed.
|
* class if needed.
|
||||||
*
|
*
|
||||||
* @param string $value Argument's value
|
* @param string $value Argument's value
|
||||||
*
|
*
|
||||||
* @return string|\Handlebars\String
|
* @return string|\Handlebars\StringWrapper
|
||||||
*/
|
*/
|
||||||
protected function prepareArgumentValue($value)
|
protected function prepareArgumentValue($value)
|
||||||
{
|
{
|
||||||
// Check if argument's value is a quoted string literal
|
// Check if argument's value is a quoted string literal
|
||||||
if ($value[0] == "'" || $value[0] == '"') {
|
if ($value[0] == "'" || $value[0] == '"') {
|
||||||
// Remove enclosing quotes and unescape
|
// Remove enclosing quotes and unescape
|
||||||
return new String(stripcslashes(substr($value, 1, -1)));
|
return new StringWrapper(stripcslashes(substr($value, 1, -1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the value is an integer literal
|
// Check if the value is an integer literal
|
||||||
if (preg_match("/^-?\d+$/", $value)) {
|
if (preg_match("/^-?\d+$/", $value)) {
|
||||||
// Wrap the value into the String class to tell the Context that
|
// Wrap the value into the String class to tell the Context that
|
||||||
// it's a value and not a variable name.
|
// it's a value and not a variable name.
|
||||||
return new String($value);
|
return new StringWrapper($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $value;
|
return $value;
|
||||||
|
@ -185,7 +185,7 @@ class Context
|
|||||||
*/
|
*/
|
||||||
public function get($variableName, $strict = false)
|
public function get($variableName, $strict = false)
|
||||||
{
|
{
|
||||||
if ($variableName instanceof \Handlebars\String) {
|
if ($variableName instanceof \Handlebars\StringWrapper) {
|
||||||
return (string)$variableName;
|
return (string)$variableName;
|
||||||
}
|
}
|
||||||
$variableName = trim($variableName);
|
$variableName = trim($variableName);
|
||||||
|
6
src/Handlebars/Loader/FilesystemLoader.php
Executable file → Normal file
6
src/Handlebars/Loader/FilesystemLoader.php
Executable file → Normal file
@ -24,7 +24,7 @@
|
|||||||
namespace Handlebars\Loader;
|
namespace Handlebars\Loader;
|
||||||
|
|
||||||
use Handlebars\Loader;
|
use Handlebars\Loader;
|
||||||
use Handlebars\String;
|
use Handlebars\StringWrapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handlebars Template filesystem Loader implementation.
|
* Handlebars Template filesystem Loader implementation.
|
||||||
@ -76,7 +76,7 @@ class FilesystemLoader implements Loader
|
|||||||
*
|
*
|
||||||
* @param string $name template name
|
* @param string $name template name
|
||||||
*
|
*
|
||||||
* @return String Handlebars Template source
|
* @return StringWrapper Handlebars Template source
|
||||||
*/
|
*/
|
||||||
public function load($name)
|
public function load($name)
|
||||||
{
|
{
|
||||||
@ -84,7 +84,7 @@ class FilesystemLoader implements Loader
|
|||||||
$this->_templates[$name] = $this->loadFile($name);
|
$this->_templates[$name] = $this->loadFile($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new String($this->_templates[$name]);
|
return new StringWrapper($this->_templates[$name]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
6
src/Handlebars/Loader/StringLoader.php
Executable file → Normal file
6
src/Handlebars/Loader/StringLoader.php
Executable file → Normal file
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
namespace Handlebars\Loader;
|
namespace Handlebars\Loader;
|
||||||
use Handlebars\Loader;
|
use Handlebars\Loader;
|
||||||
use Handlebars\String;
|
use Handlebars\StringWrapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handlebars Template string Loader implementation.
|
* Handlebars Template string Loader implementation.
|
||||||
@ -42,11 +42,11 @@ class StringLoader implements Loader
|
|||||||
*
|
*
|
||||||
* @param string $name Handlebars Template source
|
* @param string $name Handlebars Template source
|
||||||
*
|
*
|
||||||
* @return String Handlebars Template source
|
* @return StringWrapper Handlebars Template source
|
||||||
*/
|
*/
|
||||||
public function load($name)
|
public function load($name)
|
||||||
{
|
{
|
||||||
return new String($name);
|
return new StringWrapper($name);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,8 +27,9 @@ namespace Handlebars;
|
|||||||
* @license MIT <http://opensource.org/licenses/MIT>
|
* @license MIT <http://opensource.org/licenses/MIT>
|
||||||
* @version Release: @package_version@
|
* @version Release: @package_version@
|
||||||
* @link http://xamin.ir
|
* @link http://xamin.ir
|
||||||
|
* @deprecated Since v0.10.3. Use \Handlebars\StringWrapper instead.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class String extends BaseString
|
class String extends StringWrapper
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
34
src/Handlebars/StringWrapper.php
Normal file
34
src/Handlebars/StringWrapper.php
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?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 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 StringWrapper extends BaseString
|
||||||
|
{
|
||||||
|
}
|
@ -381,7 +381,7 @@ class Template
|
|||||||
|
|
||||||
$return = $helpers->call($sectionName, $this, $context, $current[Tokenizer::ARGS], $source);
|
$return = $helpers->call($sectionName, $this, $context, $current[Tokenizer::ARGS], $source);
|
||||||
|
|
||||||
if ($return instanceof String) {
|
if ($return instanceof StringWrapper) {
|
||||||
return $this->handlebars->loadString($return)->render($context);
|
return $this->handlebars->loadString($return)->render($context);
|
||||||
} else {
|
} else {
|
||||||
return $return;
|
return $return;
|
||||||
|
@ -122,7 +122,7 @@ class Tokenizer
|
|||||||
*/
|
*/
|
||||||
public function scan($text/*, $delimiters = null*/)
|
public function scan($text/*, $delimiters = null*/)
|
||||||
{
|
{
|
||||||
if ($text instanceof String) {
|
if ($text instanceof StringWrapper) {
|
||||||
$text = $text->getString();
|
$text = $text->getString();
|
||||||
}
|
}
|
||||||
$this->reset();
|
$this->reset();
|
||||||
|
@ -395,7 +395,7 @@ class HandlebarsTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('Test helper is called with a b c', $engine->render('{{test2 a b c}}', array()));
|
$this->assertEquals('Test helper is called with a b c', $engine->render('{{test2 a b c}}', array()));
|
||||||
|
|
||||||
$engine->addHelper('renderme', function () {
|
$engine->addHelper('renderme', function () {
|
||||||
return new \Handlebars\String("{{test}}");
|
return new \Handlebars\StringWrapper("{{test}}");
|
||||||
});
|
});
|
||||||
$this->assertEquals('Test helper is called', $engine->render('{{#renderme}}', array()));
|
$this->assertEquals('Test helper is called', $engine->render('{{#renderme}}', array()));
|
||||||
|
|
||||||
@ -568,9 +568,9 @@ class HandlebarsTest extends \PHPUnit_Framework_TestCase
|
|||||||
/**
|
/**
|
||||||
* test String class
|
* test String class
|
||||||
*/
|
*/
|
||||||
public function testStringClass()
|
public function testStringWrapperClass()
|
||||||
{
|
{
|
||||||
$string = new \Handlebars\String('test');
|
$string = new \Handlebars\StringWrapper('test');
|
||||||
$this->assertEquals('test', $string->getString());
|
$this->assertEquals('test', $string->getString());
|
||||||
$string->setString('new');
|
$string->setString('new');
|
||||||
$this->assertEquals('new', $string->getString());
|
$this->assertEquals('new', $string->getString());
|
||||||
@ -1096,7 +1096,7 @@ EOM;
|
|||||||
|
|
||||||
public function testString()
|
public function testString()
|
||||||
{
|
{
|
||||||
$string = new \Handlebars\String("Hello World");
|
$string = new \Handlebars\StringWrapper("Hello World");
|
||||||
$this->assertEquals((string)$string, "Hello World");
|
$this->assertEquals((string)$string, "Hello World");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user