Skip to content

Innmind/UrlTemplate

Repository files navigation

UrlTemplate

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