| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentBoards\Framework\Http; |
| 4 |
|
| 5 |
class URL |
| 6 |
{ |
| 7 |
/** |
| 8 |
* Get the current URL |
| 9 |
* |
| 10 |
* @return string |
| 11 |
*/ |
| 12 |
public function current() |
| 13 |
{ |
| 14 |
return get_site_url() . rtrim(preg_replace('/\?.*/', '', $_SERVER['REQUEST_URI']), '/'); |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* Parse a url from uncompiled route |
| 19 |
* |
| 20 |
* @param string $url |
| 21 |
* @param array $params |
| 22 |
* @return string |
| 23 |
*/ |
| 24 |
public function parse(string $url, array $params) |
| 25 |
{ |
| 26 |
return preg_replace_callback('#\{[a-zA-Z0-9-_]+\}#', function($matches) use ($params) { |
| 27 |
foreach ($matches as $match) { |
| 28 |
$match = str_replace(['{', '}'], ['', ''], $match); |
| 29 |
if (isset($params[$match])) { |
| 30 |
return $params[$match]; |
| 31 |
} |
| 32 |
} |
| 33 |
}, $url); |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Returns the string representation of the URL object |
| 38 |
* |
| 39 |
* @return string Current URL. |
| 40 |
*/ |
| 41 |
public function __toString() |
| 42 |
{ |
| 43 |
return $this->current(); |
| 44 |
} |
| 45 |
} |
| 46 |
|