painless-php / filesystem
文件系统助手功能
dev-master
2024-01-12 15:07 UTC
Requires
- php: >=8.1
- ext-mbstring: *
Requires (Dev)
- phpunit/phpunit: ^10.1
- spatie/phpunit-watcher: ^1.22
- vlucas/phpdotenv: ^v5.5.0
This package is auto-updated.
Last update: 2024-09-12 16:37:15 UTC
README
PHP的文件系统助手功能。
安装
composer require painless-php/filesystem
公共API
核心
- 文件系统
- 文件系统对象
- 文件
- 目录
- 目录迭代器配置
异常
- 文件系统异常
- 文件未找到异常
- 文件系统权限异常
接口
- 文件系统过滤器
- 目录内容迭代器
用法示例
读取目录内容
// with iterator $iterator = Directory::createFromPath($path)->getIterator( recursive: true, config: new DirectoryIteratorConfig( resultFilters: [ fn(FilesystemObject $file) => $file->getExtension() === 'php' ] ) ); // loop over iterator items foreach($iterator as FileObject $file) { var_dump($file); } // turn iterator into array $array = $iterator->toArray(); // with getContents $files = Directory::createFromPath($path)->getContents( recursive: true, config: new DirectoryIteratorConfig( resultFilters: [ fn(FilesystemObject $file) => $file->getExtension() === 'php' ] ) );
注意
- isRoot()可能在Windows上无法正常工作(以及依赖于它的函数,如findUpwards)
目录内容迭代器结构
- 目录内容迭代器(FilterIterator)
- 递归迭代器迭代器
- 递归过滤器迭代器
- 递归目录迭代器