Subversion Repositories ALCASAR

Rev

Go to most recent revision | Details | Last modification | View Log

Rev Author Line No. Line
2809 rexy 1
<?php
2
 
3
/**
4
 * Smarty Method GetLiterals
5
 *
6
 * Smarty::getLiterals() method
7
 *
8
 * @package    Smarty
9
 * @subpackage PluginsInternal
10
 * @author     Uwe Tews
11
 */
12
class Smarty_Internal_Method_Literals
13
{
14
    /**
15
     * Valid for Smarty and template object
16
     *
17
     * @var int
18
     */
19
    public $objMap = 3;
20
 
21
    /**
22
     * Get literals
23
     *
24
     * @api Smarty::getLiterals()
25
     *
26
     * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
27
     *
28
     * @return array list of literals
29
     */
30
    public function getLiterals(Smarty_Internal_TemplateBase $obj)
31
    {
32
        $smarty = $obj->_getSmartyObj();
33
        return (array)$smarty->literals;
34
    }
35
 
36
    /**
37
     * Add literals
38
     *
39
     * @api Smarty::addLiterals()
40
     *
41
     * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
42
     * @param array|string                                                    $literals literal or list of literals
43
     *                                                                                  to addto add
44
     *
45
     * @return \Smarty|\Smarty_Internal_Template
46
     * @throws \SmartyException
47
     */
48
    public function addLiterals(Smarty_Internal_TemplateBase $obj, $literals = null)
49
    {
50
        if (isset($literals)) {
51
            $this->set($obj->_getSmartyObj(), (array)$literals);
52
        }
53
        return $obj;
54
    }
55
 
56
    /**
57
     * Set literals
58
     *
59
     * @api Smarty::setLiterals()
60
     *
61
     * @param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
62
     * @param array|string                                                    $literals literal or list of literals
63
     *                                                                                  to setto set
64
     *
65
     * @return \Smarty|\Smarty_Internal_Template
66
     * @throws \SmartyException
67
     */
68
    public function setLiterals(Smarty_Internal_TemplateBase $obj, $literals = null)
69
    {
70
        $smarty = $obj->_getSmartyObj();
71
        $smarty->literals = array();
72
        if (!empty($literals)) {
73
            $this->set($smarty, (array)$literals);
74
        }
75
        return $obj;
76
    }
77
 
78
    /**
79
     * common setter for literals for easier handling of duplicates the
80
     * Smarty::$literals array gets filled with identical key values
81
     *
82
     * @param \Smarty $smarty
83
     * @param array   $literals
84
     *
85
     * @throws \SmartyException
86
     */
87
    private function set(Smarty $smarty, $literals)
88
    {
89
        $literals = array_combine($literals, $literals);
90
        $error = isset($literals[ $smarty->left_delimiter ]) ? array($smarty->left_delimiter) : array();
91
        $error = isset($literals[ $smarty->right_delimiter ]) ? $error[] = $smarty->right_delimiter : $error;
92
        if (!empty($error)) {
93
            throw new SmartyException(
94
                'User defined literal(s) "' . $error .
95
                '" may not be identical with left or right delimiter'
96
            );
97
        }
98
        $smarty->literals = array_merge((array)$smarty->literals, (array)$literals);
99
    }
100
}