Documentation

UriTemplate
in package
implements Stringable

FinalYes

Defines the URI Template syntax and the process for expanding a URI Template into a URI reference.

Tags
link
https://tools.ietf.org/html/rfc6570
author

Ignace Nyamagana Butera nyamsprod@gmail.com

since
6.1.0
phpstan-import-type

InputValue from VariableBag

Table of Contents

Interfaces

Stringable

Properties

$defaultVariables  : VariableBag
$template  : Template

Methods

__construct()  : mixed
__toString()  : string
Returns the string representation of the UriTemplate.
expand()  : UriInterface
expandOrFail()  : UriInterface
expandToPsr7Uri()  : UriInterface
expandToPsr7UriOrFail()  : UriInterface
expandToUri()  : Uri
expandToUriOrFail()  : Uri
expandToUrl()  : Url
expandToUrlOrFail()  : Url
getDefaultVariables()  : array<string, InputValue>
getTemplate()  : string
DEPRECATION WARNING! This method will be removed in the next major point release.
getVariableNames()  : array<string|int, string>
Returns the distinct variables placeholders used in the template.
withDefaultVariables()  : self
Returns a new instance with the updated default variables.
filterVariables()  : VariableBag
newRfc3986Uri()  : Uri|null
newWhatWgUrl()  : Url|null
templateExpanded()  : string
templateExpandedOrFail()  : string

Properties

$defaultVariables read-only

private VariableBag $defaultVariables

Methods

__construct()

public __construct(Stringable|string $template[, iterable<string|int, mixed> $defaultVariables = [] ]) : mixed
Parameters
$template : Stringable|string
$defaultVariables : iterable<string|int, mixed> = []
Tags
throws
SyntaxError

if the template syntax is invalid

throws
TemplateCanNotBeExpanded

if the template or the variables are invalid

__toString()

Returns the string representation of the UriTemplate.

public __toString() : string
Return values
string

expandOrFail()

public expandOrFail([iterable<string|int, mixed> $variables = [] ][, Uri|Url|Stringable|string|null $baseUri = null ]) : UriInterface
Parameters
$variables : iterable<string|int, mixed> = []
$baseUri : Uri|Url|Stringable|string|null = null
Tags
throws
TemplateCanNotBeExpanded

if the variables are invalid or missing

throws
UriException

if the resulting expansion cannot be converted to a UriInterface instance

Return values
UriInterface

expandToPsr7Uri()

public expandToPsr7Uri([iterable<string|int, mixed> $variables = [] ][, Uri|Url|Stringable|string|null $baseUrl = null ][, UriFactoryInterface $uriFactory = new HttpFactory() ]) : UriInterface
Parameters
$variables : iterable<string|int, mixed> = []
$baseUrl : Uri|Url|Stringable|string|null = null
$uriFactory : UriFactoryInterface = new HttpFactory()
Tags
throws
TemplateCanNotBeExpanded

if the variables are invalid

throws
UriException

if the resulting expansion cannot be converted to a UriInterface instance

Return values
UriInterface

expandToPsr7UriOrFail()

public expandToPsr7UriOrFail([iterable<string|int, mixed> $variables = [] ][, Uri|Url|Stringable|string|null $baseUrl = null ][, UriFactoryInterface $uriFactory = new HttpFactory() ]) : UriInterface
Parameters
$variables : iterable<string|int, mixed> = []
$baseUrl : Uri|Url|Stringable|string|null = null
$uriFactory : UriFactoryInterface = new HttpFactory()
Tags
throws
TemplateCanNotBeExpanded

if the variables are invalid

throws
UriException

if the resulting expansion cannot be converted to a UriInterface instance

Return values
UriInterface

expandToUri()

public expandToUri([iterable<string|int, mixed> $variables = [] ][, Uri|Url|Stringable|string|null $baseUri = null ]) : Uri
Parameters
$variables : iterable<string|int, mixed> = []
$baseUri : Uri|Url|Stringable|string|null = null
Tags
throws
MissingFeature

if no Uri\Rfc3986\Uri class is found

throws
TemplateCanNotBeExpanded

if the variables are invalid

throws
InvalidUriException

if the base URI cannot be converted to a Uri\Rfc3986\Uri instance

throws
InvalidUriException

if the resulting expansion cannot be converted to a Uri\Rfc3986\Uri instance

Return values
Uri

expandToUriOrFail()

public expandToUriOrFail([iterable<string|int, mixed> $variables = [] ][, Uri|Url|Stringable|string|null $baseUri = null ]) : Uri
Parameters
$variables : iterable<string|int, mixed> = []
$baseUri : Uri|Url|Stringable|string|null = null
Tags
throws
MissingFeature

if no Uri\Rfc3986\Uri class is found

throws
TemplateCanNotBeExpanded

if the variables are invalid

throws
InvalidUriException

if the base URI cannot be converted to a Uri\Rfc3986\Uri instance

throws
InvalidUriException

if the resulting expansion cannot be converted to a Uri\Rfc3986\Uri instance

Return values
Uri

expandToUrl()

public expandToUrl([iterable<string|int, mixed> $variables = [] ][, Uri|Url|Stringable|string|null $baseUrl = null ][, array<string|int, mixed>|null &$errors = [] ]) : Url
Parameters
$variables : iterable<string|int, mixed> = []
$baseUrl : Uri|Url|Stringable|string|null = null
$errors : array<string|int, mixed>|null = []
Tags
throws
MissingFeature

if no Uri\Whatwg\Url class is found

throws
TemplateCanNotBeExpanded

if the variables are invalid

throws
InvalidUrlException

if the base URI cannot be converted to a Uri\Whatwg\Url instance

throws
InvalidUrlException

if the resulting expansion cannot be converted to a Uri\Whatwg\Url instance

Return values
Url

expandToUrlOrFail()

public expandToUrlOrFail([iterable<string|int, mixed> $variables = [] ][, Uri|Url|Stringable|string|null $baseUrl = null ][, array<string|int, mixed>|null &$errors = [] ]) : Url
Parameters
$variables : iterable<string|int, mixed> = []
$baseUrl : Uri|Url|Stringable|string|null = null
$errors : array<string|int, mixed>|null = []
Tags
throws
MissingFeature

if no Uri\Whatwg\Url class is found

throws
TemplateCanNotBeExpanded

if the variables are invalid

throws
InvalidUrlException

if the base URI cannot be converted to a Uri\Whatwg\Url instance

throws
InvalidUrlException

if the resulting expansion cannot be converted to a Uri\Whatwg\Url instance

Return values
Url

getDefaultVariables()

public getDefaultVariables() : array<string, InputValue>
Return values
array<string, InputValue>

getTemplate()

DEPRECATION WARNING! This method will be removed in the next major point release.

public getTemplate() : string

Since version 7.6.0

use League\Uri\UriTemplate::__toString() instead

Tags
codeCoverageIgnore
see
UriTemplate::toString()

Create a new instance from the environment.

Return values
string

getVariableNames()

Returns the distinct variables placeholders used in the template.

public getVariableNames() : array<string|int, string>
Return values
array<string|int, string>

withDefaultVariables()

Returns a new instance with the updated default variables.

public withDefaultVariables(iterable<string|int, mixed> $defaultVariables) : self

This method MUST retain the state of the current instance, and return an instance that contains the modified default variables.

If present, variables whose name is not part of the current template possible variable names are removed.

Parameters
$defaultVariables : iterable<string|int, mixed>
Tags
throws
TemplateCanNotBeExpanded

if the variables are invalid

Return values
self

filterVariables()

private filterVariables(iterable<string|int, mixed> $variables) : VariableBag
Parameters
$variables : iterable<string|int, mixed>
Return values
VariableBag

newRfc3986Uri()

private newRfc3986Uri([Uri|Url|Stringable|string|null $uri = null ]) : Uri|null
Parameters
$uri : Uri|Url|Stringable|string|null = null
Tags
throws
InvalidUriException
Return values
Uri|null

newWhatWgUrl()

private newWhatWgUrl([Uri|Url|Stringable|string|null $url = null ]) : Url|null
Parameters
$url : Uri|Url|Stringable|string|null = null
Tags
throws
InvalidUrlException
Return values
Url|null

templateExpanded()

private templateExpanded([iterable<string|int, mixed> $variables = [] ]) : string
Parameters
$variables : iterable<string|int, mixed> = []
Return values
string

templateExpandedOrFail()

private templateExpandedOrFail([iterable<string|int, mixed> $variables = [] ]) : string
Parameters
$variables : iterable<string|int, mixed> = []
Return values
string

        
On this page

Search results