]> git.mxchange.org Git - friendica.git/blob - vendor/smarty/smarty/libs/sysplugins/smarty_internal_method_getstreamvariable.php
Add Smarty to Composer
[friendica.git] / vendor / smarty / smarty / libs / sysplugins / smarty_internal_method_getstreamvariable.php
1 <?php
2
3 /**
4  * Smarty Method GetStreamVariable
5  *
6  * Smarty::getStreamVariable() method
7  *
8  * @package    Smarty
9  * @subpackage PluginsInternal
10  * @author     Uwe Tews
11  */
12 class Smarty_Internal_Method_GetStreamVariable
13 {
14     /**
15      * Valid for all objects
16      *
17      * @var int
18      */
19     public $objMap = 7;
20
21     /**
22      * gets  a stream variable
23      *
24      * @api Smarty::getStreamVariable()
25      *
26      * @param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data
27      * @param  string                                                 $variable the stream of the variable
28      *
29      * @return mixed
30      * @throws \SmartyException
31      */
32     public function getStreamVariable(Smarty_Internal_Data $data, $variable)
33     {
34         $_result = '';
35         $fp = fopen($variable, 'r+');
36         if ($fp) {
37             while (!feof($fp) && ($current_line = fgets($fp)) !== false) {
38                 $_result .= $current_line;
39             }
40             fclose($fp);
41
42             return $_result;
43         }
44         $smarty = isset($data->smarty) ? $data->smarty : $data;
45         if ($smarty->error_unassigned) {
46             throw new SmartyException('Undefined stream variable "' . $variable . '"');
47         } else {
48             return null;
49         }
50     }
51 }