ci4

Форк
0
/
Plugins.php 
135 строк · 3.0 Кб
1
<?php
2

3
declare(strict_types=1);
4

5
/**
6
 * This file is part of CodeIgniter 4 framework.
7
 *
8
 * (c) CodeIgniter Foundation <admin@codeigniter.com>
9
 *
10
 * For the full copyright and license information, please view
11
 * the LICENSE file that was distributed with this source code.
12
 */
13

14
namespace CodeIgniter\View;
15

16
use CodeIgniter\HTTP\URI;
17

18
/**
19
 * View plugins
20
 */
21
class Plugins
22
{
23
    /**
24
     * Wrap helper function to use as view plugin.
25
     *
26
     * @return string|URI
27
     */
28
    public static function currentURL()
29
    {
30
        return current_url();
31
    }
32

33
    /**
34
     * Wrap helper function to use as view plugin.
35
     *
36
     * @return string|URI
37
     */
38
    public static function previousURL()
39
    {
40
        return previous_url();
41
    }
42

43
    /**
44
     * Wrap helper function to use as view plugin.
45
     *
46
     * @param array{email?: string, title?: string, attributes?: array<string, string>|object|string} $params
47
     */
48
    public static function mailto(array $params = []): string
49
    {
50
        $email = $params['email'] ?? '';
51
        $title = $params['title'] ?? '';
52
        $attrs = $params['attributes'] ?? '';
53

54
        return mailto($email, $title, $attrs);
55
    }
56

57
    /**
58
     * Wrap helper function to use as view plugin.
59
     *
60
     * @param array{email?: string, title?: string, attributes?: array<string, string>|object|string} $params
61
     */
62
    public static function safeMailto(array $params = []): string
63
    {
64
        $email = $params['email'] ?? '';
65
        $title = $params['title'] ?? '';
66
        $attrs = $params['attributes'] ?? '';
67

68
        return safe_mailto($email, $title, $attrs);
69
    }
70

71
    /**
72
     * Wrap helper function to use as view plugin.
73
     *
74
     * @param array<int|string, string>|list<string> $params
75
     */
76
    public static function lang(array $params = []): string
77
    {
78
        $line = array_shift($params);
79

80
        return lang($line, $params);
81
    }
82

83
    /**
84
     * Wrap helper function to use as view plugin.
85
     *
86
     * @param array{field?: string} $params
87
     */
88
    public static function validationErrors(array $params = []): string
89
    {
90
        $validator = service('validation');
91
        if ($params === []) {
92
            return $validator->listErrors();
93
        }
94

95
        return $validator->showError($params['field']);
96
    }
97

98
    /**
99
     * Wrap helper function to use as view plugin.
100
     *
101
     * @param list<string> $params
102
     *
103
     * @return false|string
104
     */
105
    public static function route(array $params = [])
106
    {
107
        return route_to(...$params);
108
    }
109

110
    /**
111
     * Wrap helper function to use as view plugin.
112
     *
113
     * @param list<string> $params
114
     */
115
    public static function siteURL(array $params = []): string
116
    {
117
        return site_url(...$params);
118
    }
119

120
    /**
121
     * Wrap csp_script_nonce() function to use as view plugin.
122
     */
123
    public static function cspScriptNonce(): string
124
    {
125
        return csp_script_nonce();
126
    }
127

128
    /**
129
     * Wrap csp_style_nonce() function to use as view plugin.
130
     */
131
    public static function cspStyleNonce(): string
132
    {
133
        return csp_style_nonce();
134
    }
135
}
136

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.