Completed
Push — master ( c348e1...63401a )
by Luka
04:22
created

functions.php ➔ h()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Helper functions for SampleApp
5
 *
6
 * @author    USAMI Kenta <[email protected]>
7
 * @copyright 2017 Baguette HQ
8
 * @license   https://www.gnu.org/licenses/gpl-3.0.html GPL-3.0
9
 */
10
11
use Teto\Routing\Router;
12
13
/**
14
 * @param  string $input
15
 * @return string
16
 */
17
function h($input)
18
{
19
    return htmlspecialchars($input, ENT_QUOTES, 'UTF-8');
20
}
21
22
/**
23
 * @param string $tpl_name
24
 * @param array $data
25
 * @return string
26
 */
27
function view($tpl_name, array $data = [])
28
{
29
    $main_tpl = __DIR__ . "/../view/{$tpl_name}.tpl.php";
30
    if (!file_exists($main_tpl)) {
31
        throw new \RuntimeException("Template file not exists: {$tpl_name}");
32
    }
33
34
    ob_start();
35
    $var = new variables($data);
36
    include __DIR__ . '/../view/body.tpl.php';
37
38
    return ob_get_clean();
39
}
40
41
/**
42
 * @param  Router $router
43
 * @return Router
44
 */
45
function router(Router $router = null)
46
{
47
    /** @var Router $cache */
48
    static $cache;
49
50
    if ($router !== null) {
51
        $cache = $router;
52
    }
53
54
    return $cache;
55
}
56