phuxtil/splfileinfo
Composer 安装命令:
composer require phuxtil/splfileinfo
包简介
SplFileInfo compatible implementation that allows to work with virtual (non existing) files
README 文档
README
VirtualSplFileInfo allows to use non existing (virtual) paths and still be able to perform
all file operations like getSize(), isFile(), getOnwer(), etc, and get predefined results.
It has setters support, and helper methods like isVirtual(), toArray(), fromArray(), fromSplFileInfo().
Installation
composer require phuxtil/splfileinfo
Note: Use v1.x for compatibility with PHP v7.0.x. Note: Use v2.x for compatibility with PHP v7.2+
Usage
Create virtual file info.
$path = '/tmp/not-yet/existing-path'; $virtualInfo = new VirtualSplFileInfo($path);
Only PathInfo data is set at this point.
$virtualInfo->getPathname(); # /tmp/not-yet/existing-path $virtualInfo->getPath(); # /tmp/not-yet ...
The rest of the data can be updated with setters.
$virtualInfo->setSize(120); $virtualInfo->setATime(time()); $virtualInfo->setPerms(0775); ...
Note: All properties besides PathInfo are set to -1 by default.
Check if resource is virtual.
$virtualInfo->getType(); # virtual $virtualInfo->isVirtual(); # true
Update virtual file info with real resource data
@mkdir($path); $virtualInfo->fromSplFileInfo(new SplFileInfo($path)); $virtualInfo->isVirtual(); # false
VirtualFileInfo vs \SplFileInfo.
$splInfo = SplFileInfo {
path: "/tmp/not-yet"
filename: "existing-path"
basename: "existing-path"
pathname: "/tmp/not-yet/existing-path"
extension: ""
realPath: "/tmp/not-yet/existing-path"
aTime: 2019-06-15 22:07:47
mTime: 2019-06-15 22:07:47
cTime: 2019-06-15 22:07:47
inode: 10248205
size: 64
perms: 040755
owner: 0
group: 0
type: "dir"
writable: true
readable: true
executable: true
file: false
dir: true
link: false
}
$virtualInfo = Phuxtil\SplFileInfo\VirtualSplFileInfo {
path: "/tmp/not-yet"
filename: "existing-path"
basename: "existing-path"
pathname: "/tmp/not-yet/existing-path"
extension: ""
realPath: "/tmp/not-yet/existing-path"
aTime: 2019-06-15 22:07:47
mTime: 2019-06-15 22:07:47
cTime: 2019-06-15 22:07:47
inode: 10248205
size: 64
perms: 040755
owner: 0
group: 0
type: "dir"
writable: true
readable: true
executable: true
file: false
dir: true
link: false
}
Extra methods
isVirtual(): bool
Returns true if the and does not really exist.
Note: isReadable(), isFile(),... etc, can return true, even if the resource does not exist.
fromSplFileInfo(\SplFileInfo $info)
$path = '/tmp/not-yet/existing-file.txt'; $virtualInfo = new VirtualSplFileInfo($path); // ... do stuff // create resource later file_put_contents($path, 'Lorem Ipsum'); // update virtual file info $virtualInfo->fromSplFileInfo(new SplFileInfo($path));
toArray(): array
$info = new VirtualSplFileInfo('/tmp/not-yet/existing-path'); $data = $info->toArray();
fromArray(array $data)
$info = new VirtualSplFileInfo('/tmp/not-yet/existing-path'); $info->fromArray( [ 'aTime' => 123, 'mTime' => 456, 'cTime' => 789, 'inode' => 222, 'size' => 333, 'perms' => 0755, 'owner' => 1, 'group' => 2, 'type' => 'dir', 'writable' => true, 'readable' => true, 'executable' => true, 'file' => false, 'dir' => true, 'link' => false, ] );
Setter support
You can use setters for all properties besides PathInfo, which is resolved by default in \SplFileInfo.
The resource does not have to yet exist for those methods to work.
Properties with setters:
realPath
aTime
mTime
cTime
inode
size
perms
owner
group
type
writable
readable
executable
file
dir
link
linkTarget
Default values
All values besides PathInfo are set to -1 by default.
TDD
See tests for more examples.
phuxtil/splfileinfo 适用场景与选型建议
phuxtil/splfileinfo 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 15.26k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 06 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 phuxtil/splfileinfo 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 phuxtil/splfileinfo 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 15.26k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 19
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-06-11