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.
<?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.
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