Skip to content

Commit

Permalink
Added $grav['uri]->getCurrentUri() function to get `Grav\Framework\…
Browse files Browse the repository at this point in the history
…Uri` instance for the current URL.
  • Loading branch information
mahagr committed Feb 19, 2018
1 parent 62dfa0e commit 35f7a2a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions system/src/Grav/Common/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
*
Expand Down

0 comments on commit 35f7a2a

Please sign in to comment.