linkorb / filelist
Requires
- php: >=5.3.0
- linkorb/objectstorage: ~2.0
- symfony/console: ~2.4
This package is auto-updated.
Last update: 2022-02-01 12:31:44 UTC
README
轻松管理应用程序中任何对象的文件列表
请阅读:此包不再维护,已被更好的实现取代。请检查 FileSpace:http://github.com/linkorb/filespace
工作原理
首先,您需要实例化一个 driver
。驱动程序允许您选择文件将物理存储的位置。最简单的驱动程序是 FileSystemDriver
。您可以这样实例化它
$driver = new LinkORB\Component\FileList\Driver\FileSystemDriver("/data/myfilelists/");
其次,您为新文件列表定义一个 key
。以下是一些示例
user.joe.contracts
:这将存储名为 "joe" 的用户的全部合同project.42.scans
:在这里,您将存储 ID 为 "42" 的项目的所有扫描post.99.downloads
:将下载列表附加到 ID 为 "99" 的帖子
...等等。这些键的选择取决于您和您的应用程序。它们无需存在于任何地方,也无需注册。它将正常工作。
现在,您已经为列表选择了 key
,您可以检索您的文件列表实例
$filelist = $driver->getFileListByKey('user.joe.contracts'); echo "Attached files: " . $filelist->getFileCount();
使用文件列表实例,您可以轻松添加、删除和列出文件
// Upload a local file to the filelist, and give it a name: $filelist->upload("/tmp/myphoto.png", "avatar.png"); // List all files on the filelist: foreach($filelist->getFiles() as $file) { echo "File: " . $file->getFilename() . "\n"; } // Download the file back from the filelist to a local directory: $filelist->download("/home/photo.png", "avatar.png"); // Delete the file from the filelist: $filelist->delete("avatar.png");
优点
与常规文件相比,使用 FileList 的一个优点是可以交换存储后端。
直接写入目录中的文件既快又简单,但随着应用程序的增长,您可能希望开始将数据远程存储在 S3、GridFS 等处...
使用 FileList 库,这变成了简单的事情,只需附加不同的驱动程序。例如,您可以使用 objectstorage 库轻松地将内容存储在 S3、GridFs、PDO 等。
控制台工具
此库附带一个简单的控制台应用程序,它使用该库。您可以使用它进行测试和检查。
示例控制台命令
# Upload a file to a filelist
bin/console filelist:upload user.joe.photos /home/test/avatar.png
# Download a file from a filelist
bin/console filelist:download user.joe.photos avatar.png /home/test/output.png
# List files on a filelist
bin/console filelist:list user.joe.photos
# Delete data from object storage
bin/console filelist:delete user.joe.photos avatar.png
配置文件
控制台工具可以使用配置文件进行配置。
它将在当前目录中查找名为 filelist.conf
的文件。如果找不到,它将查找 ~/.filelist.conf
,最后查找 /etc/filelist.conf
。
您还可以通过使用选项 --config myconfig.conf
显式指定配置文件。
示例配置文件
此存储库包含一个名为 filelist.conf.dist
的文件,您可以将其复制到 filelist.conf
并添加自己的配置。该文件中的注释解释了哪些选项可用。
特性
- PSR-0 兼容,与 composer 兼容并在 Packagist.org 上注册
- PSR-1 和 PSR-2 编码风格
- 列表、上传、下载、删除、获取和设置命令。
- 包含命令行实用程序,用于测试和内省。
待办事项(欢迎Pull Requests!)
- 集成github.com/linkorb/objectstorage以支持S3、GridFs、PDO
安装
有关安装和运行Composer的详细信息,请查看composer。
然后,将linkorb/objectstorage
添加到您的项目中的composer.json
。
{ "require": { "linkorb/filelist": "dev-master" } }
贡献
准备好构建和改进这个仓库了吗?太好了!请继续将此仓库分叉/克隆,我们期待您的Pull Requests!
如果您无法自己实现您喜欢的更改,请不要犹豫,打开一个新的问题报告,以便我们或其他人可以处理。
许可协议
请查看LICENSE.md以获取完整的许可信息。
由LinkORB工程团队提供
请在linkorb.com/engineering查看我们的其他项目。
顺便说一句,我们在招聘!