Skip to content

Commit

Permalink
Allow named groups in regexp URI matches.
Browse files Browse the repository at this point in the history
  • Loading branch information
peej committed Aug 11, 2013
1 parent 3a00507 commit 4f6f9f0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
31 changes: 31 additions & 0 deletions features/issue51.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Feature: Issue 51
In order to make sure issue #51 (https://github.com/peej/tonic/issues/51) is fixed
As a Tonic developer
I want to test the problems in the issue

Scenario: URL template variable should only match a single URL segment
Given a resource definition "issue51" with URI "/issue51/(?P<child>.+)" and priority of 1
And the request URI of "/issue51/1/a"
When I create an application object
And I create a request object
And load the resource
Then the loaded resource should have a class of "issue51"
And the loaded resource should have a param "child" with the value "1/a"

Scenario: URL template variable should only match a single URL segment
Given a resource definition "issue51c" with URI "/issue51c/(.+)" and priority of 1
And the request URI of "/issue51c/1/a"
When I create an application object
And I create a request object
And load the resource
Then the loaded resource should have a class of "issue51c"
And the loaded resource should have a param "0" with the value "1/a"

Scenario: URL template variable should only match a single URL segment
Given a resource definition "issue51b" with URI "/issue51b/{child}" and priority of 1
And the request URI of "/issue51b/1a"
When I create an application object
And I create a request object
And load the resource
Then the loaded resource should have a class of "issue51b"
And the loaded resource should have a param "child" with the value "1a"
7 changes: 5 additions & 2 deletions src/Tonic/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,13 @@ public function getResource($request = NULL)
&&
preg_match($uriRegex, $request->uri, $params)
) {
array_shift($params);
if (count($uri) > 1) { // has params within URI
$params = array_combine($uri, $params);
array_shift($uri);
foreach ($uri as $key => $name) {
$params[$name] = $params[$key];
}
}
array_shift($params);
$matchedResource = array($resourceMetadata, $params);
}
}
Expand Down

0 comments on commit 4f6f9f0

Please sign in to comment.