Skip to content

Commit

Permalink
added getPath
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick committed Sep 17, 2014
1 parent ffe65db commit cbe9bcd
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/HttpRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ public function getUri()
return $this->getServerVariable('REQUEST_URI');
}

/**
* Return just the path
*
* @return string
*/
public function getPath()
{
return strtok($this->getServerVariable('REQUEST_URI'), '?');
}

/**
* Which request method was used to access the page;
* i.e. 'GET', 'HEAD', 'POST', 'PUT'.
Expand Down
30 changes: 30 additions & 0 deletions test/Unit/HttpRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,15 @@ public function testGetMethodException()

public function testGetUri()
{
$server = ['REQUEST_URI' => '/test?abc=def'];

$request = new HttpRequest([], [], [], [], $server);

$this->assertEquals(
$request->getUri(),
$server['REQUEST_URI']
);

$server = ['REQUEST_URI' => '/test'];

$request = new HttpRequest([], [], [], [], $server);
Expand All @@ -183,6 +192,27 @@ public function testGetUriException()
$request->getUri();
}

public function testGetPath()
{
$server = ['REQUEST_URI' => '/test?abc=def'];

$request = new HttpRequest([], [], [], [], $server);

$this->assertEquals(
$request->getPath(),
'/test'
);

$server = ['REQUEST_URI' => '/test'];

$request = new HttpRequest([], [], [], [], $server);

$this->assertEquals(
$request->getPath(),
'/test'
);
}

public function testGetHttpAccept()
{
$server = ['HTTP_ACCEPT' => 'Accept: audio/*; q=0.2, audio/basic'];
Expand Down

0 comments on commit cbe9bcd

Please sign in to comment.