innmind/url-template

Url template expansion processor

3.1.0 2023-09-16 16:47 UTC

This package is auto-updated.

Last update: 2024-10-16 19:14:13 UTC


README

Build Status codecov Type Coverage

RFC6570 implementation.

Installation

composer require innmind/url-template

Usage

use Innmind\UrlTemplate\Template;
use Innmind\Immutable\Map;
use Innmind\Url\Url;

$url = Template::of('http://example.com/dictionary/{term:1}/{term}')->expand(
    Map::of(['term', 'dog']),
);
$url instanceof Url; // true
$url->toString(); // http://example.com/dictionary/d/dog

$variables = Template::of('http://example.com/dictionary/{term:1}/{term}')->extract(
    Url::of('http://example.com/dictionary/d/dog')
);
$variables; // Map<string, string>
$variables->size(); // 1
$variables->get('term'); // dog

Important: variable extraction is not supported for list (ie {foo*} expression).