Feature Request
| Q |
A |
| New Feature |
yes |
| BC Break |
no |
Proposal
Adding the ability to extract variables from an URI using a UriTemplate object.
Proposed public API
use League\Uri\UriTemplate;
use League\Uri\UriTemplate\VariableBag;
$template = 'https://example.com/hotels/{hotel}/bookings/{booking}';
$uriString = 'https://example.com/hotels/Rest%20%26%20Relax/bookings/42';
$uriTemplate = new UriTemplate($template);
$variables = $uriTemplate->extract($uriString);
// the extract method SHOULD accept as input
// - URI implementing objects (league and PSR-7)
// - stringable objects
// - string
// the extract method MUST return a VariableBag object
$variables->isEmpty(); // return false
count($variables); // returns 2
echo $variables['booking']; // returns '42'
echo $variables['hotel]; // returns 'Rest & Relax'
Good to know
- The
VariableBag object already exists
- The internal representation of the UriTemplate broke down into expression and var specifier exists
Todo (implementation)
Create from an League\Uri\UriTemplate\Template object the correct regular expression for each expression and var specifier and process the URI input to get all existing variables.
Feature Request
Proposal
Adding the ability to extract variables from an URI using a
UriTemplateobject.Proposed public API
Good to know
VariableBagobject already existsTodo (implementation)
Create from an
League\Uri\UriTemplate\Templateobject the correct regular expression for each expression and var specifier and process the URI input to get all existing variables.