12. NESTED FILESYSTEMS
Are the most common
Have directories
which have files and more directories
... which have more files and directories
... which have more files and directories.
We're really used to this structure.
13. LINEAR FILESYSTEM
Are like key/value stores
do have files, of course
require a different approach
don't really have directories.
21. SOME REASONS WHY:
We want to scale (horizontally).
... so, we want stateless apps.
We don't have to serve files ourselves.
Share files across multiple application.
We want to enable a nice experience to our users which was
not possible otherwise.
22. SOME CONSEQUENCES
We can't use built-in PHP function anymore.
We'll have to start using API's
We'll have to depend on third party code.
37. FLYSYSTEM AND STREAMS:
$resource = $dropbox->readStream($location);
$awsS3->writeStream($destination, $resource);
38. FLYSYSTEM IS A GATEWAY DRUG FOR...
... DRY code
... centralized problem domain handling
... easily testable FS interactions
... reduced technical dept
... lower development costs
... having less to learn.
40. DEPENDING ON FLYSYSTEM
class Author
{
public function __construct(FilesystemInterface $filesystem)
{
$this->filesystem = $filesystem;
}
public function getBio()
{
return $this->filesystem->read($this->getBioLocation());
}
}
41. TESTING THE DEPENDANT CODE
public function testGetBio()
{
$expected = 'Some Bio';
$fsMock = Mockery::mock('LeagueFlysystemFilesystemInterface');
$fsMock->shouldReceive('read')
->with('james-doe-bio.txt')
->andReturn($expected);
$autor = new Author($fsMock);
$this->assertEquals($expected, $author->getBio());
}
BONUS: this makes tests run super fast because you don't have
to wait for blocking filesystem operations (slow).
42. IMPROVED STABILITY OF DEPENDANT CODE
Class should have one reason to change
... changing filesystems isn't one of them.
Most code shouldn't have to care where files are stored.
Flysystem enables classes to be unaware of this.
43. OPENING UP TO NEW POSSIBILITIES
Using Dropbox for uploads
Ease development by deferring filesystem choice.
Painless pivots during application lifecycle.
Nice to build a package on.