PageRenderTime 12ms CodeModel.GetById 2ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/framework/vendor/smarty3/lib/libs/sysplugins/smarty_internal_compile_private_registered_function.php

http://zoop.googlecode.com/
PHP | 59 lines | 31 code | 2 blank | 26 comment | 6 complexity | 8e893bfdcbc87f48599a3bf1bcca82c1 MD5 | raw file
 1<?php
 2/**
 3 * Smarty Internal Plugin Compile Registered Function
 4 * 
 5 * Compiles code for the execution of a registered function
 6 * 
 7 * @package Smarty
 8 * @subpackage Compiler
 9 * @author Uwe Tews 
10 */
11/**
12 * Smarty Internal Plugin Compile Registered Function Class
13 */
14class Smarty_Internal_Compile_Private_Registered_Function extends Smarty_Internal_CompileBase {
15    /**
16     * Compiles code for the execution of a registered function
17     * 
18     * @param array $args array with attributes from parser
19     * @param string $tag name of function
20     * @param object $compiler compiler object
21     * @return string compiled code
22     */
23    public function compile($args, $compiler, $tag)
24    {
25        $this->compiler = $compiler; 
26        // This tag does create output
27        $this->compiler->has_output = true;
28
29        $this->required_attributes = array();
30        $this->optional_attributes = array('_any'); 
31        // check and get attributes
32        $_attr = $this->_get_attributes($args); 
33        // not cachable?
34        $this->compiler->tag_nocache = !$compiler->smarty->registered_plugins['function'][$tag][1]; 
35        // convert attributes into parameter array string
36        $_paramsArray = array();
37        foreach ($_attr as $_key => $_value) {
38            if (is_int($_key)) {
39                $_paramsArray[] = "$_key=>$_value";
40            } else {
41                $_paramsArray[] = "'$_key'=>$_value";
42            } 
43        } 
44        $_params = 'array(' . implode(",", $_paramsArray) . ')'; 
45        // compile code
46        $function = $compiler->smarty->registered_plugins['function'][$tag][0]; 
47        // compile code
48        if (!is_array($function)) {
49            $output = "<?php echo {$function}({$_params},\$_smarty_tpl->smarty,\$_smarty_tpl);?>\n";
50        } else if (is_object($function[0])) {
51            $output = "<?php echo call_user_func(\$_smarty_tpl->smarty->registered_plugins['function']['{$tag}'][0],{$_params},\$_smarty_tpl->smarty,\$_smarty_tpl);?>\n";
52        } else {
53            $output = "<?php echo call_user_func(array('{$function[0]}','{$function[1]}'),{$_params},\$_smarty_tpl->smarty,\$_smarty_tpl);?>\n";
54        } 
55        return $output;
56    } 
57} 
58
59?>