From cb20565ca0f0a63cd5de4146e7c9b83757b3f067 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 15 Dec 2022 11:05:15 +0100 Subject: [PATCH 01/21] Convert test method names to snake_case --- .../tests/Feature/Actions/PublicationPageCompilerTest.php | 4 ++-- packages/framework/tests/Feature/ValidatingCommandTest.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/framework/tests/Feature/Actions/PublicationPageCompilerTest.php b/packages/framework/tests/Feature/Actions/PublicationPageCompilerTest.php index f254c3a8cea..1996d193668 100644 --- a/packages/framework/tests/Feature/Actions/PublicationPageCompilerTest.php +++ b/packages/framework/tests/Feature/Actions/PublicationPageCompilerTest.php @@ -15,7 +15,7 @@ */ class PublicationPageCompilerTest extends TestCase { - public function testCanCompilePublicationPages() + public function test_can_compile_publication_pages() { $this->directory('test-publication'); $this->setupTestPublication(); @@ -27,7 +27,7 @@ public function testCanCompilePublicationPages() $this->assertEquals('Detail: My Publication', $string); } - public function testCanCompilePublicationListPages() + public function test_can_compile_publication_list_pages() { $this->directory('test-publication'); $this->setupTestPublication(); diff --git a/packages/framework/tests/Feature/ValidatingCommandTest.php b/packages/framework/tests/Feature/ValidatingCommandTest.php index 152e72df9f3..de45050350a 100644 --- a/packages/framework/tests/Feature/ValidatingCommandTest.php +++ b/packages/framework/tests/Feature/ValidatingCommandTest.php @@ -199,7 +199,7 @@ public function testInfoCommentWithExtraInfo() class SafeValidatingTestCommand extends ValidatingCommand { - // + // } class SafeThrowingValidatingTestCommand extends ValidatingCommand From bafd0c458c40f36ccd9be28c74877ddcebcfca61 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 15 Dec 2022 11:07:59 +0100 Subject: [PATCH 02/21] Introduce local variable --- .../src/Framework/Actions/PublicationPageCompiler.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Actions/PublicationPageCompiler.php b/packages/framework/src/Framework/Actions/PublicationPageCompiler.php index 78a5468a24e..195f097395b 100644 --- a/packages/framework/src/Framework/Actions/PublicationPageCompiler.php +++ b/packages/framework/src/Framework/Actions/PublicationPageCompiler.php @@ -46,8 +46,10 @@ public function compilePublicationPage(): string } // Using the Blade facade we can render any file without having to register the directory with the view finder. + $viewPath = Hyde::path("{$this->page->type->getDirectory()}/$template.blade.php"); + return Blade::render( - file_get_contents(Hyde::path("{$this->page->type->getDirectory()}/$template.blade.php")), $data + file_get_contents($viewPath), $data ); } From 194023a994e8bba75aec4b523d64a30d07101c77 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 15 Dec 2022 11:08:15 +0100 Subject: [PATCH 03/21] Check if the file exists before attempting to compile --- .../src/Framework/Actions/PublicationPageCompiler.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/framework/src/Framework/Actions/PublicationPageCompiler.php b/packages/framework/src/Framework/Actions/PublicationPageCompiler.php index 195f097395b..207b7662b67 100644 --- a/packages/framework/src/Framework/Actions/PublicationPageCompiler.php +++ b/packages/framework/src/Framework/Actions/PublicationPageCompiler.php @@ -47,6 +47,9 @@ public function compilePublicationPage(): string // Using the Blade facade we can render any file without having to register the directory with the view finder. $viewPath = Hyde::path("{$this->page->type->getDirectory()}/$template.blade.php"); + if (! file_exists($viewPath)) { + throw new InvalidArgumentException("View [$viewPath] not found."); + } return Blade::render( file_get_contents($viewPath), $data From 19a3a65bd0cba4b80b15d9e3a6775dcfe5da0760 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 15 Dec 2022 11:09:18 +0100 Subject: [PATCH 04/21] Convert string interpolation to 'sprintf()' calls --- .../src/Framework/Actions/PublicationPageCompiler.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Framework/Actions/PublicationPageCompiler.php b/packages/framework/src/Framework/Actions/PublicationPageCompiler.php index 207b7662b67..00e86172736 100644 --- a/packages/framework/src/Framework/Actions/PublicationPageCompiler.php +++ b/packages/framework/src/Framework/Actions/PublicationPageCompiler.php @@ -48,7 +48,7 @@ public function compilePublicationPage(): string // Using the Blade facade we can render any file without having to register the directory with the view finder. $viewPath = Hyde::path("{$this->page->type->getDirectory()}/$template.blade.php"); if (! file_exists($viewPath)) { - throw new InvalidArgumentException("View [$viewPath] not found."); + throw new InvalidArgumentException(sprintf('View [%s] not found.', $viewPath)); } return Blade::render( @@ -70,7 +70,7 @@ public function compilePublicationListPage(): string // Using the Blade facade we can render any file without having to register the directory with the view finder. $viewPath = Hyde::path("{$this->page->type->getDirectory()}/$template").'.blade.php'; if (! file_exists($viewPath)) { - throw new InvalidArgumentException("View [$viewPath] not found."); + throw new InvalidArgumentException(sprintf('View [%s] not found.', $viewPath)); } return Blade::render( From ad22000e06ff6377defbe7a3d0d260ea0bf72d64 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 15 Dec 2022 11:10:07 +0100 Subject: [PATCH 05/21] Display the relative path in the exception message --- .../src/Framework/Actions/PublicationPageCompiler.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/framework/src/Framework/Actions/PublicationPageCompiler.php b/packages/framework/src/Framework/Actions/PublicationPageCompiler.php index 00e86172736..3d691cbee23 100644 --- a/packages/framework/src/Framework/Actions/PublicationPageCompiler.php +++ b/packages/framework/src/Framework/Actions/PublicationPageCompiler.php @@ -48,7 +48,7 @@ public function compilePublicationPage(): string // Using the Blade facade we can render any file without having to register the directory with the view finder. $viewPath = Hyde::path("{$this->page->type->getDirectory()}/$template.blade.php"); if (! file_exists($viewPath)) { - throw new InvalidArgumentException(sprintf('View [%s] not found.', $viewPath)); + throw new InvalidArgumentException(sprintf('View [%s] not found.', Hyde::pathToRelative($viewPath))); } return Blade::render( @@ -70,7 +70,7 @@ public function compilePublicationListPage(): string // Using the Blade facade we can render any file without having to register the directory with the view finder. $viewPath = Hyde::path("{$this->page->type->getDirectory()}/$template").'.blade.php'; if (! file_exists($viewPath)) { - throw new InvalidArgumentException(sprintf('View [%s] not found.', $viewPath)); + throw new InvalidArgumentException(sprintf('View [%s] not found.', Hyde::pathToRelative($viewPath))); } return Blade::render( From 842127b5a09d4b7701e4abf033f229023649e8f2 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 15 Dec 2022 11:11:35 +0100 Subject: [PATCH 06/21] Add tests for missing views --- .../Actions/PublicationPageCompilerTest.php | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/packages/framework/tests/Feature/Actions/PublicationPageCompilerTest.php b/packages/framework/tests/Feature/Actions/PublicationPageCompilerTest.php index 1996d193668..7012ff85cf3 100644 --- a/packages/framework/tests/Feature/Actions/PublicationPageCompilerTest.php +++ b/packages/framework/tests/Feature/Actions/PublicationPageCompilerTest.php @@ -9,6 +9,7 @@ use Hyde\Hyde; use Hyde\Pages\PublicationPage; use Hyde\Testing\TestCase; +use InvalidArgumentException; /** * @covers \Hyde\Framework\Actions\PublicationPageCompiler @@ -39,4 +40,26 @@ public function test_can_compile_publication_list_pages() $this->assertEquals('List: My Publication', $string); } + + public function test_with_missing_detail_blade_view() + { + $this->directory('test-publication'); + $this->setupTestPublication(); + + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('View [test-publication/test-publication_detail.blade.php] not found.'); + + PublicationPageCompiler::call(new PublicationPage('my-publication', type: PublicationType::get('test-publication'))); + } + + public function test_with_missing_list_blade_view() + { + $this->directory('test-publication'); + $this->setupTestPublication(); + + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('View [test-publication/test-publication_list.blade.php] not found.'); + + PublicationPageCompiler::call(PublicationType::get('test-publication')->getListPage()); + } } From 7670946aff95c78aad69c78e577bed5bac82ddfc Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 15 Dec 2022 11:13:47 +0100 Subject: [PATCH 07/21] Extract method for repeated code --- .../Actions/PublicationPageCompiler.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/framework/src/Framework/Actions/PublicationPageCompiler.php b/packages/framework/src/Framework/Actions/PublicationPageCompiler.php index 3d691cbee23..7604dcbc756 100644 --- a/packages/framework/src/Framework/Actions/PublicationPageCompiler.php +++ b/packages/framework/src/Framework/Actions/PublicationPageCompiler.php @@ -47,13 +47,7 @@ public function compilePublicationPage(): string // Using the Blade facade we can render any file without having to register the directory with the view finder. $viewPath = Hyde::path("{$this->page->type->getDirectory()}/$template.blade.php"); - if (! file_exists($viewPath)) { - throw new InvalidArgumentException(sprintf('View [%s] not found.', Hyde::pathToRelative($viewPath))); - } - - return Blade::render( - file_get_contents($viewPath), $data - ); + return $this->compile($viewPath, $data); } public function compilePublicationListPage(): string @@ -69,12 +63,18 @@ public function compilePublicationListPage(): string // Using the Blade facade we can render any file without having to register the directory with the view finder. $viewPath = Hyde::path("{$this->page->type->getDirectory()}/$template").'.blade.php'; - if (! file_exists($viewPath)) { + return $this->compile($viewPath, $data); + } + + protected function compile(string $viewPath, array $data): string + { + if (!file_exists($viewPath)) { throw new InvalidArgumentException(sprintf('View [%s] not found.', Hyde::pathToRelative($viewPath))); } return Blade::render( - file_get_contents($viewPath), $data + file_get_contents($viewPath), + $data ); } } From bd2d6f9e6bd7e59120aa8a2104f27204a36878eb Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 15 Dec 2022 11:13:59 +0100 Subject: [PATCH 08/21] Inline local variables --- .../src/Framework/Actions/PublicationPageCompiler.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/framework/src/Framework/Actions/PublicationPageCompiler.php b/packages/framework/src/Framework/Actions/PublicationPageCompiler.php index 7604dcbc756..6f8ade2d92a 100644 --- a/packages/framework/src/Framework/Actions/PublicationPageCompiler.php +++ b/packages/framework/src/Framework/Actions/PublicationPageCompiler.php @@ -46,8 +46,7 @@ public function compilePublicationPage(): string } // Using the Blade facade we can render any file without having to register the directory with the view finder. - $viewPath = Hyde::path("{$this->page->type->getDirectory()}/$template.blade.php"); - return $this->compile($viewPath, $data); + return $this->compile(Hyde::path("{$this->page->type->getDirectory()}/$template.blade.php"), $data); } public function compilePublicationListPage(): string @@ -62,8 +61,7 @@ public function compilePublicationListPage(): string } // Using the Blade facade we can render any file without having to register the directory with the view finder. - $viewPath = Hyde::path("{$this->page->type->getDirectory()}/$template").'.blade.php'; - return $this->compile($viewPath, $data); + return $this->compile(Hyde::path("{$this->page->type->getDirectory()}/$template").'.blade.php', $data); } protected function compile(string $viewPath, array $data): string From cd94ce0e9b3dc827152f67d609597dd27da7cf86 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Thu, 15 Dec 2022 10:14:59 +0000 Subject: [PATCH 09/21] Apply fixes from StyleCI --- .../framework/src/Framework/Actions/PublicationPageCompiler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Actions/PublicationPageCompiler.php b/packages/framework/src/Framework/Actions/PublicationPageCompiler.php index 6f8ade2d92a..15aaf263f67 100644 --- a/packages/framework/src/Framework/Actions/PublicationPageCompiler.php +++ b/packages/framework/src/Framework/Actions/PublicationPageCompiler.php @@ -66,7 +66,7 @@ public function compilePublicationListPage(): string protected function compile(string $viewPath, array $data): string { - if (!file_exists($viewPath)) { + if (! file_exists($viewPath)) { throw new InvalidArgumentException(sprintf('View [%s] not found.', Hyde::pathToRelative($viewPath))); } From 1af30f6466ff7e4a3b852f1aebe56b1b91f70bfe Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 15 Dec 2022 11:16:46 +0100 Subject: [PATCH 10/21] Create AnonymousViewCompiler.php --- .../src/Framework/Actions/AnonymousViewCompiler.php | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 packages/framework/src/Framework/Actions/AnonymousViewCompiler.php diff --git a/packages/framework/src/Framework/Actions/AnonymousViewCompiler.php b/packages/framework/src/Framework/Actions/AnonymousViewCompiler.php new file mode 100644 index 00000000000..e1bdd62f3d9 --- /dev/null +++ b/packages/framework/src/Framework/Actions/AnonymousViewCompiler.php @@ -0,0 +1,10 @@ + Date: Thu, 15 Dec 2022 11:17:02 +0100 Subject: [PATCH 11/21] Create AnonymousViewCompilerTest.php --- .../Actions/AnonymousViewCompilerTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 packages/framework/tests/Feature/Actions/AnonymousViewCompilerTest.php diff --git a/packages/framework/tests/Feature/Actions/AnonymousViewCompilerTest.php b/packages/framework/tests/Feature/Actions/AnonymousViewCompilerTest.php new file mode 100644 index 00000000000..274ede14b59 --- /dev/null +++ b/packages/framework/tests/Feature/Actions/AnonymousViewCompilerTest.php @@ -0,0 +1,16 @@ + Date: Thu, 15 Dec 2022 11:17:12 +0100 Subject: [PATCH 12/21] Extends InvokableAction --- .../framework/src/Framework/Actions/AnonymousViewCompiler.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Actions/AnonymousViewCompiler.php b/packages/framework/src/Framework/Actions/AnonymousViewCompiler.php index e1bdd62f3d9..77444bd449c 100644 --- a/packages/framework/src/Framework/Actions/AnonymousViewCompiler.php +++ b/packages/framework/src/Framework/Actions/AnonymousViewCompiler.php @@ -4,7 +4,9 @@ namespace Hyde\Framework\Actions; -class AnonymousViewCompiler +use Hyde\Framework\Concerns\InvokableAction; + +class AnonymousViewCompiler extends InvokableAction { // } From 79cf0c62eb4b3960843dd8ef8cf53ff25ba6001a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 15 Dec 2022 11:19:55 +0100 Subject: [PATCH 13/21] Add class documentation --- .../src/Framework/Actions/AnonymousViewCompiler.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/framework/src/Framework/Actions/AnonymousViewCompiler.php b/packages/framework/src/Framework/Actions/AnonymousViewCompiler.php index 77444bd449c..653a8bcb097 100644 --- a/packages/framework/src/Framework/Actions/AnonymousViewCompiler.php +++ b/packages/framework/src/Framework/Actions/AnonymousViewCompiler.php @@ -6,6 +6,11 @@ use Hyde\Framework\Concerns\InvokableAction; + +/** + * Compile any Blade file using the Blade facade as it allows us to render + * it without having to register the directory with the view finder. + */ class AnonymousViewCompiler extends InvokableAction { // From d524d77d007ba0c0ec620955799c22b18802587a Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 15 Dec 2022 11:20:21 +0100 Subject: [PATCH 14/21] Add class properties and constructor --- .../src/Framework/Actions/AnonymousViewCompiler.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Actions/AnonymousViewCompiler.php b/packages/framework/src/Framework/Actions/AnonymousViewCompiler.php index 653a8bcb097..bd9c6ce79b9 100644 --- a/packages/framework/src/Framework/Actions/AnonymousViewCompiler.php +++ b/packages/framework/src/Framework/Actions/AnonymousViewCompiler.php @@ -13,5 +13,12 @@ */ class AnonymousViewCompiler extends InvokableAction { - // + protected string $viewPath; + protected array $data; + + public function __construct(string $viewPath, array $data = []) + { + $this->viewPath = $viewPath; + $this->data = $data; + } } From e423afa93285848cb5123451f473a28e01dbc718 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 15 Dec 2022 11:21:41 +0100 Subject: [PATCH 15/21] Implement the __invoke method --- .../Actions/AnonymousViewCompiler.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/framework/src/Framework/Actions/AnonymousViewCompiler.php b/packages/framework/src/Framework/Actions/AnonymousViewCompiler.php index bd9c6ce79b9..d7528abcd8e 100644 --- a/packages/framework/src/Framework/Actions/AnonymousViewCompiler.php +++ b/packages/framework/src/Framework/Actions/AnonymousViewCompiler.php @@ -5,6 +5,13 @@ namespace Hyde\Framework\Actions; use Hyde\Framework\Concerns\InvokableAction; +use Hyde\Hyde; +use Illuminate\Support\Facades\Blade; +use InvalidArgumentException; + +use function file_exists; +use function file_get_contents; +use function sprintf; /** @@ -21,4 +28,16 @@ public function __construct(string $viewPath, array $data = []) $this->viewPath = $viewPath; $this->data = $data; } + + public function __invoke(): string + { + if (! file_exists(Hyde::path($this->viewPath))) { + throw new InvalidArgumentException(sprintf('View [%s] not found.', $this->viewPath)); + } + + return Blade::render( + file_get_contents(Hyde::path($this->viewPath)), + $this->data + ); + } } From 4d6abaff2d1a792388bbdb3f63e4d6541c7be8b8 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 15 Dec 2022 11:24:40 +0100 Subject: [PATCH 16/21] Implement the test --- .../Actions/AnonymousViewCompilerTest.php | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/packages/framework/tests/Feature/Actions/AnonymousViewCompilerTest.php b/packages/framework/tests/Feature/Actions/AnonymousViewCompilerTest.php index 274ede14b59..3ddd79e140b 100644 --- a/packages/framework/tests/Feature/Actions/AnonymousViewCompilerTest.php +++ b/packages/framework/tests/Feature/Actions/AnonymousViewCompilerTest.php @@ -5,12 +5,37 @@ namespace Hyde\Framework\Testing\Feature\Actions; use Hyde\Framework\Actions\AnonymousViewCompiler; +use Hyde\Hyde; use Hyde\Testing\TestCase; +use InvalidArgumentException; + +use function file_put_contents; + /** * @covers \Hyde\Framework\Actions\AnonymousViewCompiler */ class AnonymousViewCompilerTest extends TestCase { - // + public function testCanCompileBladeFile() + { + $this->file('foo.blade.php', "{{ 'Hello World' }}"); + + $this->assertSame('Hello World', AnonymousViewCompiler::call('foo.blade.php')); + } + + public function testCanCompileBladeFileWithData() + { + $this->file('foo.blade.php', '{{ $foo }}'); + + $this->assertSame('bar', AnonymousViewCompiler::call('foo.blade.php', ['foo' => 'bar'])); + } + + public function testWithMissingView() + { + $this->expectException(InvalidArgumentException::class); + $this->expectExceptionMessage('View [foo.blade.php] not found.'); + + AnonymousViewCompiler::call('foo.blade.php'); + } } From 2d2bcdc6b459d68113bf6994d5fca93f09a43532 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 15 Dec 2022 11:26:30 +0100 Subject: [PATCH 17/21] Throw FileNotFoundException on fail instead --- .../src/Framework/Actions/AnonymousViewCompiler.php | 3 ++- .../tests/Feature/Actions/AnonymousViewCompilerTest.php | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/framework/src/Framework/Actions/AnonymousViewCompiler.php b/packages/framework/src/Framework/Actions/AnonymousViewCompiler.php index d7528abcd8e..71f4d7c5cd7 100644 --- a/packages/framework/src/Framework/Actions/AnonymousViewCompiler.php +++ b/packages/framework/src/Framework/Actions/AnonymousViewCompiler.php @@ -5,6 +5,7 @@ namespace Hyde\Framework\Actions; use Hyde\Framework\Concerns\InvokableAction; +use Hyde\Framework\Exceptions\FileNotFoundException; use Hyde\Hyde; use Illuminate\Support\Facades\Blade; use InvalidArgumentException; @@ -32,7 +33,7 @@ public function __construct(string $viewPath, array $data = []) public function __invoke(): string { if (! file_exists(Hyde::path($this->viewPath))) { - throw new InvalidArgumentException(sprintf('View [%s] not found.', $this->viewPath)); + throw new FileNotFoundException($this->viewPath); } return Blade::render( diff --git a/packages/framework/tests/Feature/Actions/AnonymousViewCompilerTest.php b/packages/framework/tests/Feature/Actions/AnonymousViewCompilerTest.php index 3ddd79e140b..76984970d8e 100644 --- a/packages/framework/tests/Feature/Actions/AnonymousViewCompilerTest.php +++ b/packages/framework/tests/Feature/Actions/AnonymousViewCompilerTest.php @@ -5,6 +5,7 @@ namespace Hyde\Framework\Testing\Feature\Actions; use Hyde\Framework\Actions\AnonymousViewCompiler; +use Hyde\Framework\Exceptions\FileNotFoundException; use Hyde\Hyde; use Hyde\Testing\TestCase; @@ -33,8 +34,8 @@ public function testCanCompileBladeFileWithData() public function testWithMissingView() { - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('View [foo.blade.php] not found.'); + $this->expectException(FileNotFoundException::class); + $this->expectExceptionMessage('File foo.blade.php not found.'); AnonymousViewCompiler::call('foo.blade.php'); } From 87584ca8b8647829126c00acf79a424443145d9d Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 15 Dec 2022 11:35:44 +0100 Subject: [PATCH 18/21] Refactor to use the AnonymousViewCompiler --- .../Framework/Actions/PublicationPageCompiler.php | 13 +++---------- .../Feature/Actions/PublicationPageCompilerTest.php | 10 +++++----- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/packages/framework/src/Framework/Actions/PublicationPageCompiler.php b/packages/framework/src/Framework/Actions/PublicationPageCompiler.php index 15aaf263f67..f8b6ceca729 100644 --- a/packages/framework/src/Framework/Actions/PublicationPageCompiler.php +++ b/packages/framework/src/Framework/Actions/PublicationPageCompiler.php @@ -46,7 +46,7 @@ public function compilePublicationPage(): string } // Using the Blade facade we can render any file without having to register the directory with the view finder. - return $this->compile(Hyde::path("{$this->page->type->getDirectory()}/$template.blade.php"), $data); + return $this->compile("{$this->page->type->getDirectory()}/$template.blade.php", $data); } public function compilePublicationListPage(): string @@ -61,18 +61,11 @@ public function compilePublicationListPage(): string } // Using the Blade facade we can render any file without having to register the directory with the view finder. - return $this->compile(Hyde::path("{$this->page->type->getDirectory()}/$template").'.blade.php', $data); + return $this->compile("{$this->page->type->getDirectory()}/$template" .'.blade.php', $data); } protected function compile(string $viewPath, array $data): string { - if (! file_exists($viewPath)) { - throw new InvalidArgumentException(sprintf('View [%s] not found.', Hyde::pathToRelative($viewPath))); - } - - return Blade::render( - file_get_contents($viewPath), - $data - ); + return AnonymousViewCompiler::call($viewPath, $data); } } diff --git a/packages/framework/tests/Feature/Actions/PublicationPageCompilerTest.php b/packages/framework/tests/Feature/Actions/PublicationPageCompilerTest.php index 7012ff85cf3..099e34920bf 100644 --- a/packages/framework/tests/Feature/Actions/PublicationPageCompilerTest.php +++ b/packages/framework/tests/Feature/Actions/PublicationPageCompilerTest.php @@ -9,7 +9,7 @@ use Hyde\Hyde; use Hyde\Pages\PublicationPage; use Hyde\Testing\TestCase; -use InvalidArgumentException; +use Hyde\Framework\Exceptions\FileNotFoundException; /** * @covers \Hyde\Framework\Actions\PublicationPageCompiler @@ -46,8 +46,8 @@ public function test_with_missing_detail_blade_view() $this->directory('test-publication'); $this->setupTestPublication(); - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('View [test-publication/test-publication_detail.blade.php] not found.'); + $this->expectException(FileNotFoundException::class); + $this->expectExceptionMessage('File test-publication/test-publication_detail.blade.php not found.'); PublicationPageCompiler::call(new PublicationPage('my-publication', type: PublicationType::get('test-publication'))); } @@ -57,8 +57,8 @@ public function test_with_missing_list_blade_view() $this->directory('test-publication'); $this->setupTestPublication(); - $this->expectException(InvalidArgumentException::class); - $this->expectExceptionMessage('View [test-publication/test-publication_list.blade.php] not found.'); + $this->expectException(FileNotFoundException::class); + $this->expectExceptionMessage('File test-publication/test-publication_list.blade.php not found.'); PublicationPageCompiler::call(PublicationType::get('test-publication')->getListPage()); } From 2dc269fa5d96f725261b9915497a679353cb59e1 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 15 Dec 2022 11:35:59 +0100 Subject: [PATCH 19/21] Inline simplified method --- .../src/Framework/Actions/PublicationPageCompiler.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/packages/framework/src/Framework/Actions/PublicationPageCompiler.php b/packages/framework/src/Framework/Actions/PublicationPageCompiler.php index f8b6ceca729..8fccd1c6daa 100644 --- a/packages/framework/src/Framework/Actions/PublicationPageCompiler.php +++ b/packages/framework/src/Framework/Actions/PublicationPageCompiler.php @@ -46,7 +46,7 @@ public function compilePublicationPage(): string } // Using the Blade facade we can render any file without having to register the directory with the view finder. - return $this->compile("{$this->page->type->getDirectory()}/$template.blade.php", $data); + return AnonymousViewCompiler::call("{$this->page->type->getDirectory()}/$template.blade.php", $data); } public function compilePublicationListPage(): string @@ -61,11 +61,6 @@ public function compilePublicationListPage(): string } // Using the Blade facade we can render any file without having to register the directory with the view finder. - return $this->compile("{$this->page->type->getDirectory()}/$template" .'.blade.php', $data); - } - - protected function compile(string $viewPath, array $data): string - { - return AnonymousViewCompiler::call($viewPath, $data); + return AnonymousViewCompiler::call("{$this->page->type->getDirectory()}/$template" . '.blade.php', $data); } } From b1118cfcc4eb6057d98a862e47134e711642d2db Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Thu, 15 Dec 2022 11:36:08 +0100 Subject: [PATCH 20/21] Convert concatenation to a scalar value --- .../framework/src/Framework/Actions/PublicationPageCompiler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/framework/src/Framework/Actions/PublicationPageCompiler.php b/packages/framework/src/Framework/Actions/PublicationPageCompiler.php index 8fccd1c6daa..51c9ddef2a0 100644 --- a/packages/framework/src/Framework/Actions/PublicationPageCompiler.php +++ b/packages/framework/src/Framework/Actions/PublicationPageCompiler.php @@ -61,6 +61,6 @@ public function compilePublicationListPage(): string } // Using the Blade facade we can render any file without having to register the directory with the view finder. - return AnonymousViewCompiler::call("{$this->page->type->getDirectory()}/$template" . '.blade.php', $data); + return AnonymousViewCompiler::call("{$this->page->type->getDirectory()}/$template.blade.php", $data); } } From 423e09e8f132b0cdac46f087670f750864b3d422 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Thu, 15 Dec 2022 10:36:44 +0000 Subject: [PATCH 21/21] Apply fixes from StyleCI --- .../src/Framework/Actions/PublicationPageCompiler.php | 4 ---- .../tests/Feature/Actions/PublicationPageCompilerTest.php | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/framework/src/Framework/Actions/PublicationPageCompiler.php b/packages/framework/src/Framework/Actions/PublicationPageCompiler.php index 51c9ddef2a0..408ef6b6d22 100644 --- a/packages/framework/src/Framework/Actions/PublicationPageCompiler.php +++ b/packages/framework/src/Framework/Actions/PublicationPageCompiler.php @@ -4,15 +4,11 @@ namespace Hyde\Framework\Actions; -use function file_exists; -use function file_get_contents; use Hyde\Framework\Concerns\InvokableAction; use Hyde\Framework\Features\Publications\Models\PublicationListPage; use Hyde\Framework\Features\Publications\PublicationService; -use Hyde\Hyde; use Hyde\Pages\PublicationPage; use Illuminate\Support\Facades\Blade; -use InvalidArgumentException; use function view; /** diff --git a/packages/framework/tests/Feature/Actions/PublicationPageCompilerTest.php b/packages/framework/tests/Feature/Actions/PublicationPageCompilerTest.php index 099e34920bf..a873becfb74 100644 --- a/packages/framework/tests/Feature/Actions/PublicationPageCompilerTest.php +++ b/packages/framework/tests/Feature/Actions/PublicationPageCompilerTest.php @@ -5,11 +5,11 @@ namespace Hyde\Framework\Testing\Feature\Actions; use Hyde\Framework\Actions\PublicationPageCompiler; +use Hyde\Framework\Exceptions\FileNotFoundException; use Hyde\Framework\Features\Publications\Models\PublicationType; use Hyde\Hyde; use Hyde\Pages\PublicationPage; use Hyde\Testing\TestCase; -use Hyde\Framework\Exceptions\FileNotFoundException; /** * @covers \Hyde\Framework\Actions\PublicationPageCompiler