Commit cafc9a6e authored by Sebastian De Deyne's avatar Sebastian De Deyne Committed by GitHub
Browse files

Merge pull request #15 from bmitch/segments

Added getFirstSegment() and getLastSegment()
parents d174fb31 f61c2d3d
......@@ -184,6 +184,20 @@ class Url implements UriInterface
return $segments[$index - 1] ?? $default;
}
public function getFirstSegment()
{
$segments = $this->getSegments();
return $segments[0] ?? null;
}
public function getLastSegment()
{
$segments = $this->getSegments();
return end($segments) ?? null;
}
public function withScheme($scheme)
{
$url = clone $this;
......
......@@ -15,6 +15,22 @@ class UrlSegmentTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(['opensource', 'php'], $url->getSegments());
}
/** @test */
public function it_can_return_the_last_path_segment()
{
$url = Url::create()->withPath('opensource/php');
$this->assertEquals('php', $url->getLastSegment());
}
/** @test */
public function it_can_return_the_first_path_segment()
{
$url = Url::create()->withPath('opensource/php');
$this->assertEquals('opensource', $url->getFirstSegment());
}
/** @test */
public function it_can_return_a_path_segment()
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment