Documentation

Urn
in package
implements Conditionable, Stringable, JsonSerializable

FinalYes
Tags
phpstan-type

UrnSerialize array{0: array{urn: non-empty-string}, 1: array}}

phpstan-type

UrnMap array{ scheme: 'urn', nid: string, nss: string, r_component: ?string, q_component: ?string, f_component: ?string, }

phpstan-import-type

InputComponentMap from UriString

Table of Contents

Interfaces

Conditionable
Stringable
JsonSerializable

Constants

REGEX_NID_SEQUENCE  = '/^[a-z0-9]([a-z0-9-]{0,30})[a-z0-9]$/xi'
RFC8141 namespace identifier regular expression.
REGEXP_URN_PARTS  = '/^ urn: (?<nid>[a-z0-9](?:[a-z0-9-]{0,30}[a-z0-9])?): # NID (?<nss>.*?) # NSS (?<frc>\?\+(?<rcomponent>.*?))? # r-component (?<fqc>\?\=(?<qcomponent>.*?))? # q-component (?:\#(?<fcomponent>.*))? # f-component $/xi'
RFC8141 regular expression URN splitter.

Properties

$fComponent  : non-empty-string|null
$nid  : non-empty-string
$nss  : non-empty-string
$qComponent  : non-empty-string|null
$rComponent  : non-empty-string|null
$uriString  : non-empty-string

Methods

__debugInfo()  : UrnMap
__serialize()  : UrnSerialize
__toString()  : non-empty-string
Returns the RFC8141 URN string representation.
__unserialize()  : void
equals()  : bool
fromComponents()  : self
Create a new instance from a hash representation of the URI similar to PHP parse_url function result.
fromRfc2141()  : self
fromString()  : self
getFComponent()  : non-empty-string|null
Returns the percent-encoded f-component string or null if it is not set.
getNid()  : non-empty-string
Returns the NID.
getNss()  : non-empty-string
Returns the percent-encoded NSS.
getQComponent()  : non-empty-string|null
Returns the percent-encoded q-component string or null if it is not set.
getRComponent()  : non-empty-string|null
Returns the percent-encoded r-component string or null if it is not set.
hasFComponent()  : bool
hasOptionalComponent()  : bool
hasQComponent()  : bool
hasRComponent()  : bool
jsonSerialize()  : non-empty-string
Returns the RFC8141 URN string representation.
new()  : self
normalize()  : self
parse()  : Urn|null
resolve()  : UriInterface
Returns the RFC3986 representation of the current URN.
toComponents()  : UrnMap
toDisplayString()  : string
Returns the human-readable string representation of the URN as an IRI.
toRfc2141()  : non-empty-string
Returns the RFC2141 URN string representation.
toString()  : non-empty-string
Returns the RFC8141 URN string representation.
when()  : static
Apply the callback if the given "condition" is (or resolves to) true.
withFComponent()  : self
Return an instance with the specified f-component.
withNid()  : self
Return an instance with the specified NID.
withNss()  : self
Return an instance with the specified NSS.
withQComponent()  : self
Return an instance with the specified q-component.
withRComponent()  : self
Return an instance with the specified r-component.
__construct()  : mixed
formatComponent()  : string|null
setUriString()  : non-empty-string

Constants

REGEXP_URN_PARTS

RFC8141 regular expression URN splitter.

private string REGEXP_URN_PARTS = '/^ urn: (?<nid>[a-z0-9](?:[a-z0-9-]{0,30}[a-z0-9])?): # NID (?<nss>.*?) # NSS (?<frc>\?\+(?<rcomponent>.*?))? # r-component (?<fqc>\?\=(?<qcomponent>.*?))? # q-component (?:\#(?<fcomponent>.*))? # f-component $/xi'

The regexp does not perform any look-ahead. Not all invalid URN are caught. Some post-regexp-validation checks are mandatory.

Tags
link
https://datatracker.ietf.org/doc/html/rfc8141#section-2

Properties

$fComponent read-only

private non-empty-string|null $fComponent

$nid read-only

private non-empty-string $nid

$nss read-only

private non-empty-string $nss

$qComponent read-only

private non-empty-string|null $qComponent

$rComponent read-only

private non-empty-string|null $rComponent

$uriString read-only

private non-empty-string $uriString

Methods

__debugInfo()

public __debugInfo() : UrnMap
Return values
UrnMap

__serialize()

public __serialize() : UrnSerialize
Return values
UrnSerialize

__toString()

Returns the RFC8141 URN string representation.

public __toString() : non-empty-string
Tags
see
self::toString()
Return values
non-empty-string

__unserialize()

public __unserialize(UrnSerialize $data) : void
Parameters
$data : UrnSerialize
Tags
throws
SyntaxError

fromComponents()

Create a new instance from a hash representation of the URI similar to PHP parse_url function result.

public static fromComponents([InputComponentMap $components = [] ]) : self
Parameters
$components : InputComponentMap = []

a hash representation of the URI similar to PHP parse_url function result

Return values
self

fromString()

public static fromString(Uri|Url|Stringable|string $urn) : self
Parameters
$urn : Uri|Url|Stringable|string

the percent-encoded URN

Tags
throws
SyntaxError

if the URN is invalid

Return values
self

getFComponent()

Returns the percent-encoded f-component string or null if it is not set.

public getFComponent() : non-empty-string|null
Return values
non-empty-string|null

getNid()

Returns the NID.

public getNid() : non-empty-string
Return values
non-empty-string

getNss()

Returns the percent-encoded NSS.

public getNss() : non-empty-string
Return values
non-empty-string

getQComponent()

Returns the percent-encoded q-component string or null if it is not set.

public getQComponent() : non-empty-string|null
Return values
non-empty-string|null

getRComponent()

Returns the percent-encoded r-component string or null if it is not set.

public getRComponent() : non-empty-string|null
Return values
non-empty-string|null

hasFComponent()

public hasFComponent() : bool
Return values
bool

hasOptionalComponent()

public hasOptionalComponent() : bool
Return values
bool

hasQComponent()

public hasQComponent() : bool
Return values
bool

hasRComponent()

public hasRComponent() : bool
Return values
bool

jsonSerialize()

Returns the RFC8141 URN string representation.

public jsonSerialize() : non-empty-string
Tags
see
self::toString()
Return values
non-empty-string

new()

public static new(Uri|Url|Stringable|string $urn) : self
Parameters
$urn : Uri|Url|Stringable|string

the percent-encoded URN

Tags
see
self::fromString()
throws
SyntaxError

if the URN is invalid

Return values
self

normalize()

public normalize() : self
Return values
self

parse()

public static parse(Uri|Url|Stringable|string $urn) : Urn|null
Parameters
$urn : Uri|Url|Stringable|string

the percent-encoded URN

Return values
Urn|null

resolve()

Returns the RFC3986 representation of the current URN.

public resolve([UriTemplate|Template|string|null $template = null ]) : UriInterface

If a template URI is used the following variables as present {nid} for the namespace identifier {nss} for the namespace specific string {r_component} for the r-component without its delimiter {q_component} for the q-component without its delimiter {f_component} for the f-component without its delimiter

Parameters
$template : UriTemplate|Template|string|null = null
Return values
UriInterface

toComponents()

public toComponents() : UrnMap
Return values
UrnMap

toRfc2141()

Returns the RFC2141 URN string representation.

public toRfc2141() : non-empty-string
Return values
non-empty-string

toString()

Returns the RFC8141 URN string representation.

public toString() : non-empty-string
Return values
non-empty-string

when()

Apply the callback if the given "condition" is (or resolves to) true.

public when(callable|bool $condition, callable $onSuccess[, callable|null $onFail = null ]) : static
Parameters
$condition : callable|bool
$onSuccess : callable
$onFail : callable|null = null
Return values
static

withFComponent()

Return an instance with the specified f-component.

public withFComponent(Stringable|string|null $component) : self

This method MUST retain the state of the current instance, and return an instance that contains the specified f-component.

The component is removed if the value is null.

Parameters
$component : Stringable|string|null
Tags
throws
SyntaxError

for invalid component or transformations that would result in an object in invalid state.

Return values
self

withNid()

Return an instance with the specified NID.

public withNid(Stringable|string $nid) : self

This method MUST retain the state of the current instance, and return an instance that contains the specified NID.

Parameters
$nid : Stringable|string
Tags
throws
SyntaxError

for invalid component or transformations that would result in an object in invalid state.

Return values
self

withNss()

Return an instance with the specified NSS.

public withNss(Stringable|string $nss) : self

This method MUST retain the state of the current instance, and return an instance that contains the specified NSS.

Parameters
$nss : Stringable|string
Tags
throws
SyntaxError

for invalid component or transformations that would result in an object in invalid state.

Return values
self

withQComponent()

Return an instance with the specified q-component.

public withQComponent(Stringable|string|null $component) : self

This method MUST retain the state of the current instance, and return an instance that contains the specified q-component.

The component is removed if the value is null.

Parameters
$component : Stringable|string|null
Tags
throws
SyntaxError

for invalid component or transformations that would result in an object in invalid state.

Return values
self

withRComponent()

Return an instance with the specified r-component.

public withRComponent(Stringable|string|null $component) : self

This method MUST retain the state of the current instance, and return an instance that contains the specified r-component.

The component is removed if the value is null.

Parameters
$component : Stringable|string|null
Tags
throws
SyntaxError

for invalid component or transformations that would result in an object in invalid state.

Return values
self

__construct()

private __construct(string $nid, string $nss[, string|null $rComponent = null ][, string|null $qComponent = null ][, string|null $fComponent = null ]) : mixed
Parameters
$nid : string
$nss : string

the percent-encoded NSS

$rComponent : string|null = null

the percent-encoded r-component

$qComponent : string|null = null

the percent-encoded q-component

$fComponent : string|null = null

the percent-encoded f-component

Tags
throws
SyntaxError

if one of the URN part is invalid

formatComponent()

private static formatComponent(string|null $component) : string|null
Parameters
$component : string|null
Return values
string|null

setUriString()

private setUriString() : non-empty-string
Return values
non-empty-string

        
On this page

Search results