rize/uri-template
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Rize/UriTemplate is a powerful PHP library that offers an implementation of URI Templates according to RFC 6570. This ingenious package grants you the capability to perform both expansion and extraction of URIs. Beyond simple string templating, it also uniquely supports subtypes of URI expressions along with level-based implementation as detailed by RFC6570. It even boasts notable usage in Google Cloud Core and Google Cloud Client Library. The ability to manipulate and infer data from URIs makes this library a crucial tool for developers handling API endpoints.
Using the Rize/UriTemplate package is a breeze. For starters, you must install it via Composer - add "rize/uri-template": "~0.3"
to the require
section of your composer.json file.
Once installed, you can incorporate the package into your code like any standard PHP class. Begin by using the use
statement for Rize\UriTemplate
.
To expand a URI template, you instatiate the UriTemplate class and call the expand
method, passing in the URI pattern and an associative array of variables. For example:
<?php
use Rize\UriTemplate;
$uri = new UriTemplate();
echo $uri->expand('/{username}/profile', ['username' => 'john']); // Outputs: /john/profile
The library also handles complex URI patterns and extraction. Suppose you wish to extract variables from a given URI:
<?php
use Rize\UriTemplate;
$uri = new UriTemplate();
$params = $uri->extract('/search/{term:1}/{term}/{?q*,limit}', '/search/j/john/?q=a&q=b&limit=10');
print_r($params); // Outputs an array with term:1, term, q, limit as keys.
Use this rich functionality to simplify URIs handling and to effectively streamline your coding flow.
The documentation for the Rize/UriTemplate library is primarily contained within the README on the library's GitHub page - https://github.com/rize/UriTemplate. This comprehensive guide takes you through each aspect of this robust library, providing illustrative examples and thorough explanations of both the URI expansion and extraction functionalities. Aimed at quick comprehension, it ensures you are able to efficiently leverage the package in your PHP development efforts. For more complex operational queries, consider the community of developers and users associated with this library β post your queries or explore previous discussions to more deeply understand and apply the offered functionalities.