|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace { |
|
6
|
|
|
use Hyde\Foundation\HydeKernel; |
|
7
|
|
|
|
|
8
|
|
|
if (! function_exists('hyde')) { |
|
9
|
|
|
/** |
|
10
|
|
|
* Get the available HydeKernel instance. |
|
11
|
|
|
*/ |
|
12
|
|
|
function hyde(): HydeKernel |
|
13
|
|
|
{ |
|
14
|
|
|
return app(HydeKernel::class); |
|
15
|
|
|
} |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
if (! function_exists('unslash')) { |
|
19
|
|
|
/** |
|
20
|
|
|
* Remove trailing slashes from the start and end of a string. |
|
21
|
|
|
*/ |
|
22
|
|
|
function unslash(string $string): string |
|
|
|
|
|
|
23
|
|
|
{ |
|
24
|
|
|
return trim($string, '/\\'); |
|
25
|
|
|
} |
|
26
|
|
|
} |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
namespace Hyde { |
|
30
|
|
|
use Hyde\Foundation\HydeKernel; |
|
31
|
|
|
use Illuminate\Contracts\Support\Arrayable; |
|
32
|
|
|
use Symfony\Component\Yaml\Yaml; |
|
33
|
|
|
|
|
34
|
|
|
if (! function_exists('\Hyde\hyde')) { |
|
35
|
|
|
/** |
|
36
|
|
|
* Get the available HydeKernel instance. |
|
37
|
|
|
*/ |
|
38
|
|
|
function hyde(): HydeKernel |
|
39
|
|
|
{ |
|
40
|
|
|
return app(HydeKernel::class); |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
if (! function_exists('\Hyde\unslash')) { |
|
45
|
|
|
/** |
|
46
|
|
|
* Remove trailing slashes from the start and end of a string. |
|
47
|
|
|
*/ |
|
48
|
|
|
function unslash(string $string): string |
|
|
|
|
|
|
49
|
|
|
{ |
|
50
|
|
|
return trim($string, '/\\'); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
if (! function_exists('\Hyde\make_title')) { |
|
55
|
|
|
function make_title(string $value): string |
|
56
|
|
|
{ |
|
57
|
|
|
return hyde()->makeTitle($value); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
if (! function_exists('\Hyde\normalize_newlines')) { |
|
62
|
|
|
function normalize_newlines(string $string): string |
|
63
|
|
|
{ |
|
64
|
|
|
return hyde()->normalizeNewlines($string); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
if (! function_exists('\Hyde\strip_newlines')) { |
|
69
|
|
|
function strip_newlines(string $string): string |
|
70
|
|
|
{ |
|
71
|
|
|
return hyde()->stripNewlines($string); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
if (! function_exists('\Hyde\trim_slashes')) { |
|
76
|
|
|
function trim_slashes(string $string): string |
|
77
|
|
|
{ |
|
78
|
|
|
return hyde()->trimSlashes($string); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
if (! function_exists('\Hyde\evaluate_arrayable')) { |
|
83
|
|
|
function evaluate_arrayable(array|Arrayable $array): array |
|
84
|
|
|
{ |
|
85
|
|
|
return $array instanceof Arrayable ? $array->toArray() : $array; |
|
|
|
|
|
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
if (! function_exists('\Hyde\yaml_encode')) { |
|
90
|
|
|
function yaml_encode(mixed $input, int $inline = 2, int $indent = 4, int $flags = 0): string |
|
91
|
|
|
{ |
|
92
|
|
|
return Yaml::dump($input instanceof Arrayable ? $input->toArray() : $input, $inline, $indent, $flags); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
if (! function_exists('\Hyde\yaml_decode')) { |
|
97
|
|
|
function yaml_decode(string $input, int $flags = 0): mixed |
|
98
|
|
|
{ |
|
99
|
|
|
return Yaml::parse($input, $flags); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
if (! function_exists('\Hyde\path_join')) { |
|
104
|
|
|
function path_join(string $directory, string ...$paths): string |
|
105
|
|
|
{ |
|
106
|
|
|
return implode('/', array_merge([$directory], $paths)); |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
if (! function_exists('\Hyde\system_path_join')) { |
|
111
|
|
|
function system_path_join(string $directory, string ...$paths): string |
|
112
|
|
|
{ |
|
113
|
|
|
return implode(DIRECTORY_SEPARATOR, array_merge([$directory], $paths)); |
|
114
|
|
|
} |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
if (! function_exists('\Hyde\normalize_slashes')) { |
|
118
|
|
|
function normalize_slashes(string $string): string |
|
119
|
|
|
{ |
|
120
|
|
|
return str_replace('\\', '/', $string); |
|
121
|
|
|
} |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.