headoo / dropboxhelper
Minimalist Helper to use PHP SDK alorel/dropbox-v2-php
0.1.5-alpha
2017-08-29 11:06 UTC
Requires
- alorel/dropbox-v2-php: ^0.4.2
Requires (Dev)
- phpunit/phpunit: ^5.0
This package is not auto-updated.
Last update: 2024-11-23 21:04:39 UTC
README
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"
- Your app Dropbox Token can be found here https://www.dropbox.com/developers/apps
- For folder path, do not forget the leading slash (/)
Then, launch PHPUnit:
$ ./vendor/phpunit/phpunit/phpunit -c phpunit.xml