内核更新

This commit is contained in:
2016-09-26 13:55:47 +08:00
parent 863f6a1cd0
commit 7608d4d0f7
17 changed files with 213 additions and 79 deletions

View File

@@ -95,27 +95,15 @@ class File extends SplFileObject
}
/**
* 获取文件的md5散列值
* @return $this
* 获取文件的哈希散列值
* @return $string
*/
public function md5()
public function hash($type = 'sha1')
{
if (!isset($this->hash['md5'])) {
$this->hash['md5'] = md5_file($this->filename);
if (!isset($this->hash[$type])) {
$this->hash[$type] = hash_file($type, $this->filename);
}
return $this->hash['md5'];
}
/**
* 获取文件的sha1散列值
* @return $this
*/
public function sha1()
{
if (!isset($this->hash['sha1'])) {
$this->hash['sha1'] = sha1_file($this->filename);
}
return $this->hash['sha1'];
return $this->hash[$type];
}
/**
@@ -356,19 +344,18 @@ class File extends SplFileObject
$savename = call_user_func_array($this->rule, [$this]);
} else {
switch ($this->rule) {
case 'md5':
$md5 = md5_file($this->filename);
$savename = substr($md5, 0, 2) . DS . substr($md5, 2);
break;
case 'sha1':
$sha1 = sha1_file($this->filename);
$savename = substr($sha1, 0, 2) . DS . substr($sha1, 2);
break;
case 'date':
$savename = date('Ymd') . DS . md5(microtime(true));
break;
default:
$savename = call_user_func($this->rule);
if (in_array($this->rule, hash_algos())) {
$hash = $this->hash($this->rule);
$savename = substr($hash, 0, 2) . DS . substr($hash, 2);
} elseif (is_callable($this->rule)) {
$savename = call_user_func($this->rule);
} else {
$savename = date('Ymd') . DS . md5(microtime(true));
}
}
}
} elseif ('' === $savename) {