for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Subreality\Dilmun\Anshar\Http\UriParts;
/**
* Class Scheme
* @package Subreality\Dilmun\Anshar\Http\UriParts
*/
class Scheme
{
private static $valid_pattern = '/^[a-z][\w\+\-\.]*$/i';
* Scheme constructor. Accepts a string representing a URI scheme. Construction will throw an exception if the
* scheme is either not a string or does not conform to the RFC3986 URI scheme specification.
*
* scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
* @see https://tools.ietf.org/html/rfc3986#appendix-A
* @throws \InvalidArgumentException
* @param string $scheme A string representing a URI scheme
public function __construct($scheme)
if (!is_string($scheme)) {
throw new \InvalidArgumentException("Scheme must be a string");
} elseif (!$this->isValid($scheme)) {
throw new \InvalidArgumentException("Scheme must conform to RFC3986 specification");
}
* Determines whether a given scheme adheres to the RFC3986 specification:
* @see Scheme::$valid_pattern
* @param string $scheme The scheme to check for validity
* @return bool Returns true if the provided scheme matches the RFC3986 specification
* Returns false otherwise
public static function isValid($scheme)
return (bool) preg_match(self::$valid_pattern, $scheme);