Skip to content

Commit 3195d90

Browse files
committed
Adding new URIrenderer methods
1 parent bd5f9a3 commit 3195d90

File tree

5 files changed

+298
-101
lines changed

5 files changed

+298
-101
lines changed

BaseUri.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Psr\Http\Message\UriFactoryInterface;
2525
use Psr\Http\Message\UriInterface as Psr7UriInterface;
2626
use Stringable;
27+
use Throwable;
2728

2829
use function array_map;
2930
use function array_pop;
@@ -71,6 +72,15 @@ public static function from(Stringable|string $uri, ?UriFactoryInterface $uriFac
7172
return new static(static::formatHost(static::filterUri($uri, $uriFactory)), $uriFactory);
7273
}
7374

75+
public static function tryFrom(Stringable|string $uri, ?UriFactoryInterface $uriFactory = null): ?static
76+
{
77+
try {
78+
return self::from($uri, $uriFactory);
79+
} catch (Throwable) {
80+
return null;
81+
}
82+
}
83+
7484
public function withUriFactory(UriFactoryInterface $uriFactory): static
7585
{
7686
return new static($this->uri, $uriFactory);

CHANGELOG.md

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,15 @@ All Notable changes to `League\Uri` will be documented in this file
66

77
### Added
88

9+
- Added methods to align with the upcoming `Uri\Rfc3986Uri` PHP native class (see: https://wiki.php.net/rfc/url_parsing_api#proposal)
10+
- `Uri::tryNew` returns a new `Uri` instance on success or null on failure (ie: a Relax version of `Uri::new`).
11+
- `Http::tryNew` returns a new `Uri` instance on success or null on failure (ie: a Relax version of `Http::new`).
12+
- `BaseUri::tryfrom` returns a new `BaseUri` instance on success or null on failure (ie: a Relax version of `BaseUri::from`).
913
- `BaseUri::when` conditional method to ease component building logic.
1014
- `Http::when` conditional method to ease component building logic.
11-
- `Http::tryNew` returns a new `Uri` instance on success or null on failure.
1215
- `Uri::when` conditional method to ease component building logic.
13-
- `Uri::tryNew` returns a new `Uri` instance on success or null on failure.
14-
- `Uri::resolve`
15-
- `Uri::relativize`
16-
- `Uri::isAbsolute`
17-
- `Uri::isNetworkPath`
18-
- `Uri::isAbsolutePath`
19-
- `Uri::isRelativePath`
20-
- `Uri::isSameDocument`
21-
- `Uri::equals`
22-
- `Uri::toNormalizedString`
23-
- `Uri::getOrigin`
24-
- `Uri::isSameOrigin`
25-
- `Uri::isCrossOrigin`
26-
- `Uri::todisplayString` shows the URI in a human-readable format which may be an invalid URI.
27-
- `Uri::toUnixPath` returns the URI path as a Unix Path or `null`
28-
- `Uri::toWindowsPath` returns the URI path as a Windows Path or `null`
29-
- `Uri::toRfc8089` return the URI in a RFC8089 formator `null`
30-
- `Uri::toAnchor` returns the HTML anchor string using the instance as the href attribute value
31-
- `Uri::toMarkdown` returns the markdown link construct using the instance as the href attribute value
32-
- `Uri::getUser` to be inline with PHP native URI interface
33-
- `Uri::withUser` to be inline with PHP native URI interface
34-
- `Uri::withPassword` to be inline with PHP native URI interface
35-
- `Uri::__serialize` and `Uri::__unserialize` methods
16+
- `Uri` implements the new `League\Uri\Contract\UriInspector` interface
17+
- `Uri` implements the new `League\Uri\Contract\UriRenderer` interface
3618

3719
### Fixed
3820

0 commit comments

Comments
 (0)