From 365d2834b7b7a7d9b5c0a81aa532a30429edb576 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Sat, 27 May 2023 11:35:24 +0900 Subject: [PATCH 1/5] Bind ReverseLinkerInterface --- .../Representation/RouterReverseLink.php | 0 src/Context/HalModule.php | 3 ++ .../Representation/RouterReverseLinker.php | 36 +++++++++++++++++++ .../Representation/HalRendererTest.php | 6 ++-- 4 files changed, 42 insertions(+), 3 deletions(-) rename {src => src-deprecated}/Provide/Representation/RouterReverseLink.php (100%) create mode 100644 src/Provide/Representation/RouterReverseLinker.php diff --git a/src/Provide/Representation/RouterReverseLink.php b/src-deprecated/Provide/Representation/RouterReverseLink.php similarity index 100% rename from src/Provide/Representation/RouterReverseLink.php rename to src-deprecated/Provide/Representation/RouterReverseLink.php diff --git a/src/Context/HalModule.php b/src/Context/HalModule.php index 464218ce..265d89be 100644 --- a/src/Context/HalModule.php +++ b/src/Context/HalModule.php @@ -6,8 +6,10 @@ use BEAR\Package\Provide\Representation\CreatedResourceRenderer; use BEAR\Package\Provide\Representation\RouterReverseLink; +use BEAR\Package\Provide\Representation\RouterReverseLinker; use BEAR\Resource\HalRenderer; use BEAR\Resource\RenderInterface; +use BEAR\Resource\ReverseLinkerInterface; use BEAR\Resource\ReverseLinkInterface; use Ray\Di\AbstractModule; @@ -20,6 +22,7 @@ protected function configure(): void { $this->bind(CreatedResourceRenderer::class); $this->bind(RenderInterface::class)->to(HalRenderer::class); + $this->bind(ReverseLinkerInterface::class)->to(RouterReverseLinker::class); $this->bind(ReverseLinkInterface::class)->to(RouterReverseLink::class); } } diff --git a/src/Provide/Representation/RouterReverseLinker.php b/src/Provide/Representation/RouterReverseLinker.php new file mode 100644 index 00000000..a8f1e6b3 --- /dev/null +++ b/src/Provide/Representation/RouterReverseLinker.php @@ -0,0 +1,36 @@ +router->generate($routeName, $query); + if (is_string($reverseUri)) { + return $reverseUri; + } + + return $uri; + } +} diff --git a/tests/Provide/Representation/HalRendererTest.php b/tests/Provide/Representation/HalRendererTest.php index aec09855..436fc967 100644 --- a/tests/Provide/Representation/HalRendererTest.php +++ b/tests/Provide/Representation/HalRendererTest.php @@ -6,7 +6,7 @@ use BEAR\Package\AppInjector; use BEAR\Package\Exception\LocationHeaderRequestException; -use BEAR\Resource\HalLink; +use BEAR\Resource\HalLinker; use BEAR\Resource\HalRenderer; use BEAR\Resource\ResourceInterface; use BEAR\Resource\ResourceObject; @@ -158,7 +158,7 @@ public function testOptions(): void public function testHalRendererNoParam(): void { - $halRenderer = new HalRenderer(new AnnotationReader(), new HalLink(new RouterReverseLink(new FakeRouter()))); + $halRenderer = new HalRenderer(new AnnotationReader(), new HalLinker(new RouterReverseLinker(new FakeRouter()))); $ro = new Task(); $ro->onPost(); $ro->uri = new Uri('app://self/task'); @@ -178,7 +178,7 @@ public function testHalRendererNoParam(): void public function testHalRendererWithParam(): void { - $halRenderer = new HalRenderer(new AnnotationReader(), new HalLink(new RouterReverseLink(new FakeRouter()))); + $halRenderer = new HalRenderer(new AnnotationReader(), new HalLinker(new RouterReverseLinker(new FakeRouter()))); $ro = new Task(); $ro->uri = new Uri('app://self/task?id=1'); $ro->uri->method = 'post'; From 4c2b81138f3c3438194789f3495be6cd264c0e2d Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Sat, 27 May 2023 11:35:45 +0900 Subject: [PATCH 2/5] Update fake routing --- tests/Fake/Provide/Representation/FakeRouter.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/Fake/Provide/Representation/FakeRouter.php b/tests/Fake/Provide/Representation/FakeRouter.php index e3f4d611..90d0934b 100644 --- a/tests/Fake/Provide/Representation/FakeRouter.php +++ b/tests/Fake/Provide/Representation/FakeRouter.php @@ -22,6 +22,10 @@ public function generate($name, $data) { unset($name); - return '/task/' . $data['id']; + if (isset($data['id'])) { + return '/task/' . $data['id']; + } + + return '/task'; } } From 7d792b99726da3e573f75d16589c0dde946ce84b Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Tue, 25 Jul 2023 01:36:05 +0900 Subject: [PATCH 3/5] Update bear/resource ^1.20 to enable reverse_link --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8d9e38ad..e61a6b9a 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "aura/cli": "^2.2", "bear/app-meta": "^1.8", "bear/query-repository": "^1.9.1", - "bear/resource": "^1.19", + "bear/resource": "^1.20", "bear/streamer": "^1.2.2", "bear/sunday": "^1.6.1", "monolog/monolog": "^1.25 || ^2.0", From d9fa6a5024647cb32a5081e920b49062ae6cfa65 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Tue, 25 Jul 2023 01:55:00 +0900 Subject: [PATCH 4/5] Ignore ReverseLinkInterface --- composer-require-checker.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer-require-checker.json b/composer-require-checker.json index 5512abd2..cfb90ff2 100644 --- a/composer-require-checker.json +++ b/composer-require-checker.json @@ -3,6 +3,7 @@ "null", "true", "false", "static", "self", "parent", "array", "string", "int", "float", "bool", "iterable", "callable", "void", "object", "mixed", - "Composer\\Autoload\\ClassLoader", "Doctrine\\Common\\Cache\\FilesystemCache", "Doctrine\\Common\\Cache\\PhpFileCache" + "Composer\\Autoload\\ClassLoader", "Doctrine\\Common\\Cache\\FilesystemCache", "Doctrine\\Common\\Cache\\PhpFileCache", + "BEAR\\Resource\\ReverseLinkInterface" ] } From ac593189af90ca0ef08b512654d015d2cd8a03f1 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Tue, 25 Jul 2023 02:54:02 +0900 Subject: [PATCH 5/5] Add @codeCoverageIgnoreEnd --- src/Compiler/Bootstrap.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Compiler/Bootstrap.php b/src/Compiler/Bootstrap.php index d7ccded1..21e7e163 100644 --- a/src/Compiler/Bootstrap.php +++ b/src/Compiler/Bootstrap.php @@ -53,5 +53,6 @@ public function __invoke(string $appName, string $context, array $globals, array // @codeCoverageIgnoreStart return 0; + // @codeCoverageIgnoreEnd } }