PHPNE Talk – Filesystem Abstraction

I gave a short talk at PHP North East on 18 February 2014 on PHP filesystem abstraction, with an emphasis on how it can be implemented through the Flysystem library.

It was my first talk, so I probably over-prepared the material, and then forgot half of what I wanted to mention, but the slides are here if you want to have a look. No video though:

The slides are constructed in reveal.js so use the cursor keys or the navigation icon to move around. Some slides branch off down an additional level of detail, so watch out for those. There are also speakers notes (press “s” to get those) and “Esc” will give you the sitemap of all the slides.

Edit: the source for the slides are on github. I intend to keep it a live document, so if you spot any errors, important omissions or things have substantially moved on, then that is where it will be fixed. Just raise a ticket a email me.

There is a demo linked at the end. You will need a Flickr login to access that, as it will use your Flickr account to view your contact’s photostreams. The demo uses a custom Flysystem adapter to construct a virtual directory structure over Flickr. Try drilling down to /contacts/other/{some-contact}/photostream/{some-photo} to see how it works.

A few questions came up in the talk:

  • Permissions – how is that handled? I would say, “broadly”. The permissions provided by Flysystem are very high level, and have a meaning that is largely up to interpretation (“public” and “private” – what do they even mean?). However, we did realise that using the FTP adapter, you can loop back onto the same server and access local files as a completely different user. Being an abstraction, the mechanism that performs the loopback is entirely hidden in layers away from anything the application has to deal with.
  • So I can just copy files from Dropbox to Flickr? Yep. The Flickr adapter is still in a demo state and only supports some reading of files (not writing). But once complete, copying a file from one remote store to another would be a single statement in the application.
  • Why Flysystem when PHP stream wrappers can do so much? That was a good question, and I’m still grappling with this one. I think Flysystem tries to be simple and to abstract the common functions that applications need to perform across file systems. It is not aiming (yet) to be all-comprehensive and cover everything you could possibly want to do with a file. It is object-orientated, which the PHP functions that handle streams are not, making it easier to incorporate into a modern application or framework, and to extend as needed. Google takes the stream wrapper approach, and offers its cloud file system access using that approach. I suspect in the end, Flysystem and PHP streams will be a lot more closely brought together and support each other well.

In all, I hope the presentation was interesting and informative. It was fun to do, and a big learning curve in many respects, but I would certainly love to do more. Next time I would include more colour and more cats. It needs more cats.


March 2014: I have recently come across the project. It is a file abstraction library that supports local files internally, and uses separate plugins as the adapters (FTP and SFTP are included). Just on a cursory glance, it seems to tackle many of the things I would love to have seen FlySystem implement. It implements files as object (not just as nested arrays), dives into stream wrappers, and supports an iterator interface so you can iterate through lines in a file, files in a directory, or even directories, without having to download the whole thing first. It also supports globbing (file wildcards). What it may lack is the more generic approiach to metadata – each adapter handles metadata very specific to the file storage, and is not pulled out as the lowest common shared metadata that FlySystem tries to do.

I have not tried it yet, but it looks pretty well thought through. I have also just realised that discordier/php-filesystem is a fork of filicious, and I am not sure why it died the death ten months ago. Perhaps time to revive it for new insights into abstracting your filesystem access?

No comments yet.

Leave a Reply