-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.php
More file actions
44 lines (36 loc) · 1.18 KB
/
Copy pathhelpers.php
File metadata and controls
44 lines (36 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
declare(strict_types=1);
use Switon\Core\App;
use Switon\Http\RequestInterface;
use Switon\Http\UrlGeneratorInterface;
if (!function_exists('attr_nv')) {
function attr_nv(string $name, string $default = ''): string
{
$request = App::get(RequestInterface::class);
return sprintf('name="%s" value="%s"', $name, e($request->get($name, $default)));
}
}
if (!function_exists('attr_inv')) {
function attr_inv(string $name, string $default = ''): string
{
if ($pos = strpos($name, '[')) {
$id = substr($name, $pos + 1, -1);
} else {
$id = $name;
}
$request = App::get(RequestInterface::class);
return sprintf('id="%s" name="%s" value="%s"', $id, $name, e($request->get($name, $default)));
}
}
if (!function_exists('action')) {
function action(string|array $args = [], bool|string $scheme = false): string
{
return App::get(UrlGeneratorInterface::class)->action($args, $scheme);
}
}
if (!function_exists('url')) {
function url(string|array $args = [], bool|string $scheme = false): string
{
return App::get(UrlGeneratorInterface::class)->url($args, $scheme);
}
}