toxygene/simple-uri-template

There is no license information available for the latest version (2.0.3) of this package.

2.0.3 2016-06-13 21:08 UTC

This package is not auto-updated.

Last update: 2024-03-22 19:27:16 UTC


README

A simple URI template language with a lexer and parsers to output a regular expression or a complete URI.

The primary use case is for assembling and matching path-based routes.

Installation

composer install toxygene/simple-uri-template

Language Definition

   TEMPLATE ::= ( PLACEHOLDER | LITERAL ) { TEMPLATE } *
PLACEHOLDER ::= "{" IDENTIFIER "}"
 IDENTIFIER ::= [a-zA-Z][a-zA-Z0-9]*
    LITERAL ::= [^{}]+

Regex Examples

use Toxygene\SimpleUriTemplate\Lexer;
use Toxygene\SimpleUriTemplate\RegexParser;

$lexer = new Lexer();
$parser = new RegexParser($lexer);

echo $parser->parse('/one/{two}/three'); // #^/one/(?P<two>.+?)/three$#

URI Examples

use Toxygene\SimpleUriTemplate\Lexer;
use Toxygene\SimpleUriTemplate\UriParser;

$lexer = new Lexer();
$parser = new UriParser($lexer);

echo $parser->parse('/one/{two}/three', ['two' => 2]); // /one/2/three