status()   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
function f3($get = null)
4
{
5
    $f3 = Base::instance();
6
    return $get ? $f3->get($get) : $f3;
7
}
8
9
function base_path($inner = '')
10
{
11
    return realpath(__DIR__.'/../').'/'.$inner;
12
}
13
function storage_path($inner = '')
14
{
15
    return base_path('storage/').'/'.$inner;
16
}
17
function db_path($db = '')
18
{
19
    return storage_path('db/').$db;
20
}
21
function lang_path($lang = '')
22
{
23
    return base_path('resources/lang/').'/'.$lang;
24
}
25
function views_path()
26
{
27
    return base_path('resources/views/');
28
}
29
function config_path($config = '')
30
{
31
    return base_path('config/').'/'.$config;
32
}
33
34
function abort()
35
{
36
    f3()->abort();
37
}
38
function status($code = 404)
39
{
40
    f3()->error($code);
41
}
42
function reroute($where)
43
{
44
    f3()->reroute($where);
45
}
46
function is_api($path)
47
{
48
    if (is_string($path)) {
49
        return explode('/', $path)[1] === 'api';
50
    }
51
    return false;
52
}
53
54
function template($template, array $params = [], $mime = 'text/html')
55
{
56
    $f3 = f3();
57
    if (!empty($params)) {
58
        $f3->mset($params);
59
    }
60
    if (is_array($template)) {
61
        $layout = $template[0];
62
        $view = $template[1];
63
    } else {
64
        $layout = 'layouts/app.htm';
65
        $view = $template;
66
    }
67
    $f3->set('user', App::instance()->user());
68
    $f3->set('content', extension($view, 'htm'));
69
    echo Template::instance()->render($layout, $mime);
70
}
71
72 View Code Duplication
function str_contains($haystack, $needles)
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
73
{
74
    foreach ((array) $needles as $needle) {
75
        if ($needle != '' && mb_strpos($haystack, $needle) !== false) {
76
            return true;
77
        }
78
    }
79
    return false;
80
}
81
function extension($file, $default = 'json')
82
{
83
    return $file.'.'.(pathinfo($file, PATHINFO_EXTENSION) ?: $default);
84
}
85
function flash($message, $type = 'success')
86
{
87
    Flash::instance()->addMessage($message, $type);
88
}
89
function trans($key, $params = null)
90
{
91
    return f3()->format(f3()->get($key), ($params ?: ''));
92
}
93
function error($error)
94
{
95
    if (null === $error) {
96
        return;
97
    }
98
    if (is_array($error)) {
99
        foreach ($error as $err) {
100
            if (is_array($err)) {
101
                foreach ($err as $e) {
102
                    flash($e, 'danger');
103
                }
104
            } else {
105
                flash($err, 'danger');
106
            }
107
        }
108
    } else {
109
        flash($error, 'danger');
110
    }
111
}
112