DiactorosUriFactory.php
6 months ago
GuzzleUriFactory.php
6 months ago
SlimUriFactory.php
6 months ago
SlimUriFactory.php
32 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AmeliaHttp\Message\UriFactory; |
| 4 | |
| 5 | use AmeliaHttp\Message\UriFactory; |
| 6 | use AmeliaVendor\Psr\Http\Message\UriInterface; |
| 7 | use Slim\Http\Uri; |
| 8 | |
| 9 | /** |
| 10 | * Creates Slim 3 URI. |
| 11 | * |
| 12 | * @author Mika Tuupola <tuupola@appelsiini.net> |
| 13 | */ |
| 14 | final class SlimUriFactory implements UriFactory |
| 15 | { |
| 16 | /** |
| 17 | * {@inheritdoc} |
| 18 | */ |
| 19 | public function createUri($uri) |
| 20 | { |
| 21 | if ($uri instanceof UriInterface) { |
| 22 | return $uri; |
| 23 | } |
| 24 | |
| 25 | if (is_string($uri)) { |
| 26 | return Uri::createFromString($uri); |
| 27 | } |
| 28 | |
| 29 | throw new \InvalidArgumentException('URI must be a string or UriInterface'); |
| 30 | } |
| 31 | } |
| 32 |