UriConstraints
final class UriConstraints (View source)
This class allows constraints to be applied to a given URI, transforming it accordingly as a result.
Example:
$exampleUri = new Uri('http://some-domain.tld/foo'); $uriConstraints = UriConstraints::create() ->withScheme('https') ->withHostPrefix('de.', ['en.', 'ch.']) ->withPort(8080) ->withPathPrefix('prefix/'); $resultingUri = $uriConstraints->applyTo($exampleUri); // https://de.some-domain.tld:8080/prefix/foo
Constants
CONSTRAINT_SCHEME |
|
CONSTRAINT_HOST |
|
CONSTRAINT_HOST_PREFIX |
|
CONSTRAINT_HOST_SUFFIX |
|
CONSTRAINT_PORT |
|
CONSTRAINT_PATH |
|
CONSTRAINT_PATH_PREFIX |
|
CONSTRAINT_PATH_SUFFIX |
|
CONSTRAINT_QUERY_STRING |
|
HTTP_DEFAULT_HOST |
|
Methods
Create a new instance without any constraints
Merge two instances of UriConstraints Constraints of the given $uriConstraints instance will overrule similar constraints of this instance
Create a new instance with the scheme constraint added
Create a new instance with the host constraint added
Create a new instance with the host prefix constraint added
Create a new instance with the host suffix constraint added
Create a new instance with the port constraint added
Create a new instance with the path constraint added
Create a new instance with the query string constraint added
Create a new instance with the path prefix constraint added This can be applied multiple times, later prefixes will be prepended to the start
Create a new instance with the path suffix constraint added This can be applied multiple times, later suffixes will be appended to the end
Returns the URI path constraint, which consists of the path and query string parts, or NULL if none was set
Applies all constraints of this instance to the given $templateUri and returns a new UriInterface instance satisfying all of the constraints (see example above)
Details
static UriConstraints
create()
Create a new instance without any constraints
UriConstraints
merge(UriConstraints $uriConstraints)
Merge two instances of UriConstraints Constraints of the given $uriConstraints instance will overrule similar constraints of this instance
UriConstraints
withScheme(string $scheme)
Create a new instance with the scheme constraint added
UriConstraints
withHost(string $host)
Create a new instance with the host constraint added
UriConstraints
withHostPrefix(string $prefix, array $replacePrefixes = [])
Create a new instance with the host prefix constraint added
UriConstraints
withHostSuffix(string $suffix, array $replaceSuffixes = [])
Create a new instance with the host suffix constraint added
UriConstraints
withPort(int $port)
Create a new instance with the port constraint added
UriConstraints
withPath(string $path)
Create a new instance with the path constraint added
UriConstraints
withQueryString(string $queryString)
Create a new instance with the query string constraint added
UriConstraints
withPathPrefix(string $pathPrefix, bool $append = false)
Create a new instance with the path prefix constraint added This can be applied multiple times, later prefixes will be prepended to the start
UriConstraints
withPathSuffix(string $pathSuffix, bool $prepend = false)
Create a new instance with the path suffix constraint added This can be applied multiple times, later suffixes will be appended to the end
string|null
getPathConstraint()
Returns the URI path constraint, which consists of the path and query string parts, or NULL if none was set
UriInterface
applyTo(UriInterface $baseUri, bool $forceAbsoluteUri)
Applies all constraints of this instance to the given $templateUri and returns a new UriInterface instance satisfying all of the constraints (see example above)