ssitu/barnett
一个PHP压缩工具。压缩效果堪比Barnett Newman。
v0.1-beta.1
2021-07-22 13:14 UTC
Requires
- ssitu/blueprints: ^0.2
This package is auto-updated.
Last update: 2024-09-04 10:51:22 UTC
README
/!\ 测试阶段
一个PHP压缩工具。
让您的生命更加轻松。
压缩效果堪比Barnett Newman。
概述
设置存档目标、源目录,然后voilà。
-
是的,源目录将被递归爬取。
- 整洁的存档树,与源目录一致。
- 可以设置要排除的文件列表。
- 也可以仅针对某些文件扩展名。
-
执行所有必要的检查。
- 错误将被记录。
- 是的,您可以插入您选择的 Psr-3 日志记录器。
- 或者直接访问内存中的日志。
-
现有的存档不会被覆盖。
- 好吧,除非指定。
- 可以为您处理ZIP文件名。
- 根据要求添加时间戳。
-
附带结束动作。
- 可以删除成功压缩的源文件。
- 对压缩和销毁文件提供反馈。
- 哦,还会生成HTML下载链接。
以风格调用
- Barnett的方法可以串联。
- 因为它扩展了ZipArchive,您也可以调用原生方法。
- 没有私有内容,因此您也可以扩展它。
安装
composer require ssitu/barnett
FlexLogsTrait
和FlexLogsInterface
特别。
这是一个带有回退的Psr-3 "logger aware"实现。
如果没有使用其他SSITU蓝图,您只需下载这两个文件即可。
如何使用
初始化
use SSITU\Barnett\Barnett; # Barnett also has an Assistant. require_once 'path/to/autoload.php'; $Barnett = new Barnett();
日志系统
# optional: $Barnett->setLogger($somePsr3Logger); # alternatively, you can retrieve logs that way: $Barnett->getLocalLogs(); // if no logger set: returns all logs history; // else: only last entry
简单包
成功时返回zip文件的路径。
$Barnett->zipFast($sourceDirPath, $zipDirPath, $zipFilename = null, $addDate = true, $overwrite = false);
串联
示例
$zipLink = $Barnett->setZipSource('some/source/dir/path/', ['txt']) ->setZipLocation('some/zip/dir/path/') ->zip() # this won't work if no source / location specified ->shredZippedFiles(['ButNotThisOne.txt']) ->getDownloadLink('https://example.com/aliasPath/');
注意
为getDownloadLink()
设置别名路径不是必需的,但强烈推荐。
否则,您的服务器文件树可能会暴露给世界。
按需
可串联动作
$Barnett->setZipSource($sourceDirPath, $theseExtOnly = [], $omitThesePaths = []); $Barnett->setZipLocation($zipDirPath, $zipFilename = null, $addDate = true, $overwrite = false); $Barnett->zip(); $Barnett->shredZippedFiles($omitThesePaths = []), $mockMode = false; # will only list files to delete
关于$omitThesePaths
-
指定路径可以相对于
$sourceDirPath
。
例如:someFolder/someFile.ext
而不是:Source/Dir/Path/someFolder/someFile.ext
-
要排除整个子文件夹及其所有内容,只需子文件夹路径即可。
例如:['dontTouchMe/']
而不是:['dontTouchMe/','dontTouchMe/file1.ext','dontTouchMe/file2.ext']
可串联重置器
$Barnett->resetZipSource(); $Barnett->resetZipLocation(); $Barnett->resetZipLists(); # zippedFiles and shredResults $Barnett->resetAll($localLogsToo = true);
获取器
$Barnett->isGreen(); # false if an error occured $Barnett->getDownloadLink($aliasDirPath = null, # as said before, avoid null $aliasFilename = null, $text = 'download'); $Barnett->getZipLocation(); $Barnett->getZippedFilesList(); $Barnett->getShredList();
助手静态方法
为了文档的完整性。
use SSITU\Barnett\Assistant; # return appropriate ZipArchive flag Assistant::archiveFlag($overwrite); # attempt a recursive mkdir if need to Assistant::affirmDirExistence($dirPath); # remove zip extension from filename Assistant::mayRemoveDotZip(&$filename); # append zip extension to filename Assistant::mayAppendDotZip(&$filename); # append an integer to filename Assistant::findUniqueName(&$zipName); # append a timestamp to filename Assistant::fileIsNow(&$zipName); # cleanup slashes to avoid read/write failures Assistant::reSlash(&$dirPath, $finalSlash = false); # check if path is . or .. Assistant::isDotSegment($path); # handle extensions list: removes dot, set to lower case and jpeg becomes jpg Assistant::normalizeExts(&$extensions); # read a file's extension, set to lower case and jpeg becomes jpg Assistant::extractNormalizedExt($path); # resolve file object deletion Assistant::shred($path);
贡献
当然!🙌 您可以查看CONTRIBUTING。
许可证
该项目受MIT许可证保护;有关详细信息,请参阅LICENSE。
结语
这是等离子体压缩。现在去做其他事情吧。