ci4
1<?php
2
3declare(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
14namespace CodeIgniter\View;15
16use CodeIgniter\HTTP\URI;17
18/**
19* View plugins
20*/
21class Plugins22{
23/**24* Wrap helper function to use as view plugin.
25*
26* @return string|URI
27*/
28public static function currentURL()29{30return current_url();31}32
33/**34* Wrap helper function to use as view plugin.
35*
36* @return string|URI
37*/
38public static function previousURL()39{40return 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*/
48public static function mailto(array $params = []): string49{50$email = $params['email'] ?? '';51$title = $params['title'] ?? '';52$attrs = $params['attributes'] ?? '';53
54return 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*/
62public static function safeMailto(array $params = []): string63{64$email = $params['email'] ?? '';65$title = $params['title'] ?? '';66$attrs = $params['attributes'] ?? '';67
68return 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*/
76public static function lang(array $params = []): string77{78$line = array_shift($params);79
80return lang($line, $params);81}82
83/**84* Wrap helper function to use as view plugin.
85*
86* @param array{field?: string} $params
87*/
88public static function validationErrors(array $params = []): string89{90$validator = service('validation');91if ($params === []) {92return $validator->listErrors();93}94
95return $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*/
105public static function route(array $params = [])106{107return route_to(...$params);108}109
110/**111* Wrap helper function to use as view plugin.
112*
113* @param list<string> $params
114*/
115public static function siteURL(array $params = []): string116{117return site_url(...$params);118}119
120/**121* Wrap csp_script_nonce() function to use as view plugin.
122*/
123public static function cspScriptNonce(): string124{125return csp_script_nonce();126}127
128/**129* Wrap csp_style_nonce() function to use as view plugin.
130*/
131public static function cspStyleNonce(): string132{133return csp_style_nonce();134}135}
136