- move getStreamVariable() into extension

This commit is contained in:
Uwe Tews
2015-06-28 05:00:27 +02:00
parent afe9af11b7
commit f4d7838a8f
3 changed files with 44 additions and 16 deletions

View File

@@ -4,6 +4,7 @@
- optimize security isTrustedResourceDir() - optimize security isTrustedResourceDir()
- move auto load filter methods into extension - move auto load filter methods into extension
- move $smarty->getTemplateVars() into extension - move $smarty->getTemplateVars() into extension
- move getStreamVariable() into extension
27.06.2015 27.06.2015
- bugfix resolve naming conflict between custom Smarty delimiter '<%' and PHP ASP tags https://github.com/smarty-php/smarty/issues/64 - bugfix resolve naming conflict between custom Smarty delimiter '<%' and PHP ASP tags https://github.com/smarty-php/smarty/issues/64

View File

@@ -325,21 +325,6 @@ class Smarty_Internal_Data
*/ */
public function getStreamVariable($variable) public function getStreamVariable($variable)
{ {
$_result = ''; return Smarty_Internal_Extension_GetStreamVar::getStreamVariable($this, $variable);
$fp = fopen($variable, 'r+');
if ($fp) {
while (!feof($fp) && ($current_line = fgets($fp)) !== false) {
$_result .= $current_line;
}
fclose($fp);
return $_result;
}
$smarty = isset($this->smarty) ? $this->smarty : $this;
if ($smarty->error_unassigned) {
throw new SmartyException('Undefined stream variable "' . $variable . '"');
} else {
return null;
}
} }
} }

View File

@@ -0,0 +1,42 @@
<?php
/**
* Smarty Extension GetStreamVar
*
* getStreamVariable() method
*
* @package Smarty
* @subpackage PluginsInternal
* @author Uwe Tews
*/
class Smarty_Internal_Extension_GetStreamVar
{
/**
* gets a stream variable
*
* @param $obj
* @param string $variable the stream of the variable
*
* @return mixed
* @throws \SmartyException
*/
public static function getStreamVariable($obj, $variable)
{
$_result = '';
$fp = fopen($variable, 'r+');
if ($fp) {
while (!feof($fp) && ($current_line = fgets($fp)) !== false) {
$_result .= $current_line;
}
fclose($fp);
return $_result;
}
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
if ($smarty->error_unassigned) {
throw new SmartyException('Undefined stream variable "' . $variable . '"');
} else {
return null;
}
}
}