adlawson/vfs
Composer 安装命令:
composer require adlawson/vfs
包简介
Virtual file system
README 文档
README
VFS is a virtual file system for PHP built using the stream wrapper API.
Streams are exposed just as typical file:// or http:// streams are to PHP's
built-in functions and keywords like fopen and require. This implementation
attempts to stay true to the typical streams, including triggering warnings
and handling edge cases appropriately.
It can be installed in whichever way you prefer, but I recommend Composer.
{
"require": {
"adlawson/vfs": "*"
}
}
Documentation
After creating and mounting the file system, you have the option of manipulating the virtual file system either via PHP's built-in functions, the VFS interfaces, or interfaces provided by another file system library.
<?php use Vfs\FileSystem; use Vfs\Node\Directory; use Vfs\Node\File; // Create and mount the file system $fs = FileSystem::factory('vfs://'); $fs->mount(); // Add `/foo` and `/foo/bar.txt` $foo = new Directory(['bar.txt' => new File('Hello, World!')]); $fs->get('/')->add('foo', $foo); // Get contents of `/foo/bar.txt` $fs->get('/foo/bar.txt')->getContent(); // Hello, World! file_get_contents('vfs://foo/bar.txt'); // Hello, World! // Add `/foo/bar` and `/foo/bar/baz.php` mkdir('vfs://foo/bar'); file_put_contents('vfs://foo/bar.php', '<?php echo "Hello, World!";'); // Require `/foo/bar.php` require 'vfs://foo/baz.php'; // Works with any other file system library too $symfony = new Symfony\Component\Filesystem\Filesystem(); $symfony->mkdir('vfs://foo/bar/baz'); $laravel = new Illuminate\Filesystem(); $laravel->isDirectory('vfs://foo/bar/baz'); //true // Triggers PHP warnings on error just like typical streams rename('vfs://path/to/nowhere', 'vfs://path/to/somewhere'); // PHP Warning: rename(vfs://path/to/nowhere,vfs://path/to/somewhere): No such file or directory in /srv/index.php on line 1; triggered in /srv/src/Logger/PhpErrorLogger.php on line 32
Example use cases
If you need to ask what you'd use a virtual file system for, you probably don't need one, but just in case, I've compiled a small list of examples:
- Testing file system libraries without writing to disc
- Runtime evaluation without
eval(viawriteandrequire) - ...we need some more!
Todo
Current tasks are listed on the github issues page, but some are listed here for reference:
- Symlinks
- File locks
- Permissions/ACL
Contributing
Contributions are accepted via Pull Request, but passing unit tests must be included before it will be considered for merge.
$ curl -O https://raw.githubusercontent.com/adlawson/vagrantfiles/master/php/Vagrantfile
$ vagrant up
$ vagrant ssh
...
$ cd /srv
$ composer install
$ vendor/bin/phpunit
License
The content of this library is released under the MIT License by
Andrew Lawson.
You can find a copy of this license in
LICENSE or at http://opensource.org/licenses/mit.
adlawson/vfs 适用场景与选型建议
adlawson/vfs 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 440.16k 次下载、GitHub Stars 达 300, 最近一次更新时间为 2014 年 07 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「file」 「stream」 「directory」 「virtual」 「wrapper」 「system」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 adlawson/vfs 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 adlawson/vfs 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 adlawson/vfs 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Object-Oriented API for PHP streams
The file manager intended for using Laravel with CKEditor / TinyMCE / Colorbox
LDAP user provider bundle for Symfony 6.4
Safely namespaced guzzle psr7 for WP2Static
Interface for a factory to create Psr\Http\Message\StreamInterface objects
Implementation of webignition/stream-factory-interface
统计信息
- 总下载量: 440.16k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 301
- 点击次数: 34
- 依赖项目数: 26
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-07-06