joytekmotion/zoho-workdrive

Laravel flysystem adapter for Zoho Workdrive

v1.0.4 2024-11-06 04:12 UTC

This package is auto-updated.

Last update: 2025-03-06 04:59:09 UTC


README

Flysystem API version Latest Version on Packagist License

This package contains Laravel Flysystem adapter for Zoho Workdrive. It uses the virtual path to interact with the Zoho Workdrive API.

Requirements

  • PHP 8.1 or higher
  • Laravel 8.x or higher

Installation

You can install this package via composer:

composer require joytekmotion/zoho-workdrive

Setup

  • Add the following zoho credentials to your .env file:
ZOHO_CLIENT_ID=
ZOHO_CLIENT_SECRET=
ZOHO_REFRESH_TOKEN=
ZOHO_SCOPE=WorkDrive.files.ALL,ZohoFiles.files.READ,WorkDrive.files.sharing.CREATE

To get the ZOHO_CLIENT_ID and ZOHO_CLIENT_SECRET, you need to create a Zoho Self Client in the Zoho Developer Console.

  • To generate refresh token, you can use the following command:
php artisan zoho-oauth:refresh-token {code}

Replace {code} with the authorization code you generated from Zoho Developer Console, and copy the refresh token to your .env file.

  • Add the following disk configuration to your config/filesystems.php file:
'workdrive' => [
    'driver' => 'workdrive',
    'client_id' => env('ZOHO_CLIENT_ID'),
    'client_secret' => env('ZOHO_CLIENT_SECRET'),
    'refresh_token' => env('ZOHO_REFRESH_TOKEN')
]
  • Optional: The service provider will be automatically registered by Laravel. If you need to manually register the service provider, add the following to your config/app.php file:
'providers' => [
    ...
    Joytekmotion\Zoho\Oauth\Providers\ZohoOauthServiceProvider::class,
    ...
]
  • Add the driver by extending the Storage facade in your AppServiceProvider or any other service provider:
namespace App\Providers;

use Illuminate\Support\Facades\Storage;
use Joytekmotion\Zoho\Workdrive\WorkdriveAdapter;
use Joytekmotion\Zoho\Oauth\SelfClient;
use Illuminate\Filesystem\FilesystemAdapter;
use League\Flysystem\Filesystem;

publc function boot()
{
    Storage::extend('workdrive', function ($app, $config) {
        $adapter =  new WorkDriveAdapter(
            new SelfClient(
                config('zoho.oauth_base_url'),
                $config['client_id'],
                $config['client_secret'],
                $config['refresh_token']
            )
        );
        return new FilesystemAdapter(
            new Filesystem($adapter, $config), $adapter, $config
        );
    });
}
  • Optional: You can publish the configuration file using the following command:
php artisan vendor:publish --provider="Joytekmotion\Zoho\Oauth\Providers\ZohoOauthServiceProvider"

Usage

To write a file to the disk:

use Illuminate\Support\Facades\Storage;

Storage::disk('workdrive')->put('virtual-folder-id/file.txt', 'contents');

To read a file from the disk:

use Illuminate\Support\Facades\Storage;

$contents = Storage::disk('workdrive')->get('virtual-folder-id/file.txt');

To check if a file exists:

use Illuminate\Support\Facades\Storage;

$exists = Storage::disk('workdrive')->exists('virtual-folder-id/file.txt');

Acknowledgements

This package is inspired by flysystem-google-drive-ext created by masbug.

License

The MIT License (MIT). Please see License File for more information.