Skip to content

Commit ac02641

Browse files
committed
Adding scheme validator
1 parent b3113bc commit ac02641

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

UriString.php

+19
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,25 @@ private static function filterHost(Stringable|string|null $host): ?string
730730
throw new SyntaxError(sprintf('Host `%s` is invalid : the IP host is malformed', $host));
731731
}
732732

733+
/**
734+
* Tells whether the scheme component is valid
735+
*
736+
* @param Stringable|string|null $scheme
737+
*
738+
* @return bool
739+
*/
740+
public static function isScheme(Stringable|string|null $scheme): bool
741+
{
742+
return null === $scheme || 1 === preg_match('/^[A-Za-z]([-A-Za-z\d+.]+)?$/', (string) $scheme);
743+
}
744+
745+
/**
746+
* Tells whether the host component is valid
747+
*
748+
* @param Stringable|string|null $host
749+
*
750+
* @return bool
751+
*/
733752
public static function isHost(Stringable|string|null $host): bool
734753
{
735754
try {

0 commit comments

Comments
 (0)