mirror of
https://github.com/getgrav/grav.git
synced 2026-05-06 11:37:12 +02:00
added fragment support to URI #711
This commit is contained in:
@@ -28,6 +28,7 @@ class Uri
|
||||
protected $scheme;
|
||||
protected $port;
|
||||
protected $query;
|
||||
protected $fragment;
|
||||
protected $root;
|
||||
protected $root_path;
|
||||
protected $uri;
|
||||
@@ -196,6 +197,7 @@ class Uri
|
||||
$this->host = [];
|
||||
$this->root = [];
|
||||
$this->url = [];
|
||||
$this->fragment = [];
|
||||
|
||||
$grav = Grav::instance();
|
||||
|
||||
@@ -220,6 +222,10 @@ class Uri
|
||||
parse_str($uri_bits['query'], $this->query);
|
||||
}
|
||||
|
||||
if (isset($uri_bits['fragment'])) {
|
||||
$this->fragment = $uri_bits['fragment'];
|
||||
}
|
||||
|
||||
$this->base = $this->buildBaseUrl();
|
||||
$this->host = $this->buildHost();
|
||||
$this->env = $this->buildEnvironment();
|
||||
@@ -300,6 +306,11 @@ class Uri
|
||||
$uri = $bits['path'];
|
||||
}
|
||||
|
||||
//process fragment
|
||||
if (isset($bits['fragment'])) {
|
||||
$this->fragment = $bits['fragment'];
|
||||
}
|
||||
|
||||
// remove the extension if there is one set
|
||||
$parts = pathinfo($uri);
|
||||
|
||||
@@ -464,6 +475,21 @@ class Uri
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Fragment portion of a URI (eg #target)
|
||||
*
|
||||
* @param null $fragment
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function fragment($fragment = null)
|
||||
{
|
||||
if ($fragment !== null) {
|
||||
$this->fragment = $fragment;
|
||||
}
|
||||
return $this->fragment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return URL.
|
||||
*
|
||||
|
||||
@@ -177,6 +177,15 @@ class UriTest extends \Codeception\TestCase\Test
|
||||
$this->assertSame('yyy', $this->uri->param('test'));
|
||||
}
|
||||
|
||||
public function testFragment()
|
||||
{
|
||||
$this->uri->initializeWithURL('http://localhost:8080/a/b/c#my-fragment');
|
||||
$this->assertSame('my-fragment', $this->uri->fragment());
|
||||
$this->uri->initializeWithURL('http://localhost:8080/a/b/c');
|
||||
$this->uri->fragment('something-new');
|
||||
$this->assertSame('something-new', $this->uri->fragment());
|
||||
}
|
||||
|
||||
public function testUrl()
|
||||
{
|
||||
$this->uri->initializeWithURL('http://localhost:8080/grav/it/ueper')->init();
|
||||
|
||||
Reference in New Issue
Block a user