innmind / url-template
Url template expansion processor
3.1.0
2023-09-16 16:47 UTC
Requires
- php: ~8.2
- innmind/immutable: ~4.3|~5.0
- innmind/url: ~4.1
Requires (Dev)
- innmind/black-box: ~5.5
- innmind/coding-standard: ~2.0
- phpunit/phpunit: ~10.2
- vimeo/psalm: ~5.12
README
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).