BREAKING CHANGE: Requires PHP 8.5.0RC3 Changes: - Update Docker base image from php:8.4-fpm to php:8.5.0RC3-fpm - Enable ext-uri for native WHATWG URL parsing support - Update composer.json PHP requirement from ^8.4 to ^8.5 - Add ext-uri as required extension in composer.json - Move URL classes from Url.php85/ to Url/ directory (now compatible) - Remove temporary PHP 8.4 compatibility workarounds Benefits: - Native URL parsing with Uri\WhatWg\Url class - Better performance for URL operations - Future-proof with latest PHP features - Eliminates PHP version compatibility issues
98 lines
2.3 KiB
PHP
98 lines
2.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Framework\Http\Url;
|
|
|
|
/**
|
|
* URL Specification identifier
|
|
*
|
|
* Distinguishes between RFC 3986 and WHATWG URL Standard
|
|
* for different parsing and handling semantics.
|
|
*/
|
|
enum UrlSpec: string
|
|
{
|
|
/**
|
|
* RFC 3986 - Uniform Resource Identifier (URI): Generic Syntax
|
|
*
|
|
* Use for:
|
|
* - Server-side URL canonicalization
|
|
* - API clients (REST, GraphQL, SOAP)
|
|
* - URL signatures and validation
|
|
* - cURL compatibility
|
|
* - File system paths
|
|
*
|
|
* Characteristics:
|
|
* - Strict parsing rules
|
|
* - No automatic encoding
|
|
* - No URL normalization
|
|
* - Preserves original structure
|
|
*
|
|
* Example:
|
|
* ```php
|
|
* $uri = Rfc3986Url::parse('https://api.example.com/users?id=123');
|
|
* ```
|
|
*/
|
|
case RFC3986 = 'rfc3986';
|
|
|
|
/**
|
|
* WHATWG URL Standard (Living Standard)
|
|
*
|
|
* Use for:
|
|
* - Browser-like URL handling
|
|
* - Deep links and redirects
|
|
* - Client-side generated URLs
|
|
* - HTML form actions
|
|
* - JavaScript fetch() API compatibility
|
|
*
|
|
* Characteristics:
|
|
* - Living standard (matches modern browsers)
|
|
* - Automatic percent-encoding
|
|
* - URL normalization
|
|
* - Special scheme handling (http, https, file, etc.)
|
|
*
|
|
* Example:
|
|
* ```php
|
|
* $url = WhatwgUrl::parse('https://example.com/redirect');
|
|
* ```
|
|
*/
|
|
case WHATWG = 'whatwg';
|
|
|
|
/**
|
|
* Get recommended spec for specific use case
|
|
*
|
|
* Automatically selects the appropriate URL specification
|
|
* based on the intended usage pattern.
|
|
*/
|
|
public static function forUseCase(UrlUseCase $useCase): self
|
|
{
|
|
return match ($useCase) {
|
|
UrlUseCase::API_CLIENT,
|
|
UrlUseCase::CURL_REQUEST,
|
|
UrlUseCase::SIGNATURE_GENERATION,
|
|
UrlUseCase::CANONICAL_URL => self::RFC3986,
|
|
|
|
UrlUseCase::BROWSER_REDIRECT,
|
|
UrlUseCase::DEEP_LINK,
|
|
UrlUseCase::HTML_FORM_ACTION,
|
|
UrlUseCase::CLIENT_SIDE_URL => self::WHATWG,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Check if this spec is RFC 3986
|
|
*/
|
|
public function isRfc3986(): bool
|
|
{
|
|
return $this === self::RFC3986;
|
|
}
|
|
|
|
/**
|
|
* Check if this spec is WHATWG
|
|
*/
|
|
public function isWhatwg(): bool
|
|
{
|
|
return $this === self::WHATWG;
|
|
}
|
|
}
|