Html::styles()   B
last analyzed

Complexity

Conditions 6
Paths 10

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.9137
c 0
b 0
f 0
cc 6
nc 10
nop 2
1
<?php
2
3
/**
4
 * This file is part of the NINEJKH/php-tpl library.
5
 *
6
 * (c) 9JKH (Pty) Ltd. <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE file
9
 * that was distributed with this source code.
10
 */
11
12
namespace NINEJKH\Tpl;
13
14
class Html
15
{
16
    public static function escape($string, $return = false)
17
    {
18
        if ($return) {
19
            return htmlspecialchars($string, ENT_QUOTES|ENT_HTML5, 'UTF-8');
20
        } else {
21
            echo htmlspecialchars($string, ENT_QUOTES|ENT_HTML5, 'UTF-8');
22
        }
23
24
    }
25
26
    public static function scripts($context, $return = false)
27
    {
28
        if ($context instanceof Tpl) {
29
            $scripts = $context->getScripts();
30
        } else {
31
            $scripts = $context;
32
        }
33
34
        if (empty($scripts) || !is_array($scripts)) {
35
            return;
36
        }
37
38
        $data = [];
39
40
        foreach ($scripts as $script) {
41
            $data[] = sprintf('<script src="%s"></script>', $script);
42
        }
43
44
        if ($return) {
45
            return $data;
46
        } else {
47
            echo implode("\n", $data);
48
        }
49
    }
50
51
    public static function styles($context, $return = false)
52
    {
53
        if ($context instanceof Tpl) {
54
            $styles = $context->getStyles();
55
        } else {
56
            $styles = $context;
57
        }
58
59
        if (empty($styles) || !is_array($styles)) {
60
            return;
61
        }
62
63
        $data = [];
64
65
        foreach ($styles as $style) {
66
            $data[] = sprintf('<link href="%s" rel="stylesheet">', $style);
67
        }
68
69
        if ($return) {
70
            return $data;
71
        } else {
72
            echo implode("\n", $data);
73
        }
74
    }
75
}
76