Added $grav['uri]->getCurrentUri() function to get Grav\Framework\Uri instance for the current URL.

This commit is contained in:
Matias Griese
2018-02-19 11:10:37 +02:00
parent 62dfa0e060
commit 35f7a2a9de
2 changed files with 20 additions and 1 deletions

View File

@@ -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

View File

@@ -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 @@ class Uri
}
/**
* 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
*