diff --git a/CHANGELOG.md b/CHANGELOG.md index cb6547f56d..ab74346615 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,9 +3,10 @@ 1. [](#new) * Added `Grav\Framework\Uri` classes extending PSR-7 `HTTP message UriInterface` implementation + * Added `$grav['uri]->getCurrentUri()` function to get `Grav\Framework\Uri` instance for the current URL. * Added ability to have `php` version dependencies in GPM assets 1. [](#bugfix) - * Fixed issue with remote PHP version determination for Grav updates + * Fixed issue with remote PHP version determination for Grav updates # v1.4.0-rc.2 ## 02/15/2018 diff --git a/system/src/Grav/Common/Uri.php b/system/src/Grav/Common/Uri.php index fc1f3aa5d3..7f651c9648 100644 --- a/system/src/Grav/Common/Uri.php +++ b/system/src/Grav/Common/Uri.php @@ -9,12 +9,16 @@ namespace Grav\Common; use Grav\Common\Page\Page; +use Grav\Framework\Uri\UriFactory; use Grav\Framework\Uri\UriPartsFilter; class Uri { const HOSTNAME_REGEX = '/^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/'; + /** @var \Grav\Framework\Uri\Uri */ + protected static $currentUri; + public $url; // Uri parts. @@ -596,6 +600,20 @@ public static function ip() } + /** + * Returns current Uri. + * + * @return \Grav\Framework\Uri\Uri + */ + public static function getCurrentUri() + { + if (!static::$currentUri) { + static::$currentUri = UriFactory::createFromEnvironment($_SERVER); + } + + return static::$currentUri; + } + /** * Is this an external URL? if it starts with `http` then yes, else false *