Skip to content

Commit

Permalink
Adding new URIrenderer methods
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Dec 26, 2024
1 parent bd5f9a3 commit 3195d90
Show file tree
Hide file tree
Showing 5 changed files with 298 additions and 101 deletions.
10 changes: 10 additions & 0 deletions BaseUri.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use Psr\Http\Message\UriFactoryInterface;
use Psr\Http\Message\UriInterface as Psr7UriInterface;
use Stringable;
use Throwable;

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

public static function tryFrom(Stringable|string $uri, ?UriFactoryInterface $uriFactory = null): ?static
{
try {
return self::from($uri, $uriFactory);
} catch (Throwable) {
return null;
}
}

public function withUriFactory(UriFactoryInterface $uriFactory): static
{
return new static($this->uri, $uriFactory);
Expand Down
30 changes: 6 additions & 24 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,15 @@ All Notable changes to `League\Uri` will be documented in this file

### Added

- Added methods to align with the upcoming `Uri\Rfc3986Uri` PHP native class (see: https://wiki.php.net/rfc/url_parsing_api#proposal)
- `Uri::tryNew` returns a new `Uri` instance on success or null on failure (ie: a Relax version of `Uri::new`).
- `Http::tryNew` returns a new `Uri` instance on success or null on failure (ie: a Relax version of `Http::new`).
- `BaseUri::tryfrom` returns a new `BaseUri` instance on success or null on failure (ie: a Relax version of `BaseUri::from`).
- `BaseUri::when` conditional method to ease component building logic.
- `Http::when` conditional method to ease component building logic.
- `Http::tryNew` returns a new `Uri` instance on success or null on failure.
- `Uri::when` conditional method to ease component building logic.
- `Uri::tryNew` returns a new `Uri` instance on success or null on failure.
- `Uri::resolve`
- `Uri::relativize`
- `Uri::isAbsolute`
- `Uri::isNetworkPath`
- `Uri::isAbsolutePath`
- `Uri::isRelativePath`
- `Uri::isSameDocument`
- `Uri::equals`
- `Uri::toNormalizedString`
- `Uri::getOrigin`
- `Uri::isSameOrigin`
- `Uri::isCrossOrigin`
- `Uri::todisplayString` shows the URI in a human-readable format which may be an invalid URI.
- `Uri::toUnixPath` returns the URI path as a Unix Path or `null`
- `Uri::toWindowsPath` returns the URI path as a Windows Path or `null`
- `Uri::toRfc8089` return the URI in a RFC8089 formator `null`
- `Uri::toAnchor` returns the HTML anchor string using the instance as the href attribute value
- `Uri::toMarkdown` returns the markdown link construct using the instance as the href attribute value
- `Uri::getUser` to be inline with PHP native URI interface
- `Uri::withUser` to be inline with PHP native URI interface
- `Uri::withPassword` to be inline with PHP native URI interface
- `Uri::__serialize` and `Uri::__unserialize` methods
- `Uri` implements the new `League\Uri\Contract\UriInspector` interface
- `Uri` implements the new `League\Uri\Contract\UriRenderer` interface

### Fixed

Expand Down
Loading

0 comments on commit 3195d90

Please sign in to comment.