Skip to content

Commit

Permalink
Improve UriRenderer interface (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod authored Jan 23, 2025
1 parent de49377 commit 4b9bc2f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ All Notable changes to `League\Uri\Interfaces` will be documented in this file
- `UriString::removeDotSegments`
- `UriString::normalize`
- `UriString::normalizeAuthority`
- `FeatureDetection::supportsDom`

### Fixed

Expand Down
12 changes: 6 additions & 6 deletions Contracts/UriRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function jsonSerialize(): string;
/**
* Returns the markdown string representation of the anchor tag with the current instance as its href attribute.
*/
public function toMarkdown(?string $linkTextTemplate = null): string;
public function toMarkdownAnchor(?string $linkTextTemplate = null): string;

/**
* Returns the HTML string representation of the anchor tag with the current instance as its href attribute.
Expand All @@ -67,25 +67,25 @@ public function toMarkdown(?string $linkTextTemplate = null): string;
*
* @throws DOMException
*/
public function toAnchorTag(?string $linkTextTemplate = null, iterable $attributes = []): string;
public function toHtmlAnchor(?string $linkTextTemplate = null, iterable $attributes = []): string;

/**
* Returns the Link tag content for the current instance.
*
* @param iterable<string, string|null> $attributes an ordered map of key value. you must quote the value if needed
* @param iterable<string, string|null> $attributes an ordered map of key value
*
* @throws DOMException
*/
public function toLinkTag(iterable $attributes = []): string;
public function toHtmlLink(iterable $attributes = []): string;

/**
* Returns the Link header content for a single item.
*
* @param iterable<string, string|int|float|bool> $parameters an ordered map of key value. you must quote the value if needed
* @param iterable<string, string|int|float|bool|null> $parameters an ordered map of key value.
*
* @see https://www.rfc-editor.org/rfc/rfc7230.html#section-3.2.6
*/
public function toLinkHeaderValue(iterable $parameters = []): string;
public function toHeaderLinkValue(iterable $parameters = []): string;

/**
* Returns the Unix filesystem path. The method returns null for any other scheme except the file scheme.
Expand Down
12 changes: 12 additions & 0 deletions FeatureDetection.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
use League\Uri\Exceptions\MissingFeature;
use League\Uri\IPv4\Calculator;

use function extension_loaded;

use const PHP_INT_SIZE;

/**
Expand Down Expand Up @@ -53,4 +55,14 @@ public static function supportsIPv4Conversion(): void
throw new MissingFeature('A '.Calculator::class.' implementation could not be automatically loaded. To perform IPv4 conversion use a x.64 PHP build or install one of the following extension GMP or BCMath. You can also ship your own implmentation.');
}
}

public static function supportsDom(): void
{
static $isSupported = null;
$isSupported = $isSupported ?? extension_loaded('dom');

if (!$isSupported) {
throw new MissingFeature('To use a DOM related feature, the DOM extension must be installed in your system.');
}
}
}

0 comments on commit 4b9bc2f

Please sign in to comment.