psx/uri

URI、URL 和 URN 值对象

v3.0.2 2024-05-10 17:59 UTC

This package is auto-updated.

Last update: 2024-09-10 18:44:07 UTC


README

关于

包含用于表示 URI、URL 和 URNs 的值对象的库。值对象是不可变的,所以当你通过 with* 方法更改值时,你会得到该对象的新实例。还有一个 uri 解析类,可以用来解析 URI 与基础 URI。

用法

<?php

$uri = Uri::parse('/bar?foo=bar');

$uri->getPath(); // /bar
$uri->getQuery(); // foo=bar
$uri->getParameters(); // ['foo' => 'bar']

$uri = $uri->withScheme('https');
$uri = $uri->withScheme('foo.com');

echo $uri->toString(); // https://foo.com/bar?foo=bar

// the url object validates whether a scheme and host is available thus it is a valid url
$url = Url::parse($uri->toString());

// a urn provides additional getter to get the urn specific components. A urn must start with urn:
$urn = Urn::parse('urn:uuid:6e8bc430-9c3a-11d9-9669-0800200c9a66');

$urn->getNid(); // uuid
$urn->getNss(); // 6e8bc430-9c3a-11d9-9669-0800200c9a66