Skip to content

Commit 4aa11b4

Browse files
committed
Add hash accessor
1 parent 9f920f7 commit 4aa11b4

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

packages/framework/src/Support/Filesystem/MediaFile.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ public function getMimeType(): string
128128
return 'text/plain';
129129
}
130130

131+
public function getHash(): string
132+
{
133+
return md5_file($this->getAbsolutePath());
134+
}
135+
131136
/** @internal */
132137
public static function getCacheBustKey(string $file): string
133138
{

packages/framework/tests/Unit/Support/MediaFileTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,4 +336,11 @@ public function testGetSiteMediaOutputDirectoryUsesConfiguredSiteOutputDirectory
336336
Hyde::setOutputDirectory(Hyde::path('_site'));
337337
Hyde::setMediaDirectory('_media');
338338
}
339+
340+
public function testGetHash()
341+
{
342+
$this->file('_media/foo.txt', 'Hello World!');
343+
344+
$this->assertSame(md5('Hello World!'), MediaFile::make('foo.txt')->getHash());
345+
}
339346
}

0 commit comments

Comments
 (0)