Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UriTemplate extraction #1

Open
nyamsprod opened this issue Sep 10, 2022 · 0 comments
Open

UriTemplate extraction #1

nyamsprod opened this issue Sep 10, 2022 · 0 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@nyamsprod
Copy link
Member

nyamsprod commented Sep 10, 2022

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.

@nyamsprod nyamsprod added enhancement New feature or request help wanted Extra attention is needed labels Sep 10, 2022
@nyamsprod nyamsprod transferred this issue from thephpleague/uri Nov 17, 2022
Douglasdc3 added a commit to Douglasdc3/uri-src that referenced this issue Nov 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant