o2system /
reactor
| 1 | <?php |
||||
| 2 | /** |
||||
| 3 | * This file is part of the O2System Reactor package. |
||||
| 4 | * |
||||
| 5 | * For the full copyright and license information, please view the LICENSE |
||||
| 6 | * file that was distributed with this source code. |
||||
| 7 | * |
||||
| 8 | * @author Steeve Andrian Salim |
||||
| 9 | * @copyright Copyright (c) Steeve Andrian Salim |
||||
| 10 | */ |
||||
| 11 | // ------------------------------------------------------------------------ |
||||
| 12 | |||||
| 13 | if ( ! function_exists('base_url')) { |
||||
| 14 | /** |
||||
| 15 | * base_url |
||||
| 16 | * |
||||
| 17 | * @param null $segments |
||||
|
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||||
| 18 | * @param null $query |
||||
|
0 ignored issues
–
show
|
|||||
| 19 | * |
||||
| 20 | * @return string |
||||
| 21 | */ |
||||
| 22 | function base_url($segments = null, $query = null) |
||||
| 23 | { |
||||
| 24 | $uri = (new \O2System\Kernel\Http\Message\Uri()) |
||||
| 25 | ->withSegments(new \O2System\Kernel\Http\Message\Uri\Segments('')) |
||||
| 26 | ->withQuery(''); |
||||
| 27 | |||||
| 28 | if ($uriConfig = config()->offsetGet('uri')) { |
||||
| 29 | if ( ! empty($uriConfig[ 'base' ])) { |
||||
| 30 | $base = (is_https() ? 'https' : 'http') . '://' . str_replace(['http://', 'https://'], '', |
||||
| 31 | $uriConfig[ 'base' ]); |
||||
| 32 | $uri = new \O2System\Kernel\Http\Message\Uri($base); |
||||
| 33 | } |
||||
| 34 | } |
||||
| 35 | |||||
| 36 | if (isset($segments)) { |
||||
| 37 | $uri = $uri->addSegments($segments); |
||||
| 38 | } |
||||
| 39 | |||||
| 40 | if (isset($query)) { |
||||
| 41 | $uri = $uri->addQuery($query); |
||||
| 42 | } |
||||
| 43 | |||||
| 44 | return $uri->__toString(); |
||||
| 45 | } |
||||
| 46 | } |
||||
| 47 | |||||
| 48 | // ------------------------------------------------------------------------ |
||||
| 49 | |||||
| 50 | if ( ! function_exists('domain_url')) { |
||||
| 51 | /** |
||||
| 52 | * domain_url |
||||
| 53 | * |
||||
| 54 | * @param null $segments |
||||
|
0 ignored issues
–
show
|
|||||
| 55 | * @param null $query |
||||
|
0 ignored issues
–
show
|
|||||
| 56 | * @param null $subdomain |
||||
|
0 ignored issues
–
show
|
|||||
| 57 | * |
||||
| 58 | * @return string |
||||
| 59 | */ |
||||
| 60 | function domain_url($segments = null, $query = null, $subdomain = null) |
||||
| 61 | { |
||||
| 62 | $uri = (new \O2System\Kernel\Http\Message\Uri()) |
||||
| 63 | ->withSegments(new \O2System\Kernel\Http\Message\Uri\Segments('')) |
||||
| 64 | ->withQuery(''); |
||||
| 65 | |||||
| 66 | if ($uriConfig = config()->offsetGet('uri')) { |
||||
| 67 | if ( ! empty($uriConfig[ 'base' ])) { |
||||
| 68 | $base = (is_https() ? 'https' : 'http') . '://' . str_replace(['http://', 'https://'], '', |
||||
| 69 | $uriConfig[ 'base' ]); |
||||
| 70 | $uri = new \O2System\Kernel\Http\Message\Uri($base); |
||||
| 71 | } |
||||
| 72 | } |
||||
| 73 | |||||
| 74 | if (isset($subdomain)) { |
||||
| 75 | $uri = $uri->withSubDomain($subdomain); |
||||
| 76 | } |
||||
| 77 | |||||
| 78 | if (isset($segments)) { |
||||
| 79 | $uri = $uri->addSegments($segments); |
||||
| 80 | } |
||||
| 81 | |||||
| 82 | if (isset($query)) { |
||||
| 83 | $uri = $uri->addQuery($query); |
||||
| 84 | } |
||||
| 85 | |||||
| 86 | return $uri->__toString(); |
||||
| 87 | } |
||||
| 88 | } |
||||
| 89 | |||||
| 90 | // ------------------------------------------------------------------------ |
||||
| 91 | |||||
| 92 | if ( ! function_exists('current_url')) { |
||||
| 93 | /** |
||||
| 94 | * current_url |
||||
| 95 | * |
||||
| 96 | * @param null $segments |
||||
|
0 ignored issues
–
show
|
|||||
| 97 | * @param null $query |
||||
|
0 ignored issues
–
show
|
|||||
| 98 | * |
||||
| 99 | * @return string |
||||
| 100 | */ |
||||
| 101 | function current_url($segments = null, $query = null) |
||||
| 102 | { |
||||
| 103 | $uri = new \O2System\Kernel\Http\Message\Uri(); |
||||
| 104 | |||||
| 105 | if (isset($segments)) { |
||||
| 106 | $uri = $uri->addSegments($segments); |
||||
| 107 | } |
||||
| 108 | |||||
| 109 | if (isset($query)) { |
||||
| 110 | $uri = $uri->addQuery($query); |
||||
| 111 | } |
||||
| 112 | |||||
| 113 | return $uri->__toString(); |
||||
| 114 | } |
||||
| 115 | } |
||||
| 116 | |||||
| 117 | if ( ! function_exists('public_url')) { |
||||
| 118 | /** |
||||
| 119 | * public_url |
||||
| 120 | * |
||||
| 121 | * @param string $path Uri path. |
||||
| 122 | * |
||||
| 123 | * @return string |
||||
| 124 | */ |
||||
| 125 | function public_url($path) |
||||
| 126 | { |
||||
| 127 | return path_to_url($path); |
||||
| 128 | } |
||||
| 129 | } |
||||
| 130 | |||||
| 131 | // ------------------------------------------------------------------------ |
||||
| 132 | |||||
| 133 | if ( ! function_exists('assets_url')) { |
||||
| 134 | /** |
||||
| 135 | * assets_url |
||||
| 136 | * |
||||
| 137 | * @param string $path Uri path. |
||||
| 138 | * |
||||
| 139 | * @return string |
||||
| 140 | */ |
||||
| 141 | function assets_url($path) |
||||
| 142 | { |
||||
| 143 | return presenter()->assets->file($path); |
||||
|
0 ignored issues
–
show
The function
presenter was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 144 | } |
||||
| 145 | } |
||||
| 146 | |||||
| 147 | // ------------------------------------------------------------------------ |
||||
| 148 | |||||
| 149 | if ( ! function_exists('storage_url')) { |
||||
| 150 | /** |
||||
| 151 | * storage_url |
||||
| 152 | * |
||||
| 153 | * @param string $path Uri path. |
||||
| 154 | * |
||||
| 155 | * @return string |
||||
| 156 | */ |
||||
| 157 | function storage_url($path) |
||||
| 158 | { |
||||
| 159 | $urlPath = str_replace(PATH_STORAGE, '', $path); |
||||
| 160 | |||||
| 161 | return base_url('storage/' . $urlPath); |
||||
| 162 | } |
||||
| 163 | } |
||||
| 164 | |||||
| 165 | // ------------------------------------------------------------------------ |
||||
| 166 | |||||
| 167 | if ( ! function_exists('images_url')) { |
||||
| 168 | /** |
||||
| 169 | * images_url |
||||
| 170 | * |
||||
| 171 | * @param string $path Uri path. |
||||
| 172 | * |
||||
| 173 | * @return string |
||||
| 174 | */ |
||||
| 175 | function images_url($path) |
||||
| 176 | { |
||||
| 177 | $urlPath = str_replace(PATH_STORAGE, '', $path); |
||||
| 178 | |||||
| 179 | return base_url('images/' . $urlPath); |
||||
| 180 | } |
||||
| 181 | } |
||||
| 182 | |||||
| 183 | // ------------------------------------------------------------------------ |
||||
| 184 | |||||
| 185 | if ( ! function_exists('prepare_url')) { |
||||
| 186 | /** |
||||
| 187 | * prepare_url |
||||
| 188 | * |
||||
| 189 | * Simply adds the http:// part if no scheme is included |
||||
| 190 | * |
||||
| 191 | * @param string the URL |
||||
|
0 ignored issues
–
show
The type
the was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 192 | * |
||||
| 193 | * @return string |
||||
| 194 | */ |
||||
| 195 | function prepare_url($uri = '') |
||||
| 196 | { |
||||
| 197 | if ($uri === 'http://' or $uri === 'https://' or $uri === '') { |
||||
| 198 | return ''; |
||||
| 199 | } |
||||
| 200 | |||||
| 201 | /** |
||||
| 202 | * Converts double slashes in a string to a single slash, |
||||
| 203 | * except those found in http:// |
||||
| 204 | * |
||||
| 205 | * http://www.some-site.com//index.php |
||||
| 206 | * |
||||
| 207 | * becomes: |
||||
| 208 | * |
||||
| 209 | * http://www.some-site.com/index.php |
||||
| 210 | */ |
||||
| 211 | $uri = preg_replace('#(^|[^:])//+#', '\\1/', $uri); |
||||
| 212 | |||||
| 213 | $url = parse_url($uri); |
||||
| 214 | |||||
| 215 | if ( ! $url or ! isset($url[ 'scheme' ])) { |
||||
| 216 | return (is_https() ? 'https://' : 'http://') . $uri; |
||||
| 217 | } |
||||
| 218 | |||||
| 219 | return $uri; |
||||
| 220 | } |
||||
| 221 | } |
||||
| 222 | |||||
| 223 | // ------------------------------------------------------------------------ |
||||
| 224 | |||||
| 225 | if ( ! function_exists('redirect_url')) { |
||||
| 226 | /** |
||||
| 227 | * redirect_url |
||||
| 228 | * |
||||
| 229 | * Header redirect in two flavors |
||||
| 230 | * For very fine grained control over headers, you could use the Browser |
||||
| 231 | * Library's set_header() function. |
||||
| 232 | * |
||||
| 233 | * @param string $uri URL |
||||
| 234 | * @param string $method Redirect method |
||||
| 235 | * 'auto', 'location' or 'refresh' |
||||
| 236 | * @param int $code HTTP Response status code |
||||
| 237 | * |
||||
| 238 | * @return void |
||||
| 239 | */ |
||||
| 240 | function redirect_url($uri = '', $method = 'auto', $code = null) |
||||
| 241 | { |
||||
| 242 | if (is_array($uri)) { |
||||
|
0 ignored issues
–
show
|
|||||
| 243 | $uri = implode('/', $uri); |
||||
| 244 | } |
||||
| 245 | |||||
| 246 | if (strpos($uri, 'http') === false) { |
||||
| 247 | $uri = base_url($uri); |
||||
| 248 | } |
||||
| 249 | |||||
| 250 | // IIS environment likely? Use 'refresh' for better compatibility |
||||
| 251 | if ($method === 'auto' && isset($_SERVER[ 'SERVER_SOFTWARE' ]) && strpos( |
||||
| 252 | $_SERVER[ 'SERVER_SOFTWARE' ], |
||||
| 253 | 'Microsoft-IIS' |
||||
| 254 | ) !== false |
||||
| 255 | ) { |
||||
| 256 | $method = 'refresh'; |
||||
| 257 | } elseif ($method !== 'refresh' && (empty($code) OR ! is_numeric($code))) { |
||||
| 258 | if (isset($_SERVER[ 'SERVER_PROTOCOL' ], $_SERVER[ 'REQUEST_METHOD' ]) && $_SERVER[ 'SERVER_PROTOCOL' ] === 'HTTP/1.1') { |
||||
| 259 | $code = ($_SERVER[ 'REQUEST_METHOD' ] !== 'GET') |
||||
| 260 | ? 303 // reference: http://en.wikipedia.org/wiki/Post/Redirect/Get |
||||
| 261 | : 307; |
||||
| 262 | } else { |
||||
| 263 | $code = 302; |
||||
| 264 | } |
||||
| 265 | } |
||||
| 266 | |||||
| 267 | switch ($method) { |
||||
| 268 | case 'refresh': |
||||
| 269 | header('Refresh:0;url=' . $uri); |
||||
| 270 | break; |
||||
| 271 | default: |
||||
| 272 | header('Location: ' . $uri, true, $code); |
||||
| 273 | break; |
||||
| 274 | } |
||||
| 275 | |||||
| 276 | exit; |
||||
|
0 ignored issues
–
show
|
|||||
| 277 | } |
||||
| 278 | } |