定制 corbinjurgens/qstorage 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

corbinjurgens/qstorage

Composer 安装命令:

composer require corbinjurgens/qstorage

包简介

Use Laravel Storage Filesystem in an object oriented fashion

README 文档

README

Allows you to use laravel Storage in a more object-oriented fashion. If you are like me, it feels dirty to be repeating the same paths for different operations.

Before:

if (Storage::disk('data')->exists('folder/file.txt')){
  $contents = Storage::disk('data')->get('folder/file.txt');
  ...
  Storage::disk('data')->put('folder/file.txt', $contents);
}

After:

$file = QStorage::disk('data')->file('folder/file.txt');
if ($file->exists()){
  $contents = $file->get();
  ...
  $file->put($contents);
}

Installation

Composer

composer require corbinjurgens/qstorage

Manual Installation

Copy the following to main composer.(in the case that the package is added to packages/corbinjurgens/qform)

 "autoload": {
	"psr-4": {
		"Corbinjurgens\\QStorage\\": "packages/corbinjurgens/qstorage/src"
	},
},

and run

composer dump-autoload

Add the following to config/app.php providers

Corbinjurgens\QStorage\ServiceProvider::class,

Add alias to config/app.php alias

"QStorage" => Corbinjurgens\QStorage\Facade::class,

Usage

Basics

Basically it can be used exactly as the usual laravel Storage system. However, all functions no longer take a path parameter.

For example Storage::get('folder/file.txt') becomes QStorage::file('folder/file.txt')->get()

Using 'file' sets the path. You can also use 'folder' to set path when it is a folder. These will open a new instance relative to the current instance and then set the new path. For example

$disk = QStorage::folder('folder');// 'folder', path is unaffected by the following lines
$file = $disk->file('file.txt');// 'folder/file.txt'
$file1 = $disk->file('file2.txt');// 'folder/file2.txt'

Under the hood this makes use of the 'setSub' function. By opening file or folder with a path already set, it uses the current path as a prefix and builds off that.

If you need to access the underlying disk instance, you can use 'getDisk', eg QStorage::disk('data')->getDisk()->...

Extended Features

The 'move' and 'copy' functions can take a destination path as normal, or a QStorage instance. If the disk is different, it will automatically stream the file between the different disks for you.

QStorage::disk('local')->file('test.txt')->copy(QStorage::disk('s3')->file('test.txt'));

The files() and directories() functions now return a list of new QStorage instances, meaning you can chain more storage functions directly onto them. You can also use items() for both files and directories. Whether or not the results are directories is checked and set

$files = QStorage::folder('folder')->files();
foreach($files as $file){
	$contents = $file->get();
	...
	$file->put($contents);
}

Added Features

A few functions have been added that are not available in the base Laravel Filesystem

You may zip an entire directory by the following function:

$destination = QStorage::disk('s3')->file('archive.zip');
QStorage::disk('local')->folder('test')->zip($destination);

It does not matter if the disks are different, it will use a shared local space to zip the file. The default location is a local driver at "/tmp/process". You can change this by setting QStorage::$operation_disk_fetcher as a closure in your app service provider':

QStorage::$operation_disk_fetcher = function(){
  return \Storage::disk('custom');
};

In addition to the original 'path' function you can also use: relativePath (path relative to the disk) and leafPath (path in the current 'setSub' context ie. within current folder etc). 'path' also has the alias 'absolutePath'

Changelog

  • 2.0.0
    • The 'path' function used to set the current path is changed to 'setPath', and so 'path' can be used in the original Laravel Storage way to fetch the absolute path
    • Added Zip function
    • Cross-disk move and copy
    • Emphasis on file vs directory, can use 'isDir' to check if the retrieved items is a directory
  • 1.0.0
    • Init

corbinjurgens/qstorage 适用场景与选型建议

corbinjurgens/qstorage 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 04 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 corbinjurgens/qstorage 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 corbinjurgens/qstorage 我们能提供哪些服务?
定制开发 / 二次开发

基于 corbinjurgens/qstorage 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 7
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 10
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-04-15