Passed
Push — master ( de2f20...34ca9e )
by Caen
04:56 queued 46s
created

route()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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 HydeKernel::getInstance();
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
    if (defined('HYDE_COMPATIBILITY_MODE') && HYDE_COMPATIBILITY_MODE === true) {
0 ignored issues
show
Bug introduced by
The constant HYDE_COMPATIBILITY_MODE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
29
        // Don't declare these functions when running in compatibility mode.
30
    } else {
31
        if (! function_exists('asset')) {
32
            /**
33
             * Get a relative link or URL to an asset in the media directory.
34
             */
35
            function asset(string $name, bool $preferQualifiedUrl = false): string
36
            {
37
                return hyde()->asset($name, $preferQualifiedUrl);
38
            }
39
        }
40
41
        if (! function_exists('route')) {
42
            /**
43
             * Get a page route by its key.
44
             */
45
            function route(string $key): ?Hyde\Support\Models\Route
46
            {
47
                return hyde()->route($key);
48
            }
49
        }
50
51
        if (! function_exists('url')) {
52
            /**
53
             * Get a qualified URL to the supplied path if a base URL is set.
54
             */
55
            function url(string $path = ''): string
56
            {
57
                return hyde()->url($path);
58
            }
59
        }
60
    }
61
}
62
63
namespace Hyde {
64
    use Hyde\Facades\Filesystem;
65
    use Hyde\Foundation\HydeKernel;
66
    use Illuminate\Contracts\Support\Arrayable;
67
    use Symfony\Component\Yaml\Yaml;
68
69
    use function function_exists;
70
    use function array_merge;
71
    use function str_replace;
72
    use function implode;
73
    use function trim;
74
    use function md5;
75
76
    if (! function_exists('\Hyde\hyde')) {
77
        /**
78
         * Get the available HydeKernel instance.
79
         */
80
        function hyde(): HydeKernel
81
        {
82
            return HydeKernel::getInstance();
83
        }
84
    }
85
86
    if (! function_exists('\Hyde\unslash')) {
87
        /**
88
         * Remove trailing slashes from the start and end of a string.
89
         */
90
        function unslash(string $string): string
91
        {
92
            return trim($string, '/\\');
93
        }
94
    }
95
96
    if (! function_exists('\Hyde\unixsum')) {
97
        /**
98
         * A EOL agnostic wrapper for calculating MD5 checksums.
99
         *
100
         * This function is not cryptographically secure.
101
         */
102
        function unixsum(string $string): string
103
        {
104
            return md5(str_replace(["\r\n", "\r"], "\n", $string));
105
        }
106
    }
107
108
    if (! function_exists('\Hyde\unixsum_file')) {
109
        /**
110
         * Shorthand for {@see unixsum()} but loads a file.
111
         */
112
        function unixsum_file(string $file): string
113
        {
114
            return \Hyde\unixsum(Filesystem::getContents($file));
115
        }
116
    }
117
118
    if (! function_exists('\Hyde\make_title')) {
119
        function make_title(string $value): string
120
        {
121
            return hyde()->makeTitle($value);
122
        }
123
    }
124
125
    if (! function_exists('\Hyde\normalize_newlines')) {
126
        function normalize_newlines(string $string): string
127
        {
128
            return hyde()->normalizeNewlines($string);
129
        }
130
    }
131
132
    if (! function_exists('\Hyde\strip_newlines')) {
133
        function strip_newlines(string $string): string
134
        {
135
            return hyde()->stripNewlines($string);
136
        }
137
    }
138
139
    if (! function_exists('\Hyde\trim_slashes')) {
140
        function trim_slashes(string $string): string
141
        {
142
            return hyde()->trimSlashes($string);
143
        }
144
    }
145
146
    if (! function_exists('\Hyde\evaluate_arrayable')) {
147
        function evaluate_arrayable(array|Arrayable $array): array
148
        {
149
            return $array instanceof Arrayable ? $array->toArray() : $array;
0 ignored issues
show
introduced by
$array is never a sub-type of Illuminate\Contracts\Support\Arrayable.
Loading history...
150
        }
151
    }
152
153
    if (! function_exists('\Hyde\yaml_encode')) {
154
        function yaml_encode(mixed $input, int $inline = 2, int $indent = 4, int $flags = 0): string
155
        {
156
            return Yaml::dump($input instanceof Arrayable ? $input->toArray() : $input, $inline, $indent, $flags);
157
        }
158
    }
159
160
    if (! function_exists('\Hyde\yaml_decode')) {
161
        function yaml_decode(string $input, int $flags = 0): mixed
162
        {
163
            return Yaml::parse($input, $flags);
164
        }
165
    }
166
167
    if (! function_exists('\Hyde\path_join')) {
168
        function path_join(string $directory, string ...$paths): string
169
        {
170
            return implode('/', array_merge([$directory], $paths));
171
        }
172
    }
173
174
    if (! function_exists('\Hyde\normalize_slashes')) {
175
        function normalize_slashes(string $string): string
176
        {
177
            return str_replace('\\', '/', $string);
178
        }
179
    }
180
}
181