Please consider using the the latest stable version for any production code.

Uri Interfaces

This package contains an interface to represents URI objects according to RFC 3986.

System Requirements

You need:

Install

$ composer require league/uri-interfaces

Documentation

League\Uri\Contract\UriInterface

The UriInterface interface models generic URIs as specified in RFC 3986. The interface provides methods for interacting with the various URI parts, which will obviate the need for repeated parsing of the URI. It also specifies:

Accessing URI properties

The UriInterface interface defines the following methods to access the URI string representation, its individual parts and components.

<?php

public UriInterface::__toString():string
public UriInterface::jsonSerialize():string
public UriInterface::getScheme():?string
public UriInterface::getUserInfo():?string
public UriInterface::getHost():?string
public UriInterface::getPort():?int
public UriInterface::getAuthority():?string
public UriInterface::getPath():string
public UriInterface::getQuery():?string
public UriInterface::getFragment():?string

Modifying URI properties

The Uri interface defines the following modifying methods. these methods must be implemented such that they retain the internal state of the current instance and return an instance that contains the changed state.

Delimiter characters are not part of the URI component and must not be added to the modifying method submitted value. If present they will be treated as part of the URI component content.

These methods will trigger a League\Uri\Contract\UriException exception if the resulting URI is not valid. The validation is scheme dependent.

<?php

public UriInterface::withScheme(?string $scheme): self
public UriInterface::withUserInfo(?string $user [, string $password = null]): self
public UriInterface::withHost(?string $host): self
public UriInterface::withPort(?int $port): self
public UriInterface::withPath(string $path): self
public UriInterface::withQuery(?string $query): self
public UriInterface::withFragment(?string $fragment): self

Relation with PSR-7

This interface exposes the same methods as Psr\Http\Message\UriInterface. But, differs on the following keys:

League\Uri\Contract\UriComponentInterface

The UriComponentInterface interface models generic URI components as specified in RFC 3986. The interface provides methods for interacting with an URI component, which will obviate the need for repeated parsing of the URI component. It also specifies a __toString() method for casting the modeled URI component to its string representation.

Accessing URI properties

The UriComponentInterface interface defines the following methods to access the URI component content.

<?php
public UriComponentInterface::getContent(): ?string
public UriComponentInterface::toString(): ?string
public UriComponentInterface::__toString(): string
public UriComponentInterface::getUriComponent(): ?string
public UriComponentInterface::jsonSerialize(): ?string
public UriComponentInterface::withContent(?string $content): self

UriComponentInterface extended interfaces

Because each URI component has specific needs most have specialized interface which all extends the UriComponentInterface interface. The following interfaces also exist: