]> git.mxchange.org Git - friendica.git/blob - vendor/smarty/smarty/libs/sysplugins/smarty_internal_compile_private_object_function.php
Merge pull request #4233 from MrPetovan/task/4116-move-smarty-to-composer
[friendica.git] / vendor / smarty / smarty / libs / sysplugins / smarty_internal_compile_private_object_function.php
1 <?php
2 /**
3  * Smarty Internal Plugin Compile Object Function
4  * Compiles code for registered objects as function
5  *
6  * @package    Smarty
7  * @subpackage Compiler
8  * @author     Uwe Tews
9  */
10
11 /**
12  * Smarty Internal Plugin Compile Object Function Class
13  *
14  * @package    Smarty
15  * @subpackage Compiler
16  */
17 class Smarty_Internal_Compile_Private_Object_Function extends Smarty_Internal_CompileBase
18 {
19     /**
20      * Attribute definition: Overwrites base class.
21      *
22      * @var array
23      * @see Smarty_Internal_CompileBase
24      */
25     public $optional_attributes = array('_any');
26
27     /**
28      * Compiles code for the execution of function plugin
29      *
30      * @param  array                                $args      array with attributes from parser
31      * @param \Smarty_Internal_TemplateCompilerBase $compiler  compiler object
32      * @param  array                                $parameter array with compilation parameter
33      * @param  string                               $tag       name of function
34      * @param  string                               $method    name of method to call
35      *
36      * @return string compiled code
37      */
38     public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter, $tag, $method)
39     {
40         // check and get attributes
41         $_attr = $this->getAttributes($compiler, $args);
42         //Does tag create output
43         $compiler->has_output = isset($_attr[ 'assign' ]) ? false : true;
44
45         unset($_attr[ 'nocache' ]);
46         $_assign = null;
47         if (isset($_attr[ 'assign' ])) {
48             $_assign = $_attr[ 'assign' ];
49             unset($_attr[ 'assign' ]);
50         }
51         // method or property ?
52         if (is_callable(array($compiler->smarty->registered_objects[ $tag ][ 0 ], $method))) {
53             // convert attributes into parameter array string
54             if ($compiler->smarty->registered_objects[ $tag ][ 2 ]) {
55                 $_paramsArray = array();
56                 foreach ($_attr as $_key => $_value) {
57                     if (is_int($_key)) {
58                         $_paramsArray[] = "$_key=>$_value";
59                     } else {
60                         $_paramsArray[] = "'$_key'=>$_value";
61                     }
62                 }
63                 $_params = 'array(' . implode(",", $_paramsArray) . ')';
64                 $output = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}({$_params},\$_smarty_tpl)";
65             } else {
66                 $_params = implode(",", $_attr);
67                 $output = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}({$_params})";
68             }
69         } else {
70             // object property
71             $output = "\$_smarty_tpl->smarty->registered_objects['{$tag}'][0]->{$method}";
72         }
73         if (!empty($parameter[ 'modifierlist' ])) {
74             $output = $compiler->compileTag('private_modifier', array(),
75                                             array('modifierlist' => $parameter[ 'modifierlist' ], 'value' => $output));
76         }
77         //Does tag create output
78         $compiler->has_output = isset($_attr[ 'assign' ]) ? false : true;
79
80         if (empty($_assign)) {
81             return "<?php echo {$output};?>\n";
82         } else {
83             return "<?php \$_smarty_tpl->assign({$_assign},{$output});?>\n";
84         }
85     }
86 }