Unverified Commit 9b1c47be authored by Freek Van der Herten's avatar Freek Van der Herten Committed by GitHub
Browse files

Merge pull request #23 from mattiasgeniar/master

Add support for simple mailto: links
parents fffea8b2 a1a9460d
......@@ -14,7 +14,7 @@ class QueryParameterBag
$this->parameters = $parameters;
}
public static function fromString(string $query = ''): QueryParameterBag
public static function fromString(string $query = ''): self
{
if ($query === '') {
return new static();
......
......@@ -34,7 +34,7 @@ class Url implements UriInterface
/** @var string */
protected $fragment = '';
const VALID_SCHEMES = ['http', 'https'];
const VALID_SCHEMES = ['http', 'https', 'mailto'];
public function __construct()
{
......@@ -302,7 +302,7 @@ class Url implements UriInterface
return $url;
}
public function matches(Url $url): bool
public function matches(self $url): bool
{
return $this->__toString() === $url->__toString();
}
......@@ -311,10 +311,14 @@ class Url implements UriInterface
{
$url = '';
if ($this->getScheme() !== '') {
if ($this->getScheme() !== '' && $this->getScheme() != 'mailto') {
$url .= $this->getScheme().'://';
}
if ($this->getScheme() === 'mailto' && $this->getPath() !== '') {
$url .= $this->getScheme().':';
}
if ($this->getScheme() === '' && $this->getAuthority() !== '') {
$url .= '//';
}
......
......@@ -22,4 +22,12 @@ class UrlMatchesTest extends TestCase
$this->assertFalse($url->matches(Url::fromString('https://spatie.be/opensource')));
}
/** @test */
public function it_can_check_if_it_contains_a_mailto()
{
$url = Url::fromString('mailto:email@domain.tld');
$this->assertTrue($url->matches(Url::fromString('mailto:email@domain.tld')));
}
}
......@@ -24,6 +24,14 @@ class UrlParseTest extends TestCase
$this->assertEquals('https', $url->getScheme());
}
/** @test */
public function it_can_parse_a_scheme_with_mailto()
{
$url = Url::fromString('mailto:email@domain.tld');
$this->assertEquals('mailto', $url->getScheme());
}
/** @test */
public function it_throws_an_exception_if_an_invalid_scheme_is_provided()
{
......
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