config['expire']; $now = time(); $files = $this->findFiles($this->config['path'], function (\SplFileInfo $item) use ($lifetime, $now) { // 添加文件是否存在判断 if (!$item->isFile()) { return false; } return $now - $lifetime > $item->getMTime(); }); foreach ($files as $file) { $this->unlink($file->getPathname()); } } /** * 重构unlink方法 * * 判断文件是否存在后,删除 * * @access private * @param string $file * @return bool */ protected function unlink(string $file): bool { return is_file($file) && unlink($file); } }