The League of Extraordinary Packages

Our Packages:

Presented by The League of Extraordinary Packages

Getting Started

Uri

Uri Schemes

Uri manipulation

Uri Parts API

Services

Upgrading Guide

This is the documentation for the unsupported version 4.0. Please consider upgrading your code to the latest stable version

Websockets URI

To work with websockets URIs you can use the League\Uri\Schemes\Ws class. This class handles secure and non secure websockets URI.

Validation

Websockets URIs must contain a ws or the wss scheme. It can not contain a fragment component as per RFC6455.

Adding contents to the fragment component throws an InvalidArgumentException exception

<?php

use League\Uri\Schemes\Ws as WsUri;

$uri = WsUri::createFromString('wss://thephpleague.com/path/to?here#content');
//throw an InvalidArgumentException - a fragment component was given

Apart from the fragment, the websockets URIs share the same host validation limitation as Http URIs.

Starting with version 4.2 schemeless FTP Uri will no longer trigger an InvalidArgumentException exception

Properties

Websockets URIs objects uses the specialized HierarchicalPath class to represents its path. using PHP’s magic __get method you can access the object path and get more informations about the underlying path.

<?php

use League\Uri\Schemes\Ws as WsUri;

$uri = WsUri::createFromString('wss://thephpleague.com/path/to?here');
echo $uri->path->getBasename();  //display '/path'
echo $uri->path->getDirname();   //display 'to'
echo $uri->path->getExtension(); //display ''
$uri->path->getSegments(); //returns an array representation of the path segments