Change some function names
Signed-off-by: Atul Pratap Singh <atulpratapsingh05@gmail.com>
This commit is contained in:
parent
4e35951b70
commit
e1a8fc758a
@ -75,25 +75,21 @@ class Template
|
||||
return preg_replace($regexp, "$1$2", $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets data to be used by this template
|
||||
*
|
||||
* @param array $data containing data entries
|
||||
*/
|
||||
public function setData($data = array())
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds more entries to the data for this template
|
||||
*
|
||||
* @param array $data containing data entries
|
||||
* @param array|string $data containing data array or data key
|
||||
* @param string $value containing data value
|
||||
*/
|
||||
public function addData($data = array())
|
||||
public function set($data, $value = null)
|
||||
{
|
||||
foreach ($data as $key => $value) {
|
||||
$this->data[$key] = $value;
|
||||
if(is_array($data) && ! $value) {
|
||||
$this->data = array_merge(
|
||||
$this->data,
|
||||
$data
|
||||
);
|
||||
} else if (is_string($data)) {
|
||||
$this->data[$data] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
@ -103,7 +99,7 @@ class Template
|
||||
* @param string $funcName function name
|
||||
* @param callable $funcDef function definition
|
||||
*/
|
||||
public function addFunction($funcName, $funcDef)
|
||||
public function setHelper($funcName, $funcDef)
|
||||
{
|
||||
if (! isset($this->helperFunctions[$funcName])) {
|
||||
$this->helperFunctions[$funcName] = $funcDef;
|
||||
@ -119,7 +115,7 @@ class Template
|
||||
*
|
||||
* @param string $funcName function name
|
||||
*/
|
||||
public function removeFunction($funcName)
|
||||
public function removeHelper($funcName)
|
||||
{
|
||||
if (isset($this->helperFunctions[$funcName])) {
|
||||
unset($this->helperFunctions[$funcName]);
|
||||
@ -160,7 +156,7 @@ class Template
|
||||
{
|
||||
$template = static::BASE_PATH . $this->name . '.phtml';
|
||||
try {
|
||||
$this->addData($data);
|
||||
$this->set($data);
|
||||
extract($this->data);
|
||||
$this->helperFunctions = array_merge(
|
||||
$this->helperFunctions,
|
||||
|
||||
@ -16,35 +16,15 @@ require_once 'test/PMATestCase.php';
|
||||
class TemplateTest extends PMATestCase
|
||||
{
|
||||
/**
|
||||
* Test for setData
|
||||
* Test for set function
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSetData()
|
||||
{
|
||||
$template = PMA\libraries\Template::get('test/echo');
|
||||
$template->setData(
|
||||
array(
|
||||
'variable' => 'value'
|
||||
)
|
||||
);
|
||||
$this->assertEquals('value', $template->render());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for addData
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddData()
|
||||
public function testSet()
|
||||
{
|
||||
$template = PMA\libraries\Template::get('test/add_data');
|
||||
$template->addData(
|
||||
array(
|
||||
'variable1' => 'value1'
|
||||
)
|
||||
);
|
||||
$template->addData(
|
||||
$template->set('variable1', 'value1');
|
||||
$template->set(
|
||||
array(
|
||||
'variable2' => 'value2'
|
||||
)
|
||||
@ -55,17 +35,17 @@ class TemplateTest extends PMATestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for addFunction
|
||||
* Test for setHelper
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testAddFunction()
|
||||
public function testSetHelper()
|
||||
{
|
||||
$template = PMA\libraries\Template::get('test/add_function');
|
||||
$template->addFunction('hello', function ($string) {
|
||||
$template = PMA\libraries\Template::get('test/set_helper');
|
||||
$template->setHelper('hello', function ($string) {
|
||||
return 'hello ' . $string;
|
||||
});
|
||||
$template->addData(
|
||||
$template->set(
|
||||
array(
|
||||
'variable' => 'world'
|
||||
)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user