定制 smadia/laravel-google-drive-connector 二次开发

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

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

smadia/laravel-google-drive-connector

Composer 安装命令:

composer require smadia/laravel-google-drive-connector

包简介

Connector for Laravel with Google Drive API

README 文档

README

0.0.2

Installation

Make sure you have already installed laravel >= 5.2.*

Then, install package via composer

composer require "smadia/laravel-google-drive-connector:0.0.*"

Register Facade in config/app.php

'aliases' => [
    .....
    'LGD' => Smadia\LaravelGoogleDrive\Facades\LaravelGoogleDrive::class
    .....
]

Register ServiceProvider in config/app.php

'providers' => [
    .....
    Smadia\LaravelGoogleDrive\Providers\LaravelGoogleDriveServiceProvider::class
    .....
]

You can create your own Facade and ServiceProvider manually, and then register it.

Configuration

Before using package, make sure you have added new disk in config/filesystem.php

'disks' => [

    // ...

    'googledrive' => [
        'driver' => 'googledrive',
        'clientId' => env('GOOGLE_DRIVE_CLIENT_ID'),
        'clientSecret' => env('GOOGLE_DRIVE_CLIENT_SECRET'),
        'refreshToken' => env('GOOGLE_DRIVE_REFRESH_TOKEN'),
        'folderId' => env('GOOGLE_DRIVE_FOLDER_ID'),
    ],

    // ...

],

Then, you should add new field in .env files

FILESYSTEM_CLOUD=googledrive
GOOGLE_DRIVE_CLIENT_ID=xxx.apps.googleusercontent.com
GOOGLE_DRIVE_CLIENT_SECRET=xxx
GOOGLE_DRIVE_REFRESH_TOKEN=xxx
GOOGLE_DRIVE_FOLDER_ID=null

How do I get the Google Drive API ? Follow these links :

Usage

Usage in non-object file

You can use LGD Facade in non-object file, such as routes/web.php, blade file. Below is the example usage in non-object file

LGD::dir('mydir')->ls()->toObject();

If you are using the Facade in object context, you should use the Facade in Smadia\LaravelGoogleDrive\Facades\LaravelGoogleDrive after the namespace declaration like below

<?php

namespace App\User;

// other use declaration
use Smadia\LaravelGoogleDrive\Facades\LaravelGoogleDrive;
// other use declaration

After that, you can use LaravelGoogleDrive facade instead than LGD like below

LaravelGoogleDrive::ls()->toArray()

To use it only with LGD keyword, you can use as in use declaration like code below

<?php

namespace App\User;

// other use declaration
use Smadia\LaravelGoogleDrive\Facades\LaravelGoogleDrive as LGD;
// other use declaration

Get list contents from your root directory

LGD::ls()->toArray()

Get the spesific directory

LGD::dir('mydir')->ls()->toArray()

Get the spesific index if you have two or more with the same name

Index is started from 0 (zero)

LGD::dir('mydir, 2)->ls()->toArray()

Get the spesific file in certain directory

LGD::dir('mydir')->file('youfile', 'txt')->name

You can add index to get the file (if you have two or more files with the same name)

LGD::dir('mydir')->file('yourfile', 'txt', 2)->name

Get other file's properties

Below is the list of file's property which you can get by adding ->(property) after file() method

  • name
  • extension
  • path
  • dirname
  • basename
  • size
  • timestamp
  • mimetype (only for file type)
  • type

Filter

To filter the list contents of directory, you can use filter() method

    LGD::ls(function($ls) {
        return $ls->where('type', '=', 'dir'); // another option of 'type' is 'file'
    })->toArray();

File Storing

These are some example to store file in Google Drive

LGD::put('hello.txt', 'Hello World !');

If you want store the uploaded file in your controller, you can use this one

LGD::put('hello.txt', file_get_contents($request->file('file')->getRealPath()));

If you want the name is same with the orginal uploaded file, you can assign the $request->file() as parameter

LGD::put($request->file('file'));

Directory methods

Below is optional method to your directory

Method Usage Description
ls($filter = null) Get the list contents of the current directory This method will return the Smadia/GoogleDriveLaravel/ListContent Class. $filter is a closure which return the $filter itself
delete() Delete the current directory -
rename($newname) Rename the current directory This method will return back the DirectoryHandler Class
put($filename, $contents = null) Put a new file to the current directory $contents can be null if the $filename is instance of FileHandler class. This method will return the FileHandler class of the created file. $filename can assign with UploadedFile class ($request->file() in Laravel)
file($filename, $extension, $index = 0) Get the specified file This method will return the FileHandler class
isExist() Check is the directory exist Return boolean type
mkdir($dirname) Make a new directory inside the current directory This method will return the DirectoryHandler class of the created directory
dir($dirname, $index = 0) Go to specified directory This method will return the DirectoryHandler class of the requested directory with certain index (default is 0)
parent() Get the parent directory This method will return the DirectoryHandler class

File Methods

Method Usage Description
rename($newname) Rename the current file This method will return the same FileHandler class
delete() Delete the current file This method will not delete all files with the same name in the same level of directory
isExist() Check whether the file is exist -
getDir() Get the directory where the file is located This method will return the DirectoryHandler class
show() Show the file in browser. Only work for jpeg, jpg, png, gif, and svg file extension -
download() Give a download response -

List Content Methods

Method Usage Description
toArray() Get list contents as array -
toCollect() Get list contents as Laravel's collection -
toObject() Get list contents as array which contains FileHandler or DirectoryHandler as it's member -
dir($dirname, $index = 0) Get the directory where the file is located This method will return the DirectoryHandler class
file($filename, $extension, $index = 0) Get the specific file name and extension This method will return the FileHandler class
filter($filter) Get the directory where the file is located This method will return the DirectoryHandler class. $filter is a closure which return the $filter itself
getAllProperties() Get all properties of a file or directory This method will return all properties in array

smadia/laravel-google-drive-connector 适用场景与选型建议

smadia/laravel-google-drive-connector 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.01k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 10 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 smadia/laravel-google-drive-connector 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GNU
  • 更新时间: 2017-10-28