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

CONSTRAINT_FRAGMENT

HTTP_DEFAULT_HOST

Methods

static UriConstraints
create()

Create a new instance without any constraints

static UriConstraints
fromUri(UriInterface $uri)

Create a new instance with constraints extracted from the given $uri

merge(UriConstraints $uriConstraints)

Merge two instances of UriConstraints Constraints of the given $uriConstraints instance will overrule similar constraints of this instance

withScheme(string $scheme)

Create a new instance with the scheme constraint added

withHost(string $host)

Create a new instance with the host constraint added

withHostPrefix(string $prefix, array $replacePrefixes = [])

Create a new instance with the host prefix constraint added

withHostSuffix(string $suffix, array $replaceSuffixes = [])

Create a new instance with the host suffix constraint added

withPort(int $port)

Create a new instance with the port constraint added

withPath(string $path)

Create a new instance with the path constraint added

withQueryString(string $queryString)

Create a new instance with the query string constraint added

withAddedQueryValues(array $values)

Create a new instance with a query string corresponding to the given $values merged with any existing query string constraint

withFragment(string $fragment)

Create a new instance with the fragment constraint added

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

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() deprecated

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)

UriInterface
toUri()

No description

Details

static UriConstraints create()

Create a new instance without any constraints

Return Value

UriConstraints

static UriConstraints fromUri(UriInterface $uri)

Create a new instance with constraints extracted from the given $uri

Parameters

UriInterface $uri

Return Value

UriConstraints

UriConstraints merge(UriConstraints $uriConstraints)

Merge two instances of UriConstraints Constraints of the given $uriConstraints instance will overrule similar constraints of this instance

Parameters

UriConstraints $uriConstraints

Return Value

UriConstraints

UriConstraints withScheme(string $scheme)

Create a new instance with the scheme constraint added

Parameters

string $scheme

The URI scheme to force, usually "http" or "https"

Return Value

UriConstraints

UriConstraints withHost(string $host)

Create a new instance with the host constraint added

Parameters

string $host

The URI host part to force, for example "neos.io"

Return Value

UriConstraints

UriConstraints withHostPrefix(string $prefix, array $replacePrefixes = [])

Create a new instance with the host prefix constraint added

Parameters

string $prefix

The URI host prefix to force, for example "en."

array $replacePrefixes

a list of prefixes that should be replaced with the given prefix. if the list is empty or does not match the current host $prefix will be prepended as is

Return Value

UriConstraints

UriConstraints withHostSuffix(string $suffix, array $replaceSuffixes = [])

Create a new instance with the host suffix constraint added

Parameters

string $suffix

The URI host suffix to force, for example ".com"

array $replaceSuffixes

a list of suffixes that should be replaced with the given suffix. if the list is empty or does not match, no replacement happens

Return Value

UriConstraints

UriConstraints withPort(int $port)

Create a new instance with the port constraint added

Parameters

int $port

The URI port to force, for example 80

Return Value

UriConstraints

UriConstraints withPath(string $path)

Create a new instance with the path constraint added

Parameters

string $path

The URI path to force, for example "some/path/"

Return Value

UriConstraints

UriConstraints withQueryString(string $queryString)

Create a new instance with the query string constraint added

Parameters

string $queryString

Return Value

UriConstraints

UriConstraints withAddedQueryValues(array $values)

Create a new instance with a query string corresponding to the given $values merged with any existing query string constraint

Parameters

array $values

Return Value

UriConstraints

UriConstraints withFragment(string $fragment)

Create a new instance with the fragment constraint added

Parameters

string $fragment

Return Value

UriConstraints

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

Parameters

string $pathPrefix

The URI path prefix to force, for example "some-prefix/"

bool $append

If true the $pathPrefix will be added after previous path prefix constraints. By default prefixes are added before any existing prefix

Return Value

UriConstraints

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

Parameters

string $pathSuffix

The URI path suffix to force, for example ".html"

bool $prepend

If true the $pathSuffix will be added before previous path suffix constraints. By default suffixes are added after any existing suffix

Return Value

UriConstraints

string|null getPathConstraint() deprecated

deprecated With Flow 7.0, use toUri()->getPath() and/or toUri()->getQuery() instead. @see toUri()

Returns the URI path constraint, which consists of the path and query string parts, or NULL if none was set

Return Value

string|null

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)

Parameters

UriInterface $baseUri

The base URI to transform, usually the current request's base URI

bool $forceAbsoluteUri

Whether or not to enforce the resulting URI to contain scheme and host (note: some of the constraints force an absolute URI by default)

Return Value

UriInterface

The transformed URI with all constraints applied

UriInterface toUri()

No description

Return Value

UriInterface