Skip to content

Merge branches recette into master #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ php:
- '5.6'
- '7.0'
- '7.1'
- hhvm

install:
- composer install
Expand Down
43 changes: 8 additions & 35 deletions src/Object/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ class Folder extends AbstractExceptionMode
private $iFolderIndex = 0;
/** @var array $aFolder: list of object in the current folder */
private $aFolder = [];
/** @var bool $bFolderReading: is a folder is currently reading */
private $bFolderReading = false;

public function __construct()
{
Expand Down Expand Up @@ -64,9 +62,12 @@ public function loadFolderCursor($sCursor)
*/
public function next()
{
# You have to loadFolder before
$bLoaded = $this->isFolderLoaded();
if ($bLoaded === false) {
# throw Exception in strict mode
if (!isset($this->aFolder["entries"])) {
if ($this->exceptionMode === DropboxHelper::MODE_STRICT) {
throw new FolderNotLoadException("Dropbox configuration error. Trying to get cursor without a reading folder. call loadFolder()/loadFolderContinue() before");
}

return null;
}

Expand All @@ -83,10 +84,6 @@ public function next()
return $this->getObjectOnCurrentIndex();
}

# End of folder
$this->bFolderReading = false;
unset($this->aFolder);

return null;
}

Expand All @@ -96,9 +93,7 @@ public function next()
*/
public function getCursor()
{
$bLoaded = $this->isFolderLoaded();

if ($bLoaded === false) {
if (!isset($this->aFolder['cursor'])) {
return null;
}

Expand All @@ -122,10 +117,7 @@ private function initLoadingPartOfFolder($sFolder)
return false;
}

# If folder has some entries
$this->bFolderReading = (count($this->aFolder["entries"]) != 0);

return $this->bFolderReading;
return true;
}

/**
Expand All @@ -140,29 +132,10 @@ private function getObjectOnCurrentIndex()
return $object;
}

/**
* @return bool
* @throws FolderNotLoadException
*/
private function isFolderLoaded()
{
if ($this->bFolderReading === true) {
return true;
}

# throw Exception in strict mode
if ($this->exceptionMode === DropboxHelper::MODE_STRICT) {
throw new FolderNotLoadException("Dropbox configuration error. Trying to get cursor without a reading folder. call loadFolder()/loadFolderContinue() before");
}

return false;
}

private function initializeFolder()
{
$this->iFolderIndex = 0;
$this->aFolder = [];
$this->bFolderReading = false;
}

}
Expand Down
16 changes: 3 additions & 13 deletions tests/DropboxHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function setUp()
if (isset($env['DROPBOX_TOKEN'])) {
$this->dropboxHelper = new DropboxHelper($env['DROPBOX_TOKEN']);
} else {
echo "\nWARNING: Dropbox token is empty.\n";
trigger_error("WARNING: Dropbox token is empty.", E_USER_WARNING);
}
}

Expand Down Expand Up @@ -85,8 +85,6 @@ public function testGetCursor()
$sCursor = $oFolder->getCursor();

self::assertNotEmpty($sCursor, 'Failed to get cursor on a loaded folder');

echo "\nLast Cursor of '{$this->sFolderPath}':\n$sCursor\n";
}

/**
Expand Down Expand Up @@ -168,26 +166,20 @@ public function testListFolderFromName()
}

if (empty($this->sFolderPath)) {
echo 'WARNING: Cannot run ' . __FUNCTION__ . ', Dropbox folder path is empty.';
trigger_error('WARNING: Cannot run ' . __FUNCTION__ . ', Dropbox folder path is empty.', E_USER_WARNING);
return;
}

$oFolder = $this->dropboxHelper->loadFolderPath($this->sFolderPath);

echo "\nList Folder: {$this->sFolderPath}\n";
while ($oFolder && ($aMedia = $oFolder->next())) {
if (DropboxHelper::isFile($aMedia)) {
echo 'File:' . $aMedia['name'] . ' ';
}
if (DropboxHelper::isFolder($aMedia)) {
echo 'Folder:' . DropboxHelper::getPath($aMedia);
}
if (DropboxHelper::isDeleted($aMedia)) {
echo 'Deleted:' . $aMedia['name'] . ' ';
}
}

echo "\n";
}

public function testListFolderFromCursor()
Expand All @@ -197,17 +189,15 @@ public function testListFolderFromCursor()
}

if (empty($this->sCursor)) {
echo 'WARNING: Cannot run ' . __FUNCTION__ . ', Dropbox folder cursor is empty.';
trigger_error('WARNING: Cannot run ' . __FUNCTION__ . ', Dropbox folder cursor is empty.', E_USER_WARNING);
return;
}

$oFolder = $this->dropboxHelper->loadFolderCursor($this->sCursor);

self::assertNotNull($oFolder, "Cannot load a folder from cursor: {$this->sCursor}");

echo "\nList Folder from Cursor:\n";
while (($aFolder = $oFolder->next())) {
echo $aFolder['.tag'] . ':' . $aFolder['name'] . ' ';
}
}

Expand Down