Smarty_Internal_Resource_String::getContent()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Smarty Internal Plugin Resource String
4
 *
5
 * @package    Smarty
6
 * @subpackage TemplateResources
7
 * @author     Uwe Tews
8
 * @author     Rodney Rehm
9
 */
10
11
/**
12
 * Smarty Internal Plugin Resource String
13
 * Implements the strings as resource for Smarty template
14
 * {@internal unlike eval-resources the compiled state of string-resources is saved for subsequent access}}
15
 *
16
 * @package    Smarty
17
 * @subpackage TemplateResources
18
 */
19
class Smarty_Internal_Resource_String extends Smarty_Resource
20
{
21
    /**
22
     * populate Source Object with meta data from Resource
23
     *
24
     * @param Smarty_Template_Source   $source    source object
25
     * @param Smarty_Internal_Template|null $_template template object
26
     *
27
     * @return void
28
     */
29
    public function populate(Smarty_Template_Source $source, ?Smarty_Internal_Template $_template = null)
30
    {
31
        $source->uid = $source->filepath = sha1($source->name . $source->smarty->_joined_template_dir);
32
        $source->timestamp = $source->exists = true;
0 ignored issues
show
Documentation Bug introduced by
The property $timestamp was declared of type integer, but $source->exists = true is of type true. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
33
    }
34
35
    /**
36
     * Load template's source from $resource_name into current template object
37
     *
38
     * @uses decode() to decode base64 and urlencoded template_resources
39
     *
40
     * @param Smarty_Template_Source $source source object
41
     *
42
     * @return string                 template source
43
     */
44
    public function getContent(Smarty_Template_Source $source)
45
    {
46
        return $this->decode($source->name);
47
    }
48
49
    /**
50
     * decode base64 and urlencode
51
     *
52
     * @param string $string template_resource to decode
53
     *
54
     * @return string decoded template_resource
55
     */
56
    protected function decode($string)
57
    {
58
        // decode if specified
59
        if (($pos = strpos($string, ':')) !== false) {
0 ignored issues
show
Unused Code introduced by
The assignment to $pos is dead and can be removed.
Loading history...
60
            if (!strncmp($string, 'base64', 6)) {
61
                return base64_decode(substr($string, 7));
62
            } elseif (!strncmp($string, 'urlencode', 9)) {
63
                return urldecode(substr($string, 10));
64
            }
65
        }
66
        return $string;
67
    }
68
69
    /**
70
     * modify resource_name according to resource handlers specifications
71
     *
72
     * @param Smarty  $smarty        Smarty instance
73
     * @param string  $resource_name resource_name to make unique
74
     * @param boolean $isConfig      flag for config resource
75
     *
76
     * @return string unique resource name
77
     */
78
    public function buildUniqueResourceName(Smarty $smarty, $resource_name, $isConfig = false)
79
    {
80
        return get_class($this) . '#' . $this->decode($resource_name);
81
    }
82
83
    /**
84
     * Determine basename for compiled filename
85
     * Always returns an empty string.
86
     *
87
     * @param Smarty_Template_Source $source source object
88
     *
89
     * @return string                 resource's basename
90
     */
91
    public function getBasename(Smarty_Template_Source $source)
92
    {
93
        return '';
94
    }
95
96
    /*
97
        * Disable timestamp checks for string resource.
98
        *
99
        * @return bool
100
        */
101
    /**
102
     * @return bool
103
     */
104
    public function checkTimestamps()
105
    {
106
        return false;
107
    }
108
}
109