evernote/evernote-cloud-sdk-php — pull request #2 by BradEstey (2014-10-22 00:24:06+00:00)
Title: Pass object that implements FileInterface to Resource model.

I've changed the following things.

- The `Resource` model can now accept an object that implements the `FileInterface` instead of just path and mime type.
- The `$mime_type` parameter in the `Resource` model is now optional.
- Added a `findMimeType()` method to `File` class. The `$mime_type` parameter on the `File` class is also optional now.
- Moved local file system related actions to the `File` class into a `getContent()` method.
- Added `getContent()` method to the `FileInterface`.

This decouples the `Resource` model from the file system and allows for adapters to be written to pull in files from services like S3 or Dropbox.

Here's what a [Flysystem](http://flysystem.thephpleague.com) adapter could look like:

``` php

namespace Evernote\File\Adapters;

use Evernote\File\FileInterface;
use League\Flysystem\FilesystemInterface;

class FlysystemAdapter implements FileInterface
{
/**
* Filesystem.
* @var League\Flysystem\FilesystemInterface
*/
protected $filesystem;

/**
* File path.
* @var string
*/
protected $path;

/**
* FlySystem File Class.
*
* @param string $path
* @param League\Flysystem\FilesystemInterface $filesystem
* @return void
*/
public function __construct($path, FilesystemInterface $filesystem) {
$this->path = $path;
$this->filesystem = $filesystem;
}

/**
* Get the filename.
*
* @return string
*/
public function getFilename()
{
$path = explode(DIRECTORY_SEPARATOR, $this->path);
return array_pop($path);
}

/**
* Get the file's content.
*
* @return string
*/
public function getContent()
{
return $this->filesystem->read($this->path);
}

/**
* Get the file's mimetype.
*
* @return string
*/
public function getMimetype()
{
return $this->filesystem->getMimetype($this->path);
}
}

```