padosoft / io
用于IO相关的简单通用包(文件、目录等)
1.9.0
2022-04-04 22:16 UTC
Requires
- php: >=7.0.0
Requires (Dev)
- phpunit/phpunit: ~5.0|^6.0|^7.0|^8.0|^9.0
README
这是一个具有少量或零依赖的简单通用包。它非常适合创建不需要许多依赖项的包。
##需求
- php: >=7.0.0
安装
您可以通过composer安装此包
$ composer require padosoft/io
用法
以下是使用FileHelper
类的示例
添加使用语句 use Padosoft\Io\FileHelper;
<?php if(FileHelper::checkDirExistOrCreate('public/upload', '0755')){ echo 'dir already exists or now created!'; }else{ echo 'OOPS! dir not exists and unable to create it!'; } //get all files in public/upload/ $arrFiles = FileHelper::findFiles('public/upload/*'); var_dump($arrFiles); //get all jpeg in public/upload/ $arrFiles = FileHelper::findFiles('public/upload/*.jpg'); var_dump($arrFiles); //check if the path ends with slash if(DirHelper::endsWithSlash('public/upload')){ echo 'add a final slash...'; $path = DirHelper::addFinalSlash('public/upload'); echo $path; }else{ echo 'path already finish with slash.'; } //get all directories in public/upload/ $arrFolders = DirHelper::findDirs('public/upload/*'); var_dump($arrFolders); //truncate log to last 2000 bytes without truncate line echo 'before:'.PHP_EOL; echo file_get_contents('log.csv'); if(LogHelper::ftruncatestart('log.csv', 2000)){ echo 'after:'.PHP_EOL; echo file_get_contents('log.csv'); }
函数列表
DirHelper
- isDirSafe
- checkDirExistOrCreate
- addFinalSlash
- addFinalSlashToAllPaths
- endsWithSlash
- endsWithStar
- endsWith
- startsWithSlash
- startsWith
- findDirs
- delete
- removeFinalSlash
- removeFinalSlashToAllPaths
- removeStartSlash
- removeStartSlashToAllPaths
- copy
- isLocal
- isAbsoluteUnix
- isAbsoluteWindows
- isAbsoluteWindowsRoot
- isAbsolute
- isRelative
- join
- njoin
- canonicalize
- isDirEmpty : 以高效的方式检查目录是否为空。同时检查隐藏文件。
- isDotDir : 检查条目是否为linux点目录(即:. 或 ..)
- isReadable : 检查路径是否为目录且可读。
FileHelper
- arrMimeType
- getPathinfoPart
- getDirname
- getFilename
- getFilenameWithoutExtension
- getFilenameExtension
- hasExtension
- variable2Array
- changeExtension
- unlinkSafe
- fileExistsSafe
- findFiles
- filePutContentsSafe
- getMimeType
- getMimeTypeByFinfo
- getMimeTypeByMimeContentType
- isReadable : 检查路径是否为文件且可读。
- filPerms : 获取文件或目录权限的八进制形式(例如'0777')或否(例如'644')。
LogHelper
- ftruncatestart
变更日志
请参阅 CHANGELOG 获取更多信息。
测试
$ composer test
贡献
请参阅 CONTRIBUTING 获取详细信息。
安全
如果您发现任何与安全相关的问题,请通过电子邮件报告,而不是使用问题跟踪器。
鸣谢
关于Padosoft
Padosoft (https://www.padosoft.com) 是一家位于意大利佛罗伦萨的软件公司。专注于电子商务和网站。
许可
MIT许可(MIT)。请参阅 许可文件 获取更多信息。