Add File::hash()

This commit is contained in:
Giuseppe Criscione 2020-12-14 09:51:09 +01:00
parent b5c522033a
commit 39faccb870

View File

@ -59,6 +59,13 @@ class File
*/
protected $size;
/**
* File hash
*
* @var string
*/
protected $hash;
/**
* Create a new File instance
*/
@ -150,6 +157,17 @@ class File
return $this->size;
}
/**
* Get file hash
*/
public function hash(): string
{
if ($this->hash !== null) {
return $this->hash;
}
return $this->hash = hash_file('sha256', $this->path);
}
public function __toString(): string
{
return $this->name;