Skip to content

Commit

Permalink
Add support for out-of-order named arguments (Fix #7) (#8)
Browse files Browse the repository at this point in the history
* Add support for out-of-order named arguments

* Just use var_export
  • Loading branch information
olvlvl authored Mar 19, 2023
1 parent 3bd1168 commit 8292473
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
4 changes: 1 addition & 3 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@
use ReflectionMethod;

use function array_filter;
use function array_map;
use function array_merge;
use function file_put_contents;
use function implode;
use function is_string;
use function spl_autoload_register;
use function var_export;
Expand Down Expand Up @@ -267,7 +265,7 @@ private static function renderTargetMethods(array $methods): string
*/
private static function renderArguments(array $array): string
{
return '[' . implode(', ', array_map(fn($v) => var_export($v, true), $array)) . ']';
return var_export($array, true);
}

/**
Expand Down
7 changes: 6 additions & 1 deletion tests/Acme/Attribute/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@
#[Attribute(Attribute::TARGET_METHOD)]
final class Route
{
/**
* @param string|string[] $method
*/
public function __construct(
public string $pattern
public string $pattern,
public string|array $method = 'GET',
public ?string $id = null,
) {
}
}
4 changes: 2 additions & 2 deletions tests/Acme/PSR4/Presentation/ArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
#[Resource("articles")]
final class ArticleController
{
#[Route("/articles")]
#[Route(method: 'GET', id: 'articles:list', pattern: "/articles")]
public function list(): void
{
}

#[Route("/articles/{id}")]
#[Route(id: 'articles:show', pattern: "/articles/{id}", method: 'GET')]
public function show(int $id): void
{
}
Expand Down
8 changes: 4 additions & 4 deletions tests/PluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ public function testDump(): void
$targets = Attributes::findTargetMethods(Route::class);

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

$this->assertEquals([
'list' => [ new Route("/articles") ],
'show' => [ new Route("/articles/{id}") ],
'list' => [ new Route("/articles", id: 'articles:list') ],
'show' => [ new Route("/articles/{id}", id: 'articles:show') ],
], $forClass->methodsAttributes);
}

Expand Down

0 comments on commit 8292473

Please sign in to comment.