diff options
Diffstat (limited to 'lib/Minz/Url.php')
| -rw-r--r-- | lib/Minz/Url.php | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/Minz/Url.php b/lib/Minz/Url.php index d6af50364..0780a636f 100644 --- a/lib/Minz/Url.php +++ b/lib/Minz/Url.php @@ -128,6 +128,40 @@ class Minz_Url { return $url_checked; } + + public static function serialize($url = []) { + try { + return base64_encode(json_encode($url, JSON_THROW_ON_ERROR)); + } catch (\Throwable $exception) { + return ''; + } + } + + public static function unserialize($url = '') { + try { + return json_decode(base64_decode($url), true, JSON_THROW_ON_ERROR); + } catch (\Throwable $exception) { + return ''; + } + } + + /** + * Returns an array representing the URL as passed in the address bar + * @return array URL representation + */ + public static function build () { + $url = [ + 'c' => $_GET['c'] ?? Minz_Request::defaultControllerName(), + 'a' => $_GET['a'] ?? Minz_Request::defaultActionName(), + 'params' => $_GET, + ]; + + // post-traitement + unset($url['params']['c']); + unset($url['params']['a']); + + return $url; + } } /** |
