UrlValidator
in package
Validates service URLs for security requirements.
Table of Contents
Methods
- validateDomain() : void
- Validates that a string is a safe domain name for URL construction.
- validateHttpsRequired() : void
- Validates that a service URL uses HTTPS.
- validatePathSegment() : void
- Validates that a string is safe to use as a URL path segment.
Methods
validateDomain()
Validates that a string is a safe domain name for URL construction.
public
static validateDomain(string $domain) : void
Rejects values containing path separators, traversal sequences, whitespace, query/fragment delimiters, null bytes, or other characters not valid in hostnames. Only allows alphanumeric characters, hyphens, dots, colons (for ports), and square brackets (for IPv6 literals).
Parameters
- $domain : string
-
The domain to validate
Tags
validateHttpsRequired()
Validates that a service URL uses HTTPS.
public
static validateHttpsRequired(string $url) : void
HTTP is only allowed for localhost and 127.0.0.1 to support local development. All other URLs must use HTTPS to protect sensitive data in transit.
Parameters
- $url : string
-
The service URL to validate
Tags
validatePathSegment()
Validates that a string is safe to use as a URL path segment.
public
static validatePathSegment(string $value, string $paramName) : void
Rejects values that contain path traversal sequences, path separators, query/fragment delimiters, null bytes, or are empty.
Parameters
- $value : string
-
The value to validate
- $paramName : string
-
The parameter name for error messages