Skip to content

Commit 8292473

Browse files
authored
Add support for out-of-order named arguments (Fix #7) (#8)
* Add support for out-of-order named arguments * Just use var_export
1 parent 3bd1168 commit 8292473

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

src/Plugin.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@
2424
use ReflectionMethod;
2525

2626
use function array_filter;
27-
use function array_map;
2827
use function array_merge;
2928
use function file_put_contents;
30-
use function implode;
3129
use function is_string;
3230
use function spl_autoload_register;
3331
use function var_export;
@@ -267,7 +265,7 @@ private static function renderTargetMethods(array $methods): string
267265
*/
268266
private static function renderArguments(array $array): string
269267
{
270-
return '[' . implode(', ', array_map(fn($v) => var_export($v, true), $array)) . ']';
268+
return var_export($array, true);
271269
}
272270

273271
/**

tests/Acme/Attribute/Route.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,13 @@
1414
#[Attribute(Attribute::TARGET_METHOD)]
1515
final class Route
1616
{
17+
/**
18+
* @param string|string[] $method
19+
*/
1720
public function __construct(
18-
public string $pattern
21+
public string $pattern,
22+
public string|array $method = 'GET',
23+
public ?string $id = null,
1924
) {
2025
}
2126
}

tests/Acme/PSR4/Presentation/ArticleController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
#[Resource("articles")]
1616
final class ArticleController
1717
{
18-
#[Route("/articles")]
18+
#[Route(method: 'GET', id: 'articles:list', pattern: "/articles")]
1919
public function list(): void
2020
{
2121
}
2222

23-
#[Route("/articles/{id}")]
23+
#[Route(id: 'articles:show', pattern: "/articles/{id}", method: 'GET')]
2424
public function show(int $id): void
2525
{
2626
}

tests/PluginTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ public function testDump(): void
100100
$targets = Attributes::findTargetMethods(Route::class);
101101

102102
$this->assertEquals([
103-
[ new Route("/articles"), 'Acme\PSR4\Presentation\ArticleController::list' ],
104-
[ new Route("/articles/{id}"), 'Acme\PSR4\Presentation\ArticleController::show' ],
103+
[ new Route("/articles", 'GET', 'articles:list'), 'Acme\PSR4\Presentation\ArticleController::list' ],
104+
[ new Route("/articles/{id}", 'GET', 'articles:show'), 'Acme\PSR4\Presentation\ArticleController::show' ],
105105
[ new Route("/files"), 'Acme\Presentation\FileController::list' ],
106106
[ new Route("/files/{id}"), 'Acme\Presentation\FileController::show' ],
107107
[ new Route("/images"), 'Acme\Presentation\ImageController::list' ],
@@ -122,8 +122,8 @@ public function testDump(): void
122122
], $forClass->classAttributes);
123123

124124
$this->assertEquals([
125-
'list' => [ new Route("/articles") ],
126-
'show' => [ new Route("/articles/{id}") ],
125+
'list' => [ new Route("/articles", id: 'articles:list') ],
126+
'show' => [ new Route("/articles/{id}", id: 'articles:show') ],
127127
], $forClass->methodsAttributes);
128128
}
129129

0 commit comments

Comments
 (0)