From 2f28d87ebdb6f86abede4325158a6f5a29d24139 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Fri, 26 Jul 2024 17:09:33 +0200 Subject: [PATCH] Update deprecated method usages with new helpers --- .../resources/views/layouts/head.blade.php | 2 +- packages/framework/src/Facades/Asset.php | 5 +++-- .../Actions/PreBuildTasks/CleanSiteDirectory.php | 3 ++- .../PreBuildTasks/TransferMediaAssets.php | 7 +++---- .../Features/Blogging/Models/FeaturedImage.php | 3 ++- .../src/Framework/Services/ValidationService.php | 5 +++-- .../tests/Feature/Foundation/FilesystemTest.php | 16 ++++++++-------- .../framework/tests/Feature/HydeKernelTest.php | 11 ++++++----- 8 files changed, 28 insertions(+), 24 deletions(-) diff --git a/packages/framework/resources/views/layouts/head.blade.php b/packages/framework/resources/views/layouts/head.blade.php index 32ed4390d8b..111aced665b 100644 --- a/packages/framework/resources/views/layouts/head.blade.php +++ b/packages/framework/resources/views/layouts/head.blade.php @@ -2,7 +2,7 @@ {{ $page->title() }} -@if (file_exists(Hyde::mediaPath('favicon.ico'))) +@if (file_exists(MediaFile::sourcePath('favicon.ico'))) @endif diff --git a/packages/framework/src/Facades/Asset.php b/packages/framework/src/Facades/Asset.php index 9691a43c211..45e16a0a881 100644 --- a/packages/framework/src/Facades/Asset.php +++ b/packages/framework/src/Facades/Asset.php @@ -5,6 +5,7 @@ namespace Hyde\Facades; use Hyde\Hyde; +use Hyde\Support\Filesystem\MediaFile; use function md5_file; use function file_exists; @@ -24,13 +25,13 @@ public static function mediaLink(string $file): string public static function hasMediaFile(string $file): bool { - return file_exists(Hyde::mediaPath($file)); + return file_exists(MediaFile::sourcePath($file)); } protected static function getCacheBustKey(string $file): string { return Config::getBool('hyde.enable_cache_busting', true) - ? '?v='.md5_file(Hyde::mediaPath("$file")) + ? '?v='.md5_file(MediaFile::sourcePath("$file")) : ''; } } diff --git a/packages/framework/src/Framework/Actions/PreBuildTasks/CleanSiteDirectory.php b/packages/framework/src/Framework/Actions/PreBuildTasks/CleanSiteDirectory.php index 849f077b7cb..ba64f24ee76 100644 --- a/packages/framework/src/Framework/Actions/PreBuildTasks/CleanSiteDirectory.php +++ b/packages/framework/src/Framework/Actions/PreBuildTasks/CleanSiteDirectory.php @@ -7,6 +7,7 @@ use Hyde\Hyde; use Hyde\Facades\Config; use Hyde\Facades\Filesystem; +use Hyde\Support\Filesystem\MediaFile; use Hyde\Framework\Features\BuildTasks\PreBuildTask; use function basename; @@ -22,7 +23,7 @@ public function handle(): void { if ($this->isItSafeToCleanOutputDirectory()) { Filesystem::unlink(glob(Hyde::sitePath('*.{html,json}'), GLOB_BRACE)); - Filesystem::cleanDirectory(Hyde::siteMediaPath()); + Filesystem::cleanDirectory(MediaFile::outputPath()); } } diff --git a/packages/framework/src/Framework/Actions/PreBuildTasks/TransferMediaAssets.php b/packages/framework/src/Framework/Actions/PreBuildTasks/TransferMediaAssets.php index fdec03a75ff..3acb112ea9d 100644 --- a/packages/framework/src/Framework/Actions/PreBuildTasks/TransferMediaAssets.php +++ b/packages/framework/src/Framework/Actions/PreBuildTasks/TransferMediaAssets.php @@ -4,7 +4,6 @@ namespace Hyde\Framework\Actions\PreBuildTasks; -use Hyde\Hyde; use Hyde\Support\Filesystem\MediaFile; use Hyde\Framework\Features\BuildTasks\PreBuildTask; use Hyde\Framework\Concerns\InteractsWithDirectories; @@ -17,14 +16,14 @@ class TransferMediaAssets extends PreBuildTask public function handle(): void { - $this->needsDirectory(Hyde::siteMediaPath()); + $this->needsDirectory(MediaFile::outputPath()); $this->newLine(); $this->withProgressBar(MediaFile::files(), function (string $identifier): void { - $sitePath = Hyde::siteMediaPath($identifier); + $sitePath = MediaFile::outputPath($identifier); $this->needsParentDirectory($sitePath); - copy(Hyde::mediaPath($identifier), $sitePath); + copy(MediaFile::sourcePath($identifier), $sitePath); }); $this->newLine(); diff --git a/packages/framework/src/Framework/Features/Blogging/Models/FeaturedImage.php b/packages/framework/src/Framework/Features/Blogging/Models/FeaturedImage.php index 0f42f961c87..5c4acef1996 100644 --- a/packages/framework/src/Framework/Features/Blogging/Models/FeaturedImage.php +++ b/packages/framework/src/Framework/Features/Blogging/Models/FeaturedImage.php @@ -11,6 +11,7 @@ use Hyde\Support\BuildWarnings; use Illuminate\Support\Facades\Http; use Hyde\Foundation\Kernel\Hyperlinks; +use Hyde\Support\Filesystem\MediaFile; use Hyde\Framework\Exceptions\FileNotFoundException; use Hyde\Markdown\Contracts\FrontMatter\SubSchemas\FeaturedImageSchema; @@ -213,7 +214,7 @@ protected function has(string $property): bool protected function getContentLengthForLocalImage(): int { - $storagePath = Hyde::mediaPath($this->source); + $storagePath = MediaFile::sourcePath($this->source); if (! file_exists($storagePath)) { throw new FileNotFoundException(customMessage: sprintf('Featured image [%s] not found.', Hyde::pathToRelative($storagePath))); diff --git a/packages/framework/src/Framework/Services/ValidationService.php b/packages/framework/src/Framework/Services/ValidationService.php index 88deee3496b..052486d4041 100644 --- a/packages/framework/src/Framework/Services/ValidationService.php +++ b/packages/framework/src/Framework/Services/ValidationService.php @@ -11,6 +11,7 @@ use Hyde\Pages\MarkdownPage; use Hyde\Pages\DocumentationPage; use Hyde\Enums\Feature; +use Hyde\Support\Filesystem\MediaFile; use Hyde\Support\Models\ValidationResult as Result; use function count; @@ -102,12 +103,12 @@ public function check_documentation_site_has_an_index_page(Result $result): Resu public function check_site_has_an_app_css_stylesheet(Result $result): Result { - if (file_exists(Hyde::siteMediaPath('/app.css')) || file_exists(Hyde::mediaPath('app.css'))) { + if (file_exists(MediaFile::outputPath('/app.css')) || file_exists(MediaFile::sourcePath('app.css'))) { return $result->pass('Your site has an app.css stylesheet'); } return $result->fail(sprintf('Could not find an app.css file in the %s or %s directory!', - Hyde::pathToRelative(Hyde::siteMediaPath()), Hyde::getMediaDirectory() + Hyde::pathToRelative(MediaFile::outputPath()), Hyde::getMediaDirectory() ))->withTip('You may need to run `npm run dev`.`'); } diff --git a/packages/framework/tests/Feature/Foundation/FilesystemTest.php b/packages/framework/tests/Feature/Foundation/FilesystemTest.php index 0be01b45c22..86bc2c76479 100644 --- a/packages/framework/tests/Feature/Foundation/FilesystemTest.php +++ b/packages/framework/tests/Feature/Foundation/FilesystemTest.php @@ -263,20 +263,20 @@ public function testHelperForDocumentationPages() public function testHelperForMediaPath() { - $this->assertSame(Hyde::path('_media'), Hyde::mediaPath()); - $this->assertSame(MediaFile::sourcePath(), Hyde::mediaPath()); + $this->assertSame(Hyde::path('_media'), MediaFile::sourcePath()); + $this->assertSame(MediaFile::sourcePath(), MediaFile::sourcePath()); - $this->assertSame(Hyde::path('_media/foo.png'), Hyde::mediaPath('foo.png')); - $this->assertSame(MediaFile::sourcePath('foo.png'), Hyde::mediaPath('foo.png')); + $this->assertSame(Hyde::path('_media/foo.png'), MediaFile::sourcePath('foo.png')); + $this->assertSame(MediaFile::sourcePath('foo.png'), MediaFile::sourcePath('foo.png')); } public function testHelperForMediaOutputPath() { - $this->assertSame(Hyde::path('_site/media'), Hyde::siteMediaPath()); - $this->assertSame(MediaFile::outputPath(), Hyde::siteMediaPath()); + $this->assertSame(Hyde::path('_site/media'), MediaFile::outputPath()); + $this->assertSame(MediaFile::outputPath(), MediaFile::outputPath()); - $this->assertSame(Hyde::path('_site/media/foo.png'), Hyde::siteMediaPath('foo.png')); - $this->assertSame(MediaFile::outputPath('foo.png'), Hyde::siteMediaPath('foo.png')); + $this->assertSame(Hyde::path('_site/media/foo.png'), MediaFile::outputPath('foo.png')); + $this->assertSame(MediaFile::outputPath('foo.png'), MediaFile::outputPath('foo.png')); } public function testHelperForSiteOutputPath() diff --git a/packages/framework/tests/Feature/HydeKernelTest.php b/packages/framework/tests/Feature/HydeKernelTest.php index bd22206502d..9ff8799dd06 100644 --- a/packages/framework/tests/Feature/HydeKernelTest.php +++ b/packages/framework/tests/Feature/HydeKernelTest.php @@ -13,6 +13,7 @@ use Hyde\Foundation\HydeKernel; use Hyde\Enums\Feature; use Hyde\Foundation\Kernel\Filesystem; +use Hyde\Support\Filesystem\MediaFile; use Hyde\Framework\HydeServiceProvider; use Hyde\Hyde; use Hyde\Pages\BladePage; @@ -262,9 +263,9 @@ public function testFluentModelSourcePathHelpers() $this->assertSame(Hyde::path('_pages'), MarkdownPage::path()); $this->assertSame(Hyde::path('_docs'), DocumentationPage::path()); - $this->assertSame(Hyde::path('_media'), Hyde::mediaPath()); + $this->assertSame(Hyde::path('_media'), MediaFile::sourcePath()); + $this->assertSame(Hyde::path('_site/media'), MediaFile::outputPath()); $this->assertSame(Hyde::path('_site'), Hyde::sitePath()); - $this->assertSame(Hyde::path('_site/media'), Hyde::siteMediaPath()); } public function testPathToRelativeHelperReturnsRelativePathForGivenPath() @@ -395,7 +396,7 @@ public function testCanGetSiteMediaOutputDirectory() { // Todo: Move to MediaFileTest - $this->assertSame(Hyde::path('_site/media'), Hyde::siteMediaPath()); + $this->assertSame(Hyde::path('_site/media'), MediaFile::outputPath()); } public function testGetSiteMediaOutputDirectoryUsesTrimmedVersionOfMediaSourceDirectory() @@ -403,7 +404,7 @@ public function testGetSiteMediaOutputDirectoryUsesTrimmedVersionOfMediaSourceDi // Todo: Move to MediaFileTest Hyde::setMediaDirectory('_foo'); - $this->assertSame(Hyde::path('_site/foo'), Hyde::siteMediaPath()); + $this->assertSame(Hyde::path('_site/foo'), MediaFile::outputPath()); } public function testGetSiteMediaOutputDirectoryUsesConfiguredSiteOutputDirectory() @@ -413,7 +414,7 @@ public function testGetSiteMediaOutputDirectoryUsesConfiguredSiteOutputDirectory Hyde::setOutputDirectory(Hyde::path('foo')); Hyde::setMediaDirectory('bar'); - $this->assertSame(Hyde::path('foo/bar'), Hyde::siteMediaPath()); + $this->assertSame(Hyde::path('foo/bar'), MediaFile::outputPath()); } public function testMediaOutputDirectoryCanBeChangedInConfiguration()