Skip to content

Commit

Permalink
Merge pull request #84 from barryvdh/fix-flysystem3
Browse files Browse the repository at this point in the history
Fix flysystem3
  • Loading branch information
barryvdh authored Mar 15, 2022
2 parents e58c1cf + c68c668 commit c9fea39
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 273 deletions.
47 changes: 0 additions & 47 deletions src/Cache/SessionStore.php

This file was deleted.

82 changes: 49 additions & 33 deletions src/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
use League\Flysystem\Cached\CacheInterface;
use League\Flysystem\Filesystem;
use League\Flysystem\FilesystemOperator;
use League\Flysystem\UnableToCopyFile;
use League\Flysystem\UnableToCreateDirectory;
use League\Flysystem\UnableToDeleteDirectory;
use League\Flysystem\UnableToDeleteFile;
use League\Flysystem\UnableToMoveFile;
use League\Flysystem\UnableToWriteFile;
use League\Flysystem\Util;
use League\Flysystem\FilesystemInterface;
use League\Flysystem\Cached\Storage\Memory as MemoryStore;
use League\Flysystem\WhitespacePathNormalizer;
use League\Glide\Urls\UrlBuilderFactory;
use Barryvdh\elFinderFlysystemDriver\Plugin\GetUrl;
use Barryvdh\elFinderFlysystemDriver\Cache\SessionStore;

/**
* elFinder driver for Flysytem (https://github.com/thephpleague/flysystem)
*
Expand Down Expand Up @@ -97,8 +99,6 @@ protected function init()
return $this->setError('A FilesystemOperator instance is required');
}

// $this->fs->addPlugin(new GetUrl());

$this->options['icon'] = $this->options['icon'] ?: (empty($this->options['rootCssClass'])? $this->getIcon() : '');
$this->root = $this->options['path'];

Expand Down Expand Up @@ -127,7 +127,8 @@ protected function init()
**/
protected function _dirname($path)
{
return dirname($path) ?: '/';
$dirname = dirname($path);
return $dirname === '.' ? '/' : $dirname;
}

/**
Expand All @@ -152,7 +153,7 @@ protected function _dirExists($path)
$dir = $this->_dirname($path);
$basename = basename($path);

foreach ($this->fs->listContents($dir) as $meta) {
foreach ($this->fs->listContents($dir)->toArray() as $meta) {
if ($meta && $meta['type'] !== 'file' && $meta['basename'] == $basename) {
return true;
}
Expand Down Expand Up @@ -223,7 +224,6 @@ protected function _stat($path)
$meta['size'] = $this->fs->fileSize($path);
}
} catch (\Exception $e) {
var_dump($e->getMessage());
return array();
}

Expand Down Expand Up @@ -269,10 +269,6 @@ protected function _stat($path)
}
}

// if (!isset($stat['url']) && $this->fs->getUrl()) {
// $stat['url'] = 1;
// }

return $stat;
}

Expand All @@ -286,14 +282,11 @@ protected function _stat($path)
**/
protected function _subdirs($path)
{
$contents = $this->fs->listContents($path);

$filter = function ($item) {
$contents = $this->fs->listContents($path)->filter(function ($item) {
return $item['type'] == 'dir';
};
});

$dirs = array_filter($contents, $filter);
return !empty($dirs);
return !empty($contents->toArray());
}

/**
Expand Down Expand Up @@ -325,7 +318,7 @@ protected function _scandir($path)
{
$paths = array();

foreach ($this->fs->listContents($path, false) as $object) {
foreach ($this->fs->listContents($path, false)->toArray() as $object) {
if ($object) {
$paths[] = $object['path'];
}
Expand Down Expand Up @@ -370,7 +363,9 @@ protected function _mkdir($path, $name)
{
$path = $this->_joinPath($path, $name);

if ($this->fs->createDir($path) === false) {
try {
$this->fs->createDirectory($path);
} catch (UnableToCreateDirectory $e) {
return false;
}

Expand All @@ -388,7 +383,9 @@ protected function _mkfile($path, $name)
{
$path = $this->_joinPath($path, $name);

if ($this->fs->write($path, '') === false) {
try {
$this->fs->write($path, '');
} catch (UnableToWriteFile $e) {
return false;
}

Expand All @@ -407,7 +404,9 @@ protected function _copy($source, $target, $name)
{
$path = $this->_joinPath($target, $name);

if ($this->fs->copy($source, $path) === false) {
try {
$this->fs->copy($source, $path);
} catch (UnableToCopyFile $e) {
return false;
}

Expand All @@ -427,7 +426,9 @@ protected function _move($source, $target, $name)
{
$path = $this->_joinPath($target, $name);

if ($this->fs->rename($source, $path) === false) {
try {
$this->fs->move($source, $path);
} catch (UnableToMoveFile $e) {
return false;
}

Expand All @@ -442,7 +443,13 @@ protected function _move($source, $target, $name)
**/
protected function _unlink($path)
{
return $this->fs->delete($path);
try {
$this->fs->delete($path);
} catch (UnableToDeleteFile $e) {
return false;
}

return true;
}

/**
Expand All @@ -453,7 +460,13 @@ protected function _unlink($path)
**/
protected function _rmdir($path)
{
return $this->fs->deleteDir($path);
try {
$this->fs->deleteDirectory($path);
} catch (UnableToDeleteDirectory $e) {
return false;
}

return true;
}

/**
Expand All @@ -480,7 +493,9 @@ protected function _save($fp, $dir, $name, $stat)
$config['visibility'] = $this->options['visibility'];
}

if ($this->fs->putStream($path, $fp, $config) === false) {
try {
$this->fs->writeStream($path, $fp, $config);
} catch (UnableToWriteFile $e) {
return false;
}

Expand All @@ -507,7 +522,12 @@ protected function _getContents($path)
**/
protected function _filePutContents($path, $content)
{
return $this->fs->put($path, $content);
try {
$this->fs->write($path, $content);
} catch (UnableToWriteFile $e) {
return false;
}
return true;
}

/*********************** paths/urls *************************/
Expand Down Expand Up @@ -764,11 +784,7 @@ public function getContentUrl($hash, $options = array())
return parent::getContentUrl($hash, $options);
}
$path = $this->decode($hash);
if (($res = $this->fs->getUrl($path)) || empty($options['temporary'])) {
return $res;
} else {
return parent::getContentUrl($hash, $options);
}
return parent::getContentUrl($hash, $options);
}
return $file['url'];
}
Expand Down
88 changes: 0 additions & 88 deletions src/Plugin/GetUrl.php

This file was deleted.

Loading

0 comments on commit c9fea39

Please sign in to comment.