Skip to content
This repository has been archived by the owner on Dec 31, 2022. It is now read-only.

Commit

Permalink
Новый эксепшн, автоматическое преобразование схемы и хоста в нижний р…
Browse files Browse the repository at this point in the history
…егистр
  • Loading branch information
fenric committed Oct 7, 2018
1 parent a949e99 commit 67d18a2
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 56 deletions.
36 changes: 18 additions & 18 deletions src/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function __construct(string $uri)
/**
* {@inheritDoc}
*
* @throws \InvalidArgumentException
* @throws \Sunrise\Uri\UriException
*
* @link https://tools.ietf.org/html/rfc3986#section-3.1
*/
Expand All @@ -136,18 +136,18 @@ public function setScheme(string $scheme) : UriInterface

if (! \preg_match($regex, $scheme))
{
throw new \InvalidArgumentException('Invalid URI component "scheme"');
throw new UriException('Invalid URI component "scheme"');
}

$this->scheme = $scheme;
$this->scheme = \strtolower($scheme);

return $this;
}

/**
* {@inheritDoc}
*
* @throws \InvalidArgumentException
* @throws \Sunrise\Uri\UriException
*
* @link https://tools.ietf.org/html/rfc3986#section-3.2.1
*/
Expand All @@ -157,7 +157,7 @@ public function setUsername(string $username) : UriInterface

if (! \preg_match($regex, $username))
{
throw new \InvalidArgumentException('Invalid URI component "username"');
throw new UriException('Invalid URI component "username"');
}

$this->username = $username;
Expand All @@ -168,7 +168,7 @@ public function setUsername(string $username) : UriInterface
/**
* {@inheritDoc}
*
* @throws \InvalidArgumentException
* @throws \Sunrise\Uri\UriException
*
* @link https://tools.ietf.org/html/rfc3986#section-3.2.1
*/
Expand All @@ -178,7 +178,7 @@ public function setPassword(string $password) : UriInterface

if (! \preg_match($regex, $password))
{
throw new \InvalidArgumentException('Invalid URI component "password"');
throw new UriException('Invalid URI component "password"');
}

$this->password = $password;
Expand All @@ -189,7 +189,7 @@ public function setPassword(string $password) : UriInterface
/**
* {@inheritDoc}
*
* @throws \InvalidArgumentException
* @throws \Sunrise\Uri\UriException
*
* @link https://tools.ietf.org/html/rfc3986#section-3.2.2
*/
Expand All @@ -199,18 +199,18 @@ public function setHost(string $host) : UriInterface

if (! \preg_match($regex, $host))
{
throw new \InvalidArgumentException('Invalid URI component "host"');
throw new UriException('Invalid URI component "host"');
}

$this->host = $host;
$this->host = \strtolower($host);

return $this;
}

/**
* {@inheritDoc}
*
* @throws \InvalidArgumentException
* @throws \Sunrise\Uri\UriException
*/
public function setPort(?int $port) : UriInterface
{
Expand All @@ -219,7 +219,7 @@ public function setPort(?int $port) : UriInterface

if (! ($port === null || ($port >= $min && $port <= $max)))
{
throw new \InvalidArgumentException('Invalid URI component "port"');
throw new UriException('Invalid URI component "port"');
}

$this->port = $port;
Expand All @@ -230,7 +230,7 @@ public function setPort(?int $port) : UriInterface
/**
* {@inheritDoc}
*
* @throws \InvalidArgumentException
* @throws \Sunrise\Uri\UriException
*
* @link https://tools.ietf.org/html/rfc3986#section-3.3
*/
Expand All @@ -240,7 +240,7 @@ public function setPath(string $path) : UriInterface

if (! \preg_match($regex, $path))
{
throw new \InvalidArgumentException('Invalid URI component "path"');
throw new UriException('Invalid URI component "path"');
}

$this->path = $path;
Expand All @@ -251,7 +251,7 @@ public function setPath(string $path) : UriInterface
/**
* {@inheritDoc}
*
* @throws \InvalidArgumentException
* @throws \Sunrise\Uri\UriException
*
* @link https://tools.ietf.org/html/rfc3986#section-3.4
*/
Expand All @@ -261,7 +261,7 @@ public function setQuery(string $query) : UriInterface

if (! \preg_match($regex, $query))
{
throw new \InvalidArgumentException('Invalid URI component "query"');
throw new UriException('Invalid URI component "query"');
}

$this->query = $query;
Expand All @@ -272,7 +272,7 @@ public function setQuery(string $query) : UriInterface
/**
* {@inheritDoc}
*
* @throws \InvalidArgumentException
* @throws \Sunrise\Uri\UriException
*
* @link https://tools.ietf.org/html/rfc3986#section-3.5
*/
Expand All @@ -282,7 +282,7 @@ public function setFragment(string $fragment) : UriInterface

if (! \preg_match($regex, $fragment))
{
throw new \InvalidArgumentException('Invalid URI component "fragment"');
throw new UriException('Invalid URI component "fragment"');
}

$this->fragment = $fragment;
Expand Down
25 changes: 25 additions & 0 deletions src/UriException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php declare(strict_types=1);

/**
* It's free open-source software released under the MIT License.
*
* @author Anatoly Fenric <anatoly@fenric.ru>
* @copyright Copyright (c) 2018, Anatoly Fenric
* @license https://github.com/sunrise-php/uri/blob/master/LICENSE
* @link https://github.com/sunrise-php/uri
*/

namespace Sunrise\Uri;

/**
* Import classes
*/
use RuntimeException;

/**
* UriException
*
* @package Sunrise\Uri
*/
class UriException extends RuntimeException
{}

0 comments on commit 67d18a2

Please sign in to comment.