componenta/file-hasher
Composer 安装命令:
composer require componenta/file-hasher
包简介
File hashing contract and default implementation
README 文档
README
File hashing contract and default implementation.
Use this package when a service needs to hash a file by filename and receive file-specific exceptions for invalid paths.
Installation
composer require componenta/file-hasher
Usage
use Componenta\Stdlib\FileHasher; $hasher = new FileHasher('sha256'); $hash = $hasher->hashFile(__DIR__ . '/document.pdf'); $sha1 = $hasher->withAlgorithm('sha1');
FileHasher exposes the selected algorithm as read-only public state:
$hasher->algorithm; // sha256
withAlgorithm() returns a new immutable instance.
Contract
interface FileHasherInterface { public function hashFile(string $filename): string; }
Exceptions
All package exceptions are named with a File* prefix and implement FileHasherExceptionInterface.
| Exception | When it is thrown |
|---|---|
FileNotFoundException |
The path does not exist. |
FileNotReadableException |
The path exists but is not a readable regular file. |
FileHashFailedException |
PHP failed to compute the file hash. |
Related Packages
| Package | Why it matters here |
|---|---|
componenta/hasher |
Hashes strings and PSR-7 streams. |
componenta/password |
Hashes passwords with PHP's dedicated password API. |
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-06-17