当前位置:网站首页>[symfony/finder] The best file manipulation library
[symfony/finder] The best file manipulation library
2022-08-02 03:55:00 【phpreturn】
Sometimes, we need to operate the files on the server, either traverse the directory or find the corresponding extension files. At this time, the code we found on the Internet is very bad. Is there an elegant high-performance one?How?
finder is one such library.
Basic usage
use Symfony\Component\Finder\Finder;$finder = new Finder();// go to a folder$finder->files()->in(__DIR__);// check if it is emptyif ($finder->hasResults()) {// ...}foreach ($finder as $file) {// start traversing the file$absoluteFilePath = $file->getRealPath();$fileNameWithExtension = $file->getRelativePathname();// ...}Elegant Filtered Search
Calling the in method in a chain means looking for another directory under a certain directory.
$finder->in(__DIR__)->in('/elsewhere');Match the corresponding file by *
$finder->in('src/Symfony/*/*/Resources');Exclude some files
$finder->in(__DIR__)->exclude('ruby');Directly filter out files that do not have permission to read
$finder->ignoreUnreadableDirs()->in(__DIR__);Support various underlying systems
Support access to standard file protocols
// Open an FTP address$finder->in('ftp://example.com/');$finder->in('ftp://example.com/pub/');The following access methods are supported:
- file:// — access the local file system
- http:// — Access HTTP(s) URL
- ftp:// — Access FTP(s) URLs
- php:// — access each input/I/O streams
- zlib:// — Compressed Streamli>
- data:// — Data (RFC 2397)
- glob:// — find matching filesPath Pattern
- phar:// — PHP Archiveli>
- ssh2:// — Secure Shell 2
- rar:// — RAR
- ogg:// — Audio Streamingli>
- expect:// — handles interactiveStream
Supports custom underlying system protocols, the following example shows access to Amazon's storage.
use Symfony\Component\Finder\Finder;// Register access protocol through AWS official package 's3://'$s3Client = new Aws\S3\S3Client([/* config options */]);$s3Client->registerStreamWrapper();$finder = new Finder();$finder->name('photos*')->size('< 100K')->date('since 1 hour ago');foreach ($finder->in('s3://bucket-name') as $file) {// ... do something with the file}Easy to manipulate files or directories
// only query files$finder->files();// only query the directory$finder->directories();Filter files
Supports a very elegant way of manipulating files.
$finder->files()->name('*.php');$finder->files()->name('/\.php$/');$finder->files()->notName('*.rb');$finder->files()->size('>= 1K')->size('<= 2K');$finder->date('>= 2018-01-01')->date('<= 2018-12-31');边栏推荐
- 微信小程序自定义swiper轮播图面板指示点|小圆点|进度条
- (2)Thinkphp6模板引擎**标签
- [league/flysystem]一个优雅且支持度非常高的文件操作接口
- The Error in the render: "TypeError: always read the properties of null '0' (reading)" Error solution
- Using PHPMailer send mail
- js 正则中 replace() 使用
- 面试总结 22/7/22 面试中的重点
- PHP 给图片添加全图水印
- (7) 浅学 “爬虫” 过程 (概念+练习)
- [symfony/mailer] An elegant and easy-to-use mail library
猜你喜欢

解决 Zlibrary 卡死/找不到域名/达到限额问题,Zlibrary最新地址

13.JS输出内容和语法

PHP8.2中字符串变量解析的新用法

IP access control: teach you how to implement an IP firewall with PHP
![[league/climate] A robust command-line function manipulation library](/img/ce/39114b1c74af649223db97e5b0e29c.png)
[league/climate] A robust command-line function manipulation library

6.24今日学习

SQL:DDL、DML、DQL、DCL相应介绍以及演示

微信小程序云开发之券码领取,怎么防止用户领取到相同的数据?

(2) Thinkphp6 template engine ** tag

js __proto__、prototype、constructor的关系
随机推荐
5.20今日学习
如何计算地球上两点的距离(附公式推导)
[phpunit/php-timer]一个用于代码执行时间的计时器
What are the PHP framework?
(8) requests、os、sys、re、_thread
js的“类数组”及“类数组转数组”
page load process
SQL classification, DQL (Data Query Language), and corresponding SQL query statement demonstration
About the apache .htaccess file of tp
uniapp | 使用npm update更新后编译报错问题
(3)Thinkphp6数据库
AES加密的各种蛋疼方式方式
When PHP initiates Alipay payment, the order information is garbled and solved
数组的高级操作
微信小程序开发视频加载:[渲染层网络层错误] Failed to load media
Phpstudy installs Thinkphp6 (problem + solution)
轮播图详解(完整代码在最后)
easyswoole 使用redis执行geoRadiusByMember Count无效修复
PHP的几个有趣的打开方式:从基本到变态
Advanced Operations on Arrays