Skip to content

Minimalist Helper to use the complete PHP SDK alorel/dropbox-v2-php

License

Notifications You must be signed in to change notification settings

Headoo/DropboxHelper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status codecov Latest Stable Version License

DropboxHelper

Minimalist helper to use the complete PHP SDK for Dropbox's v2 API Alorel/dropbox-v2-php. Simplifies at best the following uses at Dropbox:

  • read/write/delete a file
  • list a folder from the path
  • list the delta of a folder from the cursor
  • get account information of the connected account

Installation

Via Composer

$ composer require headoo/dropboxhelper

Utilisation

Load the helper:

<?php
    use \Headoo\DropboxHelper\DropboxHelper;

    $dropboxHelper = new DropboxHelper($yourAppDropboxToken);
?>

or

<?php
    $dropboxHelper = new DropboxHelper();
    $dropboxHelper->setToken($yourAppDropboxToken);
?>

Write/Read/Delete a file:

<?php
    use \Headoo\DropboxHelper\DropboxHelper;

    $dropboxHelper = new DropboxHelper($yourAppDropboxToken);

    $dropboxHelper->write('/Path/To/The/File', 'put your content here');
    $dropboxHelper->read('/Path/To/The/File');
    $dropboxHelper->delete('/Path/To/The/File');
?>

List a folder from the path:

<?php
    use \Headoo\DropboxHelper\DropboxHelper;

    $dropboxHelper = new DropboxHelper($yourAppDropboxToken);

    $oFolder = $dropboxHelper->loadFolderPath('/Path/To/List');
    while ($oFolder && ($aMedia = $oFolder->next())) {
        if (DropboxHelper::isFolder($aMedia)) {
            echo $aMedia['name'] . ' is a folder';
        }
        if (DropboxHelper::isFile($aMedia)) {
            echo $aMedia['name'] . ' is a file';
        } 
    }
?>

List a folder from the cursor:

<?php
    use \Headoo\DropboxHelper\DropboxHelper;

    $dropboxHelper = new DropboxHelper($yourAppDropboxToken);

    $oFolder = $dropboxHelper->loadFolderCursor('--this--is--the--last--cursor--of--the--folder--');
    while ($oFolder && ($aMedia = $oFolder->next())) {
        if (DropboxHelper::isFolder($aMedia)) {
            echo $aMedia['name'] . ' is a folder';
        }
        if (DropboxHelper::isFile($aMedia)) {
            echo $aMedia['name'] . ' is a file';
        }
    }
    
    echo "The last cursor of the folder is: " . $oFolder->getCursor();
?>

Unit Test

Prerequisite

git clone https://github.com/Headoo/DropboxHelper.git
composer install

Test

To test this project with PHPUnit, declare following environment variables:

$ export DROPBOX_TOKEN="YourAppDropboxToken"
$ export DROPBOX_FOLDER_PATH="/Path/In/Your/Dropbox/To/Test"

Then, launch PHPUnit:

$ ./vendor/phpunit/phpunit/phpunit -c phpunit.xml

Links

About

Minimalist Helper to use the complete PHP SDK alorel/dropbox-v2-php

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages