library/smarty/libs/sysplugins/smarty_internal_compile_private_function_plugin.php
changeset 46 f11c31f7fa3e
parent 45 a56e7f9a0463
child 47 03388ec805b4
equal deleted inserted replaced
45:a56e7f9a0463 46:f11c31f7fa3e
     1 <?php
       
     2 /**
       
     3  * Smarty Internal Plugin Compile Function Plugin
       
     4  * Compiles code for the execution of function plugin
       
     5  *
       
     6  * @package    Smarty
       
     7  * @subpackage Compiler
       
     8  * @author     Uwe Tews
       
     9  */
       
    10 
       
    11 /**
       
    12  * Smarty Internal Plugin Compile Function Plugin Class
       
    13  *
       
    14  * @package    Smarty
       
    15  * @subpackage Compiler
       
    16  */
       
    17 class Smarty_Internal_Compile_Private_Function_Plugin extends Smarty_Internal_CompileBase {
       
    18     /**
       
    19      * Attribute definition: Overwrites base class.
       
    20      *
       
    21      * @var array
       
    22      * @see Smarty_Internal_CompileBase
       
    23      */
       
    24     public $required_attributes = array();
       
    25     /**
       
    26      * Attribute definition: Overwrites base class.
       
    27      *
       
    28      * @var array
       
    29      * @see Smarty_Internal_CompileBase
       
    30      */
       
    31     public $optional_attributes = array('_any');
       
    32 
       
    33     /**
       
    34      * Compiles code for the execution of function plugin
       
    35      *
       
    36      * @param  array $args array with attributes from parser
       
    37      * @param  object $compiler compiler object
       
    38      * @param  array $parameter array with compilation parameter
       
    39      * @param  string $tag name of function plugin
       
    40      * @param  string $function PHP function name
       
    41      *
       
    42      * @return string compiled code
       
    43      */
       
    44     public function compile($args, $compiler, $parameter, $tag, $function) {
       
    45         // This tag does create output
       
    46         $compiler->has_output = true;
       
    47 
       
    48         // check and get attributes
       
    49         $_attr = $this->getAttributes($compiler, $args);
       
    50         if ($_attr['nocache'] === true) {
       
    51             $compiler->tag_nocache = true;
       
    52         }
       
    53         unset($_attr['nocache']);
       
    54         // convert attributes into parameter array string
       
    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         // compile code
       
    65         $output = "<?php echo {$function}({$_params},\$_smarty_tpl);?>\n";
       
    66 
       
    67         return $output;
       
    68     }
       
    69 }