php-dto/uri

Immutable uri object with validation and helpful methods

0.1.0 2022-11-10 12:53 UTC

This package is not auto-updated.

Last update: 2024-04-26 18:09:19 UTC


README

Installation

composer require php-dto/uri

Usage

<?php

$uri = new \PhpDto\Uri\Uri('https://foo@test.example.com:42?query#');

echo $uri->get(); //will print https://foo@test.example.com:42?query#
echo (string) $uri; //will print https://foo@test.example.com:42?query#

print_r($uri->getComponents());
//will print
array(
  'scheme' => 'https',           // the URI scheme component
  'user' => 'foo',              // the URI user component
  'pass' => null,               // the URI pass component
  'host' => 'test.example.com', // the URI host component
  'port' => 42,                 // the URI port component
  'path' => '',                 // the URI path component
  'query' => 'query',           // the URI query component
  'fragment' => '',             // the URI fragment component
);

new \PhpDto\Uri\Uri('http://test.com', ['https',]); //will throw \PhpDto\Uri\Exception\UriException (allows only `https` scheme)