Skip to content
This repository has been archived by the owner on Nov 8, 2020. It is now read-only.

Commit

Permalink
Parameters with placeholder names
Browse files Browse the repository at this point in the history
  • Loading branch information
klapuch committed Mar 25, 2017
1 parent 8fe22c1 commit 661e0ad
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
12 changes: 5 additions & 7 deletions Core/HttpRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@ public function action(): string {
}

public function parameters(): array {
$parameters = array_values(
array_diff(
explode(self::DELIMITER, $this->uri->path()),
explode(self::DELIMITER, $this->source)
)
$sources = explode(self::DELIMITER, $this->source);
$parameters = array_diff(explode(self::DELIMITER, $this->uri->path()), $sources);
return array_combine(
str_replace(['{', '}'], '', array_intersect_key($sources, $parameters)),
array_map('intval', array_filter($parameters, 'is_numeric')) + $parameters
);
return array_map('intval', array_filter($parameters, 'is_numeric'))
+ $parameters;
}
}
4 changes: 2 additions & 2 deletions Tests/Unit/HttpRoute.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ final class HttpRoute extends Tester\TestCase {

public function testExtractingMatchedParameters() {
Assert::same(
['foo', 'cool'],
['foo' => 'foo', 'adjective' => 'cool'],
(new Routing\HttpRoute(
'/books/{foo}/{adjective}',
'Foo/bar',
Expand All @@ -49,7 +49,7 @@ final class HttpRoute extends Tester\TestCase {

public function testTypeAwareParameters() {
Assert::same(
[1, 123456789, '1ab', 'ba1'],
['a' => 1, 'b' => 123456789, 'c' => '1ab', 'd' => 'ba1'],
(new Routing\HttpRoute(
'/books/{a}/{b}/{c}/{d}',
'Foo/bar',
Expand Down

0 comments on commit 661e0ad

Please sign in to comment.