Code Monkey home page Code Monkey logo

flysystem's Introduction

League\Flysystem

Author Source Code Latest Version Software License Quality Assurance Total Downloads php 7.2+

About Flysystem

Flysystem is a file storage library for PHP. It provides one interface to interact with many types of filesystems. When you use Flysystem, you're not only protected from vendor lock-in, you'll also have a consistent experience for which ever storage is right for you.

Getting Started

Officially supported adapters

Third party Adapters

You can always create an adapter yourself.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Enjoy

Oh, and if you've come down this far, you might as well follow me on twitter.

flysystem's People

Contributors

ajgarlag avatar amenophis avatar awilum avatar dannyvdsluijs avatar driesvints avatar elgigi avatar erikn69 avatar frankdejonge avatar jkuma avatar jnoordsij avatar kbond avatar lcobucci avatar lctrs avatar madmaxinfinity avatar mattbartel avatar maxhelias avatar mmetayer avatar mtawil avatar mtorromeo avatar n1crack avatar nyholm avatar orklah avatar oskarstark avatar philintv avatar rwinzhang avatar simpod avatar slamdunk avatar tinect avatar warxcell avatar yoeriboven avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flysystem's Issues

Errors using DropBox adapter

When I run a listPaths with a foldername:
$filesystem = new Filesystem(new Adapter($client, '/dummyroot'));
$paths = $filesystem->listPaths("/test", true);
It results in:
PHP Catchable fatal error: Argument 2 passed to League\Flysystem\Cache\AbstractCache::storeContents() must be of the type array, boolean given, called in ./vendor/league/flysystem/src/Filesystem.php on line 382 and defined in ./vendor/league/flysystem/src/Cache/AbstractCache.php on line 66

If I manipulate the code and run it as
$filesystem = new Filesystem(new Adapter($client, ''));
$paths = $filesystem->listPaths("/", true);
It results in:
PHP Warning: substr_compare(): The start position cannot exceed initial string length in ./vendor/dropbox/dropbox-sdk/lib/Dropbox/Path.php on line 67
PHP Fatal error: Uncaught exception 'InvalidArgumentException' with message ''path'': bad path: must start with "/": ''' in ./vendor/dropbox/dropbox-sdk/lib/Dropbox/Path.php:141
Stack trace:
#0 ./vendor/dropbox/dropbox-sdk/lib/Dropbox/Client.php(737): Dropbox\Path::checkArg('path', '')
#1 ./vendor/league/flysystem/src/Adapter/Dropbox.php(222): Dropbox\Client->getMetadataWithChildren('')
#2 ./vendor/league/flysystem/src/Adapter/Dropbox.php(213): League\Flysystem\Adapter\Dropbox->retrieveListing('/', true)
#3 ./vendor/league/flysystem/src/Filesystem.php(380): League\Flysystem\Adapter\Dropbox->listContents('', true)
#4 ./vendor/league/flysystem/src/Filesystem.php(393): League\Flysystem\Filesystem->listContents('/', true)
#5 ./ in ./vendor/dropbox/dropbox-sdk/lib/Dropbox/Path.php on line 141

It more or less works if I do:
$filesystem = new Filesystem(new Adapter($client, '/'));
$paths = $filesystem->listPaths(".", true);

foreach ($paths as $path) {
echo "Found: ".$path;
}

Then the result is:
Found: ting Started.pdf
While it should not be 'ting' but 'Getting'.

Versions from composer:
"league/flysystem": "0.2.9",
"dropbox/dropbox-sdk": "1.1.3"

[Dropbox] listContents recursivly not returning subdirectory-name

Config:Adapter = Dropbox
Contents on Dropbox:
/fileA.pdf
/subfolder/fileB.pdf

situation: $paths = $filesystem->listContents("/", true);

result: $paths contains fileA, subfolder & fileB (so far so good)

Problem: when looking at fileB, there is nothing that indicates if fileB is at the same level as fileA of inside the folder 'subfolder'.
The returned array has a property 'dirname' that is always empty and basename & path are the same.
By looking at the wiki - I would suspect that basename contains the value as it contains at the moment but I expected path to contain either '/subfolder' or the complete path ('/subfolder/fileB.pdf').

Can set permissions on directories in the local filessytem adapter - and it's wrong

Setting folder permissions is fine if it is done right.

You can create a folder then set its visibility to public or private. Regardless of which you do, on linux at least, the permissions are not correct.

On Unix/Linux, the execute permission on directories determines if the contents of the directory can be read. This allows you to navigate to a directory from a shell. By setting the directory permissions to 0644 or 0600, the execute flags are reset, so the directory cannot be navigated into. The permissions for directories should be public 0755 or private 0700 (for Linux). But as for files, even private may need the group set, depending on how the system is set up.

public:
drw-r--r-- 2 apache  apache   4096 Feb 13 16:47 xxx
$ cd xxx
$ cd: xxx: Permission denied

private:
d--------- 2 apache  apache   4096 Feb 13 16:46 xxx

The permissions are fine if the directory does not have visibility set at all:

drwxr-xr-x 2 apache  apache   4096 Feb 13 16:49 xxx

getTimestamp and getSize returns whole metadata

I see that in case of a directory there is no size and timestamp, but I think that should be handled and not the whole meta array returned.

Do you have other reasons for this implementation?

Use file access mode 'r' instead of 'r+' for readStream

Hi,

the Local Adapter uses file access mode r+ in his readStream() method.

The naming suggesting that a source is used read only. But r+ allows reading and writing. In my current project I have only read access on the files, so following exception throws:

ContextErrorException: Warning: fopen(...): failed to open stream: Permission denied in .../vendor/league/flysystem/src/Adapter/Local.php line 157

The more suitable file access mode is r.

What's your opinion?

Zip does not support visibility settings

I am trying to zip an entire folder as per your suggested code. Although I want to include sub-directories too, for now, I am ignoring them.

PS: I am working on Windows XP with WAMP stack.

$local = new Filesystem( new Local(__DIR__.'/path/to/dir'));
$zip = new Filesystem( new Zip(__DIR__.'/path/to/archive.zip'));

$contents = $local->listContents('', true);

foreach ($contents as $info) {
    if ($info['type'] === 'dir') {
        continue;
    }

$zip->write($info['path'], $local->read($info['path']));
}

$zip = null;

The process failes when writing ".htaccess" file. I guess its due to that it does not have a filename. Please confirm.

The error that I get is:

Message:    Flysystem\Adapter\Zip does not support visibility settings.
File: C:\wamp\www\oxwall\ow_plugins\backup\classes\Flysystem\Adapter\AbstractAdapter.php
Line:   50

#0 C:\wamp\www\backup\classes\Flysystem\Adapter\Zip.php(61): Flysystem\Adapter\AbstractAdapter->setVisibility('.htaccess', 'public')
#1 C:\wamp\www\backup\classes\Flysystem\Filesystem.php(106): Flysystem\Adapter\Zip->write('.htaccess', 'Options +Follow...', 'public')
#2 C:\wamp\www\backup\controllers\admin.php(226): Flysystem\Filesystem->write('.htaccess', 'Options +Follow...')

Cache negative lookups

When a file doesn't exist that result is currently not cached, resulting in another poll from the adapter the next time a request comes in. Better would be if the cacher would store the result and setting an exists boolean on the object cache item array.

Empty Object for zip

I get empty Zip object after writing the content from local to zip adapter. No files are listed for the zip object where the source has files.

Is there any other way to make the object to save the file instead of using null.

Sorry again for all the trouble.

$local = new Filesystem(new Local("C:\wamp\www\oxwall\watermark"));
$zip = new Filesystem(new Zip($zipFilename));

$contents = $local->listContents();

foreach ($contents as $info) {
    if ($info['type'] === 'dir') {
        continue;
    }

    $zip->write($info['path'], $local->read($info['path']));
}
var_dump($zip->listContents());
$zip = null;

Move files from subdirectory

Hello,

i need to move many files on a sub direcotry i ahev this architecture 👍

Dir01
 |->sub-Dir02

i used this code :

$sourceSystem = new Filesystem(new Adapter('/Dir01'));

//listing files  from sub directory !
$contents = $sourceSystem->listContents('Dire02');

foreach ($contents as $object) {
           if ($object['type'] == "file"){// to an object file
                    $filesContents = $sourceSystem->read($object['basename']);
                    $cp1 = $fluxDestPath->write($object['basename'], $filesContents);
                               if ($cp1 == 1){
                                     $sourceSystem->delete( $object['basename']);
                            }
               }
}

and now way to copy the program line $filesContents = $sourceSystem->read($object['basename']); can't find the sourceFiles ?

can u says me why please

thanks a lot

Flysystem API

I just now tried to use, after you have added support for webdav, thanks.
But to be honest, it is impossible to use.
I think your wrapper should extends DirectoryIterator, and do not return bool or something other. It's should throws exception or return something instead.

Support append for adapters that support it

I may just be missing this completely, but I cannot see a way to append to an existing file. Operations only allow files to be overwritten completely.

Some storage locations would not support appending (e.g. FTP) but some would (e.g. local). Being able to append it vital for being able to write to log files.

Just like different stream wrappers have different levels of support for some operations (e.g. some may support seek, some may not) is this something that would be acceptable to the adapters?

Adapter Factory

Are there any plans to implement a factory of some sort to create adapters based on configuration files? Thanks, Tom.

Dropbox Issue

I am getting an error when i use dropbox more than once for any operation.

[root@glados site]# php artisan tinker
[1] > Flysystem::put('123', '123');
// true
[2] > Flysystem::put('123', '123');
PHP Fatal error:  Uncaught exception 'Dropbox\Exception_NetworkIO' with message 'Error executing HTTP request: SSL connect error' in /var/www/retejo/cms/site/vendor/dropbox/dropbox-sdk/lib/Dropbox/Curl.php:69
Stack trace:
#0 /var/www/retejo/cms/site/vendor/dropbox/dropbox-sdk/lib/Dropbox/Client.php(523): Dropbox\Curl->exec()
#1 /var/www/retejo/cms/site/vendor/dropbox/dropbox-sdk/lib/Dropbox/Client.php(336): Dropbox\Client->_uploadFile('/123', Object(Dropbox\WriteMode), Object(Closure))
#2 /var/www/retejo/cms/site/vendor/league/flysystem/src/League/Flysystem/Adapter/Dropbox.php(115): Dropbox\Client->uploadFileFromString('/123', Object(Dropbox\WriteMode), '123')
#3 /var/www/retejo/cms/site/vendor/league/flysystem/src/League/Flysystem/Adapter/Dropbox.php(90): League\Flysystem\Adapter\Dropbox->upload('123', '123', Object(Dropbox\WriteMode))
#4 /var/www/retejo/cms/site/vendor/league/flysystem/src/League/Flysystem/Filesystem.php(244): League\Flysystem\Adapter\Dropbox->update('123', '123')
#5 /var/www/retejo/cms/site/vendor/league/fl in /var/www/retejo/cms/site/vendor/dropbox/dropbox-sdk/lib/Dropbox/Curl.php on line 69
[3] > Flysystem::put('1234', '1234');
PHP Fatal error:  Uncaught exception 'Dropbox\Exception_NetworkIO' with message 'Error executing HTTP request: SSL connect error' in /var/www/retejo/cms/site/vendor/dropbox/dropbox-sdk/lib/Dropbox/Curl.php:69
Stack trace:
#0 /var/www/retejo/cms/site/vendor/dropbox/dropbox-sdk/lib/Dropbox/RequestUtil.php(223): Dropbox\Curl->exec()
#1 /var/www/retejo/cms/site/vendor/dropbox/dropbox-sdk/lib/Dropbox/Client.php(1379): Dropbox\RequestUtil::doGet('DSMG/1.0', 'f9i-safpkG8AAAA...', NULL, 'api.dropbox.com', '1/metadata/auto...', Array)
#2 /var/www/retejo/cms/site/vendor/dropbox/dropbox-sdk/lib/Dropbox/Client.php(786): Dropbox\Client->doGet('api.dropbox.com', '1/metadata/auto...', Array)
#3 /var/www/retejo/cms/site/vendor/dropbox/dropbox-sdk/lib/Dropbox/Client.php(745): Dropbox\Client->_getMetadata('/1234', Array)
#4 /var/www/retejo/cms/site/vendor/league/flysystem/src/League/Flysystem/Adapter/Dropbox.php(187): Dropbox\Client->getMetadata('/1234')
#5 /var/www/retejo/cms/site/vendor/league/flysystem/src/League/Flysystem/Adapter/Dropbox.ph in /var/www/retejo/cms/site/vendor/dropbox/dropbox-sdk/lib/Dropbox/Curl.php on line 69
[4] >

See https://github.com/dropbox/dropbox-sdk-php/issues/12.

Suggested Adaptors

I have been following this repo and I am very much impressed with this library. A real good job. Thanks for your time on this.

I was thinking about the support for Google Drive and Sky drive adapters. Hope it makes sense in this era of cloud computing.

.ltrim on file

Flysystem / src / League / Flysystem / Adapter / Sftp.php

I was reading through the code. Not sure is it intensional or not
on line 19.

.ltrim

//Best

Mime type for stream uploads

I noticed that my stream uploads for objects like jpg files are getting force-downloaded in the browser and it seems the mime type for streams is not being set. Is there a way to specify the mime type manually, or detect it from the stream? This is for Amazon S3.

Thanks.

write/update

Is there a reason why you differentiate between update and write calls?

I've a use-case where (oh wonder xD) I just want to write a file. If it is not present, create it and if present, overwrite it.

That would result in 5 lines of code with the current implementation:

if ($fs->has($path)) {
    $fs->update($path, $content);
} else {
    $fs->write($path, $content);
}

Wouldn't it be better if write overwrites simply if the file exists? I mean write is usually known as a simple write command as in other contexts. Means: create it or overwrite. file_set_contents does it, > in bash too etc.

My suggestion would be to rename the current implementation of write to create and make a write method that overwrites or creates. With the current behavior of write it would make more sense this way.

What do you think?

Ftp commands warning

I found a new issue related to ftp directories, but it also affects other ftp_* functions.

Eg. ftp_mkdir not just returns true or false, but also throws a PHP Warning. Could it be supressed?

I HATE PHP Warnings. 😄

Usage without Composer

I am trying to incorporate Flysystem in one of the open-source script which does not support Composer. How can I use your excellent script in that script?

I was expecting I could just include a .php file and start working.

README.md

Trough Composer should be Through Composer
(I feel silly for even making tickets for trivial stuff like this, but it only takes a second to post anyway)

Archive files connector

Does anybody tries to make connector for archive files (at leas for ZIP)? I mean to work with archive as a file system.

AwsS3 adapter dosen't support $dirname nor $recursive in `listContent()`

This is the code, it dosen't have any TODO or not supported information/error/exception:

    /**
     * List contents of a directory
     *
     * @param   string  $dirname
     * @param   bool    $recursive
     * @return  array   directory contents
     */
    public function listContents($dirname = '', $recursive = false)
    {
        $result = $this->client->listObjects(array(
            'Bucket' => $this->bucket,
        ))->getAll(array('Contents'));

        $contents = isset($result['Contents']) ? $result['Contents'] : array();
        $result = array_map(array($this, 'normalizeObject'), $contents);

        return Util::emulateDirectories($result);
    }

Inconcistent error reporting in Filesystem methods (?)

Why methods of Filesystem like read() and getTimestamp() are both able to throw an exception and return FALSE?

Filesystem class example:

    public function read($path)
    {
        $path = Util::normalizePath($path);
        $this->assertPresent($path);
        if ($contents = $this->cache->read($path)) {
            return $contents;
        }
        if ( ! $object = $this->adapter->read($path)) {
            return false;
        }
        $this->cache->updateObject($path, $object, true);
        return $object['contents'];
    }

I cannot relay on an output like that, it makes my error checking horribly complicated. Why those methods are not throwing exception on adapter error? Why adapters are not throwing exceptions on errors but they are just returning meaningful FALSE? I need to write, for example:

try {
  $content = $fileSystem->read($pathname);
  if ($content === false) {
    throw new \Exception("Unkown adapter error! Don't ask me what happened...");
  }
  // processing $content
  return true;
} catch (FileNotFoundException $e) {
  // file-system error
} catch (Exception $e) {
  // my thrown error
}

Why there is no "AdapterError" exception? What is the reason after design like that? BTW Docblocks misses information about returning FALSE, I've fixed it at least in read() but I see it needs to be fixed also in getTimestamp().

InvalidArgumentException thrown when i try to use mountmanager with s3

[09-Dec-2013 15:29:12 Europe/London] PHP Fatal error: Uncaught exception 'InvalidArgumentException' with message 'No prefix detected in for path: s3://x.jpg' in /Applications/MAMP/htdocs/post_s3/vendor/frenkynet/flysystem/src/Flysystem/MountManager.php:94
Stack trace:
I might not be using this correctly but I tried adding a prefix and tried it without and getting the following error

/Applications/MAMP/htdocs/post_s3/vendor/frenkynet/flysystem/src/Flysystem/MountManager.php(112): Flysystem\MountManager->filterPrefix(Array)
#1 /Applications/MAMP/htdocs/post_s3/application/controllers/ftptos3.php(64): Flysystem\MountManager->__call('write', Array)
#2 /Applications/MAMP/htdocs/post_s3/application/controllers/ftptos3.php(64): Flysystem\MountManager->write('s3://x...', '', 'public')
#3 [internal function]: ftptos3->test()
#4 /Applications/MAMP/htdocs/post_s3/system/core/CodeIgniter.php(359): call_user_func_array(Array, Array)
#5 /Applications/MAMP/htdocs/post_s3/index.php(203): require_once('/Applications/M...')
#6 {main}
  thrown in /Applications/MAMP/htdocs/post_s3/vendor/frenkynet/flysystem/src/Flysystem/MountManager.php on line 94

heres my code assuming the libraries are loaded

$ftp = new Flysystem\Filesystem(new ftpAdapter(array(
    'host' => 'xxx',
    'username' => 'xxx',
    'password' => 'xxx',


    'port' => 21,
    'root' => '/domains/public_html/img_uploads/',
    'passive' => true,
    'timeout' => 30,
)));

$client = S3Client::factory(array(
    'key'    => 'x',
    'secret' => 'x',
));     

$s3 = new Flysystem\Filesystem(new awsAdapter($client, 'upd8r-cdn','/imgs'));

$manager = new Flysystem\MountManager(array(
    'ftp' => $ftp,
    's3' => $s3,
));

$contents = $manager->read('ftp://x.jpg');
$manager->write('s3://x.jpg', $contents,AdapterInterface::VISIBILITY_PUBLIC);

Private file permissions on local adapter is wrong

Sorry - don't want to do another pull request until I have a test system up and running, but this should be a simple one.

The local file adapter uses 0000 as the private file permissions. That creates a file that looks like this:

---------- 1 apache apache 5 Feb 13 16:26 jj.txt

Whoops - created the file and now can't even read it. Should be 0600.

Other permissions may be needed to determine public/private, depending upon what the PHP module is, so maybe they should not be static settings, for the local file adapter at least.

Code Coverage Is Broken

The code coverage is only showing up for those classes that have any tests. Those classes with no tests are not included in the report. For example, the webdav adapter has no tests...

add line to CSV

Hello,

well i m want use FLystem to add information on a csv files, but the files is not update.

i use this :
$contentsCsv = "Info1;info2;";
$destiny->put('files.csv', $contentsCsv);
$contentsCsv = "Info1;info2;";
$destiny->put('files.csv', $contentsCsv);

but on résulte i have this :

Info1;info2;Info1;info2;

so how add a return line like a real csv files.

thanks

Uploading a large file

Is there a recommended way of sending a large file without using file_get_contents() first, ie by providing a path?

Creating Zip File from Folder

How would I zip an entire folder and make it available as a zip file? I have couple of views on the documents and I am not able to get any info on zipping the files.

Please let me know if I am missing any thing on this.

[Dropbox] listContents not working correctly

Since the latest version listContents isn't working correctly anymore.

  1. If I try to request a recursive list, I only get items from the requested folder (not from subfolders)
  2. The returned names are incorrect (the first char is missing)
  3. Passing an empty prefix to the adapter-constructor and next invoking listContents("/", true) results in a stacktrace that indicates that the given path is invalid (as it becomes empty in the call made by listContents to the adapter)

So I'm afraid that the last fix broke something.

i have FileName on the path

Hello i used this code 👍
$sourceSystem = new Filesystem(new Adapter('/src/01/DD'));
foreach ($contents as $object) {//permet d'itérer les différents fichier du dossier
echo "\n";
var_dump($object);
echo "\n";
}

and i have the result 👍

array(8) {
["dirname"]=>
string(0) ""
["basename"]=>
string(10) "file01.txt"
["extension"]=>
string(3) "txt"
["filename"]=>
string(10) " string(75) "file01.txt""
["path"]=>
string(10) " string(75) "file01.txt""
["type"]=>
string(4) "file"
["timestamp"]=>
int(1392040200)
["size"]=>
int(15486)
}

so why i have the filename on th path variable ?

how i can get the path of the files please ?

Root directory isn't actually a root

If I configure a path as the root of my adapter I would expect it to work as the root and not allow access down from there. Otherwise it's really more of a "home" directory, or "initial" directory. When I hand it a path with multiple "../../" in there, it will gladly allow me outside of the root.
(note: this is based on the Local adapter as I haven't used any of the others yet)

A possible fix might be something along these lines in the prefix() method:

<?php
    protected function prefix($path)
    {
        if (empty($path)) {
            return $this->root;
        }

        $path = realpath($this->root.Util::normalizePath($path, DIRECTORY_SEPARATOR));
        if (strpos($path, $this->root) !== 0) {
            throw new \OutOfBoundsException('You cannot go outside the root directory.');
        }

        return $path;
    }

This is an issue with possible security concerns as well. Even though the dev using this lib still should do his own input filtering, the library shouldn't allow paths below something called a 'root' as an extra layer of security. Or the setting should be renamed to something that doesn't imply it's the lowest the adapter will go.

Download/Upload-Progress

When working with mid-size or large files it's actual always required to have a kind of progress information.
Especially, when the server has not a big bandwidth or the connection is pretty busy and you want to inform your client/user with a progress-bar while uploading/downloading.

What do you think about providing such a API? I don't know whether all adapters are able to support that or if we have to emulate it somehow.

I guess a event-based system would be a good method to achieve that.

Example:

$fs = new Filesystem();
$fs->on('upload', function($bytes, $totalBytes, $path){
    echo sprintf("%s: %d of %d\n", $path, $bytes, $totalBytes);
});

$fs->write('bla', 'hossa');

What do you think?

WebDav

What about webdav support? Many cloud storages supports this protocol

No path available for listContents() result

The listContents() function for Local adaptor does not return the path value of the filename. We have just the file name.

array
(
    [dirname] => 
    [basename] => credits.zip
    [extension] => zip
    [filename] => credits
    [path] => credits.zip // No Path
    [type] => file
    [timestamp] => 1351350466
    [size] => 30001
)

Type: Array

Consistent error handling

This has become apparent as a part of the discussion here:

https://groups.google.com/forum/#!topic/php-fig/T4mtQc6qyaE

If Flysystem is used in a framework that catches errors and warnings, often converting them into exceptions, then the error handling within Flysystem will be bypassed. So if you try to open a file in a directory that can't be accessed, for example, you will expect to be given a "false" when you try to read or write that file. However, if you use a library like Asplode, you don't get to see the result, and instead are thrown into the exception handling system.

You can, of course, try...catch the exception, but for a low-level library that could sit under a huge stack of other libraries, it needs to act on errors consistently.

You could decide that it would be better to return exceptions now, so anyone using FlySystem should code to expect exceptions, then a library like Asplode won't break anything using your library.

Or maybe you want to always return false and hide any exceptions, so you need to (@) suppress PHP warnings on the file operations and handle just return codes.

Related to this, the following will be an error:

$fs = new Filesystem(new Adapter('/');

However, $fs will still be returned as a Filesystem object, and you have no idea it has failed. But enable Asplode and an exception is raised, which can be caught. That is leading me down the route of expecting exceptions to be raised by FlySystem, since some errors can happen several levels deep and get ignored (like in new... above) when the exceptional program flow should really be dealt with immediately.

Just on the above example, maybe if an error happens in any call to fopen() or likewise, and you decide NOT to raise an exception, then perhaps FlySystem should record the error and its message in the filesystem object. That way after $fs is returned above, there is a further check that can be done to make sure it actually worked, and then to get the error details for context and logging.

Hope that makes sense.

Issue with Zip files containing non-ASCII names

Testing the Zip adapter I'm opening a backup.zip with:

  1. A directory with English and non-ASCII characters (names Arabic عربي)
  2. A file named عربي

I'm getting:
Notice: Undefined index: path in /home/ossama/www/fly/vendor/frenkynet/flysystem/src/Flysystem/Cache/AbstractCache.php on line 71
Notice: Undefined index: dirname in /home/ossama/www/fly/vendor/frenkynet/flysystem/src/Flysystem/Util.php on line 18

The folder with mixed letters is read fine, but not the non-ASCII file name
You can find the test file here:
http://www.ossama.me/backup.zip

Move package to the League.

The package will get an awesome new home at @php-loep. Allowing it to get broader support and a slick website for docs.

local adaptor method writeStream doesn't create directories

I'm not sure if there is a reason for this but write runs mkdir if the directory the file is being written to doesn't exist but this doesn't happen with writeStream. I'm happy to make a patch but just wanted to know if there is a reason for this or if it is an oversight?

Awesome library 👍

Support for chunked data sources

I may just be overlooking something or misunderstanding how it works, but would streaming out files or listings that are fetched in chunks be possible?

The result would be to ask FlySystem for, say, a directory listing through a stream or maybe an iterator interface, and fetch the listing one row at a time. For example, a directory listing may be a list of files for a user (e.g. abstracted to /users/781762@768/photos/all). There may be more photos than can be fetched in one go.

The Flickr API would deliver the list in a number of "pages". The calling application does not have to know about the pages - it just fetches directory listings one entry at a time. What FlySystem would need to do, is cache each page as it is fetched, keep track of what page it is one, and iterate through the photos.

I have done a similar thing for a SugarCRM API, and it seems to work okay.

What I am wondering is whether there is room for this kind of approach in FlySystem? You can fetch files and directory listings in monolithic chunks. You can stream a file content out (though that file will be fetched from the remote source in its entirety and stuffed into a temporary file for streaming out). Now supposing I need to read a half-gigabyte remote file or get a directory listing of 100,000 images (yes, I've needed to do that, unfortunately) - where would you say an interface that lets me stream it out to a file without loading it all into memory, or read one record at a time fit in?

Rackspace Adapter: 404 Not Found Error

I have started running into an error while using the Rackspace Adapter. When I try to upload a file that has never been uploaded before, I get a OpenCloud\ObjectStore\Exception\ObjectNotFoundException with the following message

0a61cc75-cb78-4a05-a24b-5f9eee7a12a3.jpg could not be found. The API returned this HTTP response: HTTP/1.1 404 Not Found Content-Length: 70 Content-Type: text/html; charset=UTF-8 X-Trans-Id: tx7508b2797f4342b48269a-005310edbaiad3 Date: Fri, 28 Feb 2014 20:12:42 GMT <html><h1>Not Found</h1><p>The resource could not be found.</p></html>

Which in turn stops the upload all together. It looks like a 404 being returned was expected, and is used to return false for the has function, but for some reason this exception isnt being caught and it bubbles all the way up to Laravels general Exception catcher I have.

When a directory listing is requested for a directory which doesn't exist an catchable fatal error is thrown with Ftp

PHP error message is as follows.

<b>Catchable fatal error</b>:  Argument 1 passed to League\Flysystem\Adapter\AbstractFtpAdapter::normalizeListing() must be of the type array, boolean given, called in vendor/league/flysystem/src/Adapter/Ftp.php on line 293 and defined in <b>vendor/league/flysystem/src/Adapter/AbstractFtpAdapter.php</b> on line <b>206</b><br />

A \LogicException should be thrown when no directory listing could be retrieved.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.