Added Laravel project

This commit is contained in:
2017-09-17 00:35:10 +02:00
parent a3c19304d5
commit ecf605b8f5
6246 changed files with 682270 additions and 2 deletions

View File

@@ -0,0 +1 @@
_site

View File

@@ -0,0 +1 @@
flysystem.thephpleague.com

View File

@@ -0,0 +1,8 @@
# Path to project specific favicon.ico, leave blank to use default
favicon:
# Path to project specific apple-touch-icon-precomposed.png, leave blank to use default
apple_touch:
# Path to project logo
logo:

View File

@@ -0,0 +1,30 @@
Getting Started:
Introduction: '/'
Installation: '/installation/'
Integrations: '/integrations/'
Core concepts: '/core-concepts/'
The API: '/api/'
Mount Manager: '/mount-manager/'
Caching: '/caching/'
Recipes: '/recipes/'
Plugins: '/plugins/'
Upgrade to 1.0.0: '/upgrade-to-1.0.0/'
Creating an adapter: '/creating-an-adapter/'
Performance: '/performance/'
Adapters:
Local: '/adapter/local/'
Azure: '/adapter/azure/'
AWS S3 V2: '/adapter/aws-s3-v2/'
AWS S3 V3: '/adapter/aws-s3-v3/'
Copy.com: '/adapter/copy/'
Dropbox: '/adapter/dropbox/'
FTP: '/adapter/ftp/'
GridFS: '/adapter/gridfs/'
Memory: '/adapter/memory/'
Null / Test: '/adapter/null-test/'
Rackspace: '/adapter/rackspace/'
ReplicateAdapter: '/adapter/replicate/'
SFTP: '/adapter/sftp/'
WebDAV: '/adapter/webdav/'
PHPCR: '/adapter/phpcr/'
ZipArchive: '/adapter/zip-archive/'

View File

@@ -0,0 +1,4 @@
title: "Flysystem"
tagline: "Multiple Filesystems, One API"
description: "Filesystem abstraction package allowing you to use the same API for both local, remote and cloud filesystems."
google_analytics_tracking_id: "UA-46050814-3"

View File

@@ -0,0 +1,100 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
{% if page.url == '/' %}
<title>{{ site.data.project.title }} - {{ site.data.project.tagline }}</title>
{% else %}
<title>{{ page.title }} - {{ site.data.project.title }}</title>
{% endif %}
{% if site.data.project.description %}
<meta name="description" content="{{ site.data.project.description }}">
{% endif %}
{% if site.data.images.favicon %}
<link rel="icon" type="image/x-icon" href="{{ site.data.images.favicon }}" />
{% else %}
<link rel="icon" type="image/x-icon" href="//theme.thephpleague.com/img/favicon.ico" />
{% endif %}
{% if site.data.images.apple_touch %}
<link rel="apple-touch-icon-precomposed" href="{{ site.data.images.apple_touch }}">
{% else %}
<link rel="apple-touch-icon-precomposed" href="//theme.thephpleague.com/img/apple-touch-icon-precomposed.png">
{% endif %}
<link rel="stylesheet" href="//theme.thephpleague.com/css/all.css">
<base href="//flysystem.thephpleague.com{{ page.permalink }}">
</head>
<body>
<section class="all_packages">
<a href="//thephpleague.com/">
<img src="//theme.thephpleague.com/img/loep_logo.png" width="195" height="200" alt="The League of Extraordinary Packages">
</a>
<h2>Our Packages:</h2>
<ul>
<!-- Loaded via JavaScript -->
</ul>
</section>
<header>
<a class="logo" href="/">
{% if site.data.images.logo %}
<span class="icon">
<img src="{{ site.data.images.logo }}" width="50" height="40" alt="{{ site.data.project.title }} - {{ site.data.project.tagline }}">
</span>
{% endif %}
<span class="name">{{ site.data.project.title }}</span>
<span class="tagline">{{ site.data.project.tagline }}</span>
</a>
<a href="//thephpleague.com/" class="league">
Presented by The League of Extraordinary Packages
</a>
</header>
<input type="checkbox" id="menu">
<label for="menu" onclick>
<div class="closed">&#9776; Menu</div>
<div class="open">&#9776; Hide Menu</div>
</label>
<main>
<menu>
{% for section in site.data.menu %}
<h2>{{ section[0] }}</h2>
<ul>
{% for link in section[1] %}
<li {% if page.url == link[1] %}class="selected"{% endif %}>
<a href="{{ link[1] }}">{{ link[0] }}</a>
</li>
{% endfor %}
</ul>
{% endfor %}
</menu>
<article>
{{ content }}
</article>
</main>
<footer>
<span>&copy; Copyright <a href="//thephpleague.com">The League of Extraordinary Packages</a>.</span>
<span>Site design by <a href="//reinink.ca">Jonathan Reinink</a>.</span>
</footer>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//theme.thephpleague.com/js/scripts.js"></script>
<script src="//theme.thephpleague.com/js/prism.js"></script>
{% if site.data.project.google_analytics_tracking_id %}
<script>
(function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=
function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;
e=o.createElement(i);r=o.getElementsByTagName(i)[0];
e.src='//www.google-analytics.com/analytics.js';
r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));
ga('create','{{ site.data.project.google_analytics_tracking_id }}');ga('send','pageview');
</script>
{% endif %}
</body>
</html>

View File

@@ -0,0 +1,55 @@
---
layout: default
permalink: /adapter/aws-s3-v2/
title: Aws S3 Adapter V2
---
# Aws S3 Adapter - SDK V2
## Installation
~~~ bash
composer require league/flysystem-aws-s3-v2
~~~
## Usage
~~~ php
use Aws\S3\S3Client;
use League\Flysystem\AwsS3v2\AwsS3Adapter;
use League\Flysystem\Filesystem;
$client = S3Client::factory([
'key' => '[your key]',
'secret' => '[your secret]',
'region' => '[aws-region]',
]);
$adapter = new AwsS3Adapter($client, 'bucket-name', 'optional/path/prefix');
$filesystem = new Filesystem($adapter);
~~~
To enable [reduced redunancy storage](http://aws.amazon.com/s3/details/#RRS) set up your adapter like so:
~~~ php
$adapter = new AwsS3Adapter($client, 'bucket-name', 'optional/path/prefix', [
'StorageClass' => 'REDUCED_REDUNDANCY',
]);
~~~
### Compatible storage protocols
If you're using a storage service which implements the S3 protocols, you can set the `base_url` configuration option when constructing the client.
~~~ php
$client = S3Client::factory([
'base_url' => 'http://some.other.endpoint',
// ... other settings
]);
~~~
Known compliant storage providers are:
* [Google Cloud Storage](https://cloud.google.com/storage/docs/migrating#migration-simple)
* Know more? Please submit a PR!

View File

@@ -0,0 +1,32 @@
---
layout: default
permalink: /adapter/aws-s3-v3/
title: Aws S3 Adapter V3
---
# Aws S3 Adapter - SDK V3
## Installation
~~~ bash
composer require league/flysystem-aws-s3-v3
~~~
## Usage
~~~ php
use Aws\S3\S3Client;
use League\Flysystem\AwsS3v3\AwsS3Adapter;
use League\Flysystem\Filesystem;
$client = S3Client::factory([
'credentials' => [
'key' => 'your-key',
'secret' => 'your-secret',
],
'region' => 'your-region',
'version' => 'latest|version',
]);
$adapter = new AwsS3Adapter($client, 'your-bucket-name', 'optional/path/prefix');
~~~

View File

@@ -0,0 +1,31 @@
---
layout: default
permalink: /adapter/azure/
title: Azure Blob Storage
---
# Azure Blob Storage
## Installation
~~~ bash
composer require league/flysystem-azure
~~~
## Usage
~~~ php
use WindowsAzure\Common\ServicesBuilder;
use League\Flysystem\Filesystem;
use League\Flysystem\Azure\AzureAdapter;
$endpoint = sprintf(
'DefaultEndpointsProtocol=https;AccountName=%s;AccountKey=%s',
'account-name',
'api-key'
);
$blobRestProxy = ServicesBuilder::getInstance()->createBlobService($endpoint);
$filesystem = new Filesystem(new AzureAdapter($blobRestProxy, 'my-container'));
~~~

View File

@@ -0,0 +1,24 @@
---
layout: default
permalink: /adapter/copy/
title: Copy.com Adapter
---
# Copy.com Adapter
## Installation
~~~ bash
composer require league/flysystem-copy
~~~
## Usage
~~~ php
use Barracuda\Copy\API;
use League\Flysystem\Filesystem;
use League\Flysystem\Copy\CopyAdapter;
$client = new API($consumerKey, $consumerSecret, $accessToken, $tokenSecret);
$filesystem = new Filesystem(new CopyAdapter($client, 'optional/path/prefix'));
~~~

View File

@@ -0,0 +1,29 @@
---
layout: default
permalink: /adapter/dropbox/
title: Dropbox Adapter
---
# Dropbox Adapter
## Installation
~~~ bash
composer require spatie/flysystem-dropbox
~~~
## Usage
A token can be generated in the [App Console](https://www.dropbox.com/developers/apps) for any Dropbox API app. You'll find more info at [the Dropbox Developer Blog](https://blogs.dropbox.com/developers/2014/05/generate-an-access-token-for-your-own-account/).
~~~ php
use League\Flysystem\Filesystem;
use Spatie\Dropbox\Client;
use Spatie\FlysystemDropbox\DropboxAdapter;
$client = new Client($authorizationToken);
$adapter = new DropboxAdapter($client);
$filesystem = new Filesystem($adapter);
~~~

View File

@@ -0,0 +1,31 @@
---
layout: default
permalink: /adapter/ftp/
title: FTP Adapter
---
# FTP Adapter
## Installation
Comes with the main Flysystem package.
## Usage
~~~ php
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\Ftp as Adapter;
$filesystem = new Filesystem(new Adapter([
'host' => 'ftp.example.com',
'username' => 'username',
'password' => 'password',
/** optional config settings */
'port' => 21,
'root' => '/path/to/root',
'passive' => true,
'ssl' => true,
'timeout' => 30,
]));
~~~

View File

@@ -0,0 +1,26 @@
---
layout: default
permalink: /adapter/gridfs/
title: GridFS Adapter
---
# GridFS Adapter
## Installation
~~~ bash
composer require league/flysystem-gridfs
~~~
## Usage
~~~ php
use League\Flysystem\GridFS\GridFSAdapter;
use League\Flysystem\Filesystem;
$mongoClient = new MongoClient();
$gridFs = $mongoClient->selectDB('db_name')->getGridFS();
$adapter = new GridFSAdapter($gridFs);
$filesystem = new Filesystem($adapter);
~~~

View File

@@ -0,0 +1,62 @@
---
layout: default
permalink: /adapter/local/
title: Local Adapter
---
# Local Adapter
## Installation
Comes with the main Flysystem package.
## Usage
~~~ php
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\Local;
$adapter = new Local(__DIR__.'/path/to/root');
$filesystem = new Filesystem($adapter);
~~~
## Locks
By default this adapter uses a lock during writes
and updates. This behaviour can be altered using the
second constructor argument.
~~~ php
$adapter = new Local(__DIR__.'/path/to/too', 0);
~~~
## Links [added in 1.0.8]
The Local adapter doesn't support links, this violates
the root path constraint which is enforced throughout
Flysystem. By default, when links are encountered an
exception is thrown. This behaviour can be altered
using the third constructor argument.
~~~ php
// Skip links
$adapter = new Local(__DIR__.'/path/to/too', LOCK_EX, Local::SKIP_LINKS);
// Throw exceptions (default)
$adapter = new Local(__DIR__.'/path/to/too', LOCK_EX, Local::DISALLOW_LINKS);
~~~
## File and directory permission settings [added in 1.0.14]
~~~ php
$adapter = new Local(__DIR__.'/path/to/too', LOCK_EX, Local::DISALLOW_LINKS, [
'file' => [
'public' => 0744,
'private' => 0700,
],
'dir' => [
'public' => 0755,
'private' => 0700,
]
]);
~~~

View File

@@ -0,0 +1,24 @@
---
layout: default
permalink: /adapter/memory/
title: Memory Adapter
---
# Memory Adapter
This adapter keeps the filesystem completely in memory. This is useful when you need a filesystem, but don't want it persisted.
## Installation
~~~ bash
composer require league/flysystem-memory
~~~
## Usage
~~~ php
use League\Flysystem\Filesystem;
use League\Flysystem\Memory\MemoryAdapter;
$filesystem = new Filesystem(new MemoryAdapter());
~~~

View File

@@ -0,0 +1,20 @@
---
layout: default
permalink: /adapter/null-test/
title: Null Adapter
---
# Null Adapter
## Installation
Comes with the main Flysystem package.
## Usage
Acts like `/dev/null`
~~~ php
$adapter = new League\Flysystem\Adapter\NullAdapter;
$filesystem = new League\Flysystem\Filesystem($adapter);
~~~

View File

@@ -0,0 +1,48 @@
---
layout: default
permalink: /adapter/phpcr/
title: PHPCR Adapter
---
# PHPCR Adapter
This adapter works with any [PHPCR](http://phpcr.github.io) implementation.
Choose the one that fits your needs and add it to your project, or composer
will complain that you miss `phpcr/phpcr-implementation`. See
[this article](http://symfony.com/doc/master/cmf/cookbook/database/choosing_phpcr_implementation.html)
for more on choosing your implementation.
## Installation
Assuming you go with jackalope-doctrine-dbal, do:
~~~bash
composer require jackalope/jackalope-doctrine-dbal league/flysystem-phpcr
~~~
## Usage
Bootstrap your PHPCR implementation. If you chose jackalope-doctrine-dbal with sqlite,
this will look like this for example:
~~~php
use League\Flysystem\Filesystem;
use League\Flysystem\Phpcr\PhpcrAdapter;
use Jackalope\RepositoryFactoryDoctrineDBAL;
use Doctrine\DBAL\Driver\Connection;
use Doctrine\DBAL\DriverManager;
$connection = DriverManager::getConnection([
'driver' => 'pdo_sqlite',
'path' => '/path/to/sqlite.db',
]);
$factory = new RepositoryFactoryDoctrineDBAL();
$repository = $factory->getRepository([
'jackalope.doctrine_dbal_connection' => $connection,
]);
$session = $repository->login(new SimpleCredentials('', ''));
// this part looks the same regardless of your phpcr implementation.
$root = '/flysystem_tests';
$filesystem = new Filesystem(new PhpcrAdapter($session, $root));
~~~

View File

@@ -0,0 +1,32 @@
---
layout: default
permalink: /adapter/rackspace/
title: Rackspace Adapter
---
# Rackspace Adapter
## Installation
~~~ bash
composer require league/flysystem-rackspace
~~~
## Usage
~~~ php
use OpenCloud\OpenStack;
use OpenCloud\Rackspace;
use League\Flysystem\Filesystem;
use League\Flysystem\Rackspace\RackspaceAdapter;
$client = new OpenStack(Rackspace::UK_IDENTITY_ENDPOINT, [
'username' => ':username',
'password' => ':password',
]);
$store = $client->objectStoreService('cloudFiles', 'LON');
$container = $store->getContainer('flysystem');
$filesystem = new Filesystem(new RackspaceAdapter($container, 'optional/path/prefix'));
~~~

View File

@@ -0,0 +1,23 @@
---
layout: default
permalink: /adapter/replicate/
title: Replicate Adapter
---
# Replicate Adapter
## Installation
~~~ bash
composer require league/flysystem-replicate-adapter
~~~
## Usage
The `ReplicateAdapter` facilitates smooth transitions between adapters, allowing an application to stay functional and migrate its files from one adapter to another. The adapter takes two other adapters, a source and a replica. Every change is delegated to both adapters, while all the read operations are passed onto the source only.
~~~ php
$source = new League\Flysystem\AwsS3V3\AwsS3Adapter(...);
$replica = new League\Flysystem\Adapter\Local(...);
$adapter = new League\Flysystem\Replicate\ReplicateAdapter($source, $replica);
~~~

View File

@@ -0,0 +1,30 @@
---
layout: default
permalink: /adapter/sftp/
title: SFTP Adapter
---
# SFTP Adapter
## Installation
~~~ bash
composer require league/flysystem-sftp
~~~
## Usage
~~~ php
use League\Flysystem\Filesystem;
use League\Flysystem\Sftp\SftpAdapter;
$filesystem = new Filesystem(new SftpAdapter([
'host' => 'example.com',
'port' => 21,
'username' => 'username',
'password' => 'password',
'privateKey' => 'path/to/or/contents/of/privatekey',
'root' => '/path/to/root',
'timeout' => 10,
]));
~~~

View File

@@ -0,0 +1,21 @@
---
layout: default
permalink: /adapter/webdav/
title: WebDAV Adapter
---
# WebDAV Adapter
## Installation
~~~ bash
composer require league/flysystem-webdav
~~~
## Usage
~~~ php
$client = new Sabre\DAV\Client($settings);
$adapter = new League\Flysystem\WebDAV\WebDAVAdapter($client, 'optional/path/prefix');
$flysystem = new League\Flysystem\Filesystem($adapter);
~~~

View File

@@ -0,0 +1,30 @@
---
layout: default
permalink: /adapter/zip-archive/
title: ZipArchive Adapter
---
# ZipArchive Adapter
## Installation
~~~ bash
composer require league/flysystem-ziparchive
~~~
## Usage
~~~ php
use League\Flysystem\Filesystem;
use League\Flysystem\ZipArchive\ZipArchiveAdapter;
$filesystem = new Filesystem(new ZipArchiveAdapter(__DIR__.'/path/to/archive.zip'));
~~~
### Force Save
When creating a new zip file it will only be saved at the end of the PHP request because the ZipArchive library relies on an internal `__destruct` method to be called. You can force the saving of the zip file before the end of the request by calling the `close` method on the archive through the adapter.
~~~ php
$filesystem->getAdapter()->getArchive()->close();
~~~

View File

@@ -0,0 +1,231 @@
---
layout: default
permalink: /api/
title: API
---
# API
## General Usage
__Write Files__
~~~ php
$filesystem->write('path/to/file.txt', 'contents');
~~~
__Update Files__
~~~ php
$filesystem->update('path/to/file.txt', 'new contents');
~~~
__Write or Update Files__
~~~ php
$filesystem->put('path/to/file.txt', 'contents');
~~~
__Read Files__
~~~ php
$contents = $filesystem->read('path/to/file.txt');
~~~
__Check if a file exists__
~~~ php
$exists = $filesystem->has('path/to/file.txt');
~~~
__NOTE__: This only has consistent behaviour for files, not directories. Directories
are less important in Flysystem, they're created implicitly and often ignored because
not every adapter (filesystem type) supports directories.
__Delete Files__
~~~ php
$filesystem->delete('path/to/file.txt');
~~~
__Read and Delete__
~~~ php
$contents = $filesystem->readAndDelete('path/to/file.txt');
~~~
__Rename Files__
~~~ php
$filesystem->rename('filename.txt', 'newname.txt');
~~~
__Copy Files__
~~~ php
$filesystem->copy('filename.txt', 'duplicate.txt');
~~~
__Get Mimetypes__
~~~ php
$mimetype = $filesystem->getMimetype('path/to/file.txt');
~~~
__Get Timestamps__
~~~ php
$timestamp = $filesystem->getTimestamp('path/to/file.txt');
~~~
__Get File Sizes__
~~~ php
$size = $filesystem->getSize('path/to/file.txt');
~~~
__Create Directories__
~~~ php
$filesystem->createDir('path/to/nested/directory');
~~~
Directories are also made implicitly when writing to a deeper path
~~~ php
$filesystem->write('path/to/file.txt', 'contents');
~~~
__Delete Directories__
~~~ php
$filesystem->deleteDir('path/to/directory');
~~~
The above method will delete directories recursively
__NOTE__: All paths used by Flysystem API are relative to the adapter root directory.
__Manage Visibility__
Visibility is the abstraction of file permissions across multiple platforms. Visibility can be either public or private.
~~~ php
use League\Flysystem\AdapterInterface;
$filesystem->write('db.backup', $backup, [
'visibility' => AdapterInterface::VISIBILITY_PRIVATE
]);
// or simply
$filesystem->write('db.backup', $backup, ['visibility' => 'private']);
~~~
You can also change and check visibility of existing files
~~~ php
if ($filesystem->getVisibility('secret.txt') === 'private') {
$filesystem->setVisibility('secret.txt', 'public');
}
~~~
## Global visibility setting
You can set the visibility as a default, which prevents you from setting it all over the place.
~~~ php
$filesystem = new League\Flysystem\Filesystem($adapter, [
'visibility' => AdapterInterface::VISIBILITY_PRIVATE
]);
~~~
__List Contents__
~~~ php
$contents = $filemanager->listContents();
~~~
The result of a contents listing is a collection of arrays containing all the metadata the file manager knows at that time. By default you'll receive path info and file type. Additional info could be supplied by default depending on the adapter used.
Example:
~~~ php
foreach ($contents as $object) {
echo $object['basename'].' is located at'.$object['path'].' and is a '.$object['type'];
}
~~~
By default Flysystem lists the top directory non-recursively. You can supply a directory name and recursive boolean to get more precise results
~~~ php
$contents = $filesystem->listContents('some/dir', true);
~~~
__List paths__
~~~ php
$filesystem->addPlugin(new ListPaths());
$paths = $filesystem->listPaths();
foreach ($paths as $path) {
echo $path;
}
~~~
__List with ensured presence of specific metadata__
~~~ php
$listing = $filesystem->listWith(['mimetype', 'size', 'timestamp'], 'optional/path/to/dir', true);
foreach ($listing as $object) {
echo $object['path'].' has mimetype: '.$object['mimetype'];
}
~~~
__Get file into with explicit metadata__
~~~ php
$info = $filesystem->getWithMetadata('path/to/file.txt', ['timestamp', 'mimetype']);
echo $info['mimetype'];
echo $info['timestamp'];
~~~
__NOTE__: This requires the `League\Flysystem\Plugin\GetWithMetadata` plugin.
## Using streams for reads and writes
<p class="message-notice">
Some SDK's close streams after consuming them, therefore, before calling fclose on the resource, check if it's still valid using <code>is_resource</code>.
</p>
~~~ php
$stream = fopen('/path/to/database.backup', 'r+');
$filesystem->writeStream('backups/'.strftime('%G-%m-%d').'.backup', $stream);
// Using write you can also directly set the visibility
$filesystem->writeStream('backups/'.strftime('%G-%m-%d').'.backup', $stream, [
'visibility' => AdapterInterface::VISIBILITY_PRIVATE
]);
if (is_resource($stream)) {
fclose($stream);
}
// Or update a file with stream contents
$filesystem->updateStream('backups/'.strftime('%G-%m-%d').'.backup', $stream);
// Retrieve a read-stream
$stream = $filesystem->readStream('something/is/here.ext');
$contents = stream_get_contents($stream);
fclose($stream);
// Create or overwrite using a stream.
$putStream = tmpfile();
fwrite($putStream, $contents);
rewind($putStream);
$filesystem->putStream('somewhere/here.txt', $putStream);
if (is_resource($putStream)) {
fclose($putStream);
}
~~~

View File

@@ -0,0 +1,126 @@
---
layout: default
permalink: /caching/
title: Caching
---
# Caching
File system I/O is slow, so Flysystem uses cached file system meta-data to boost performance. When your application needs to scale you can also choose to use a (shared) persistent caching solution for this.
Or enable a per request caching (recommended).
## Installing the adapter cache decorator
~~~bash
composer require league/flysystem-cached-adapter
~~~
This package supplies an Adapter decorator which acts as a caching proxy.
The CachedAdapter (the decorator) caches anything but the file contents. This keeps the cache small enough to be beneficial and covers all the file system inspection operations.
## Memory Caching
The easiest way to boost the performance of Flysystem is to add Memory caching.
This type of caching will cache everything in the lifetime of the current process (cli-job or http-request).
Setting it up is easy:
~~~ php
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\Local as Adapter;
use League\Flysystem\Cached\CachedAdapter;
use League\Flysystem\Cached\Storage\Memory as CacheStore;
// Create the adapter
$localAdapter = new Local('/path/to/root');
// Create the cache store
$cacheStore = new CacheStore();
// Decorate the adapter
$adapter = new CachedAdapter($localAdapter, $cacheStore);
// And use that to create the file system
$filesystem = new Filesystem($adapter);
~~~
You can now use the file system as you would have before, but caching will be done for you on the fly.
## Persistent Caching
The following examples demonstrate how you can setup persistent meta-data caching:
## Predis Caching Setup
~~~ php
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\Local as Adapter;
use League\Flysystem\Cached\CachedAdapter;
use League\Flysystem\Cached\Storage\Predis as Cache;
$adapter = new CachedAdapter(new Adapter(__DIR__.'/path/to/root'), new Cache);
$filesystem = new Filesystem($adapter);
// Or supply a client
$client = new Predis\Client;
$adapter = new CachedAdapter(new Adapter(__DIR__.'/path/to/root'), new Cache($client));
$filesystem = new Filesystem($adapter);
~~~
## Memcached Caching Setup
~~~ php
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\Local as Adapter;
use League\Flysystem\Cached\CachedAdapter;
use League\Flysystem\Cached\Storage\Memcached as Cache;
$memcached = new Memcached;
$memcached->addServer('localhost', 11211);
$adapter = new CachedAdapter(
new Adapter(__DIR__.'/path/to/root'),
new Cache($memcached, 'storageKey', 300)
);
$filesystem = new Filesystem($adapter);
// Storage Key and expire time are optional
~~~
## Adapter Caching Setup
~~~ php
use Dropbox\Client;
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\Dropbox;
use League\Flysystem\Adapter\Local;
use League\Flysystem\Cached\CachedAdapter;
use League\Flysystem\Cached\Storage\Adapter;
$client = new Client('token', 'app');
$dropbox = new Dropbox($client, 'prefix');
$local = new Local('path');
$cache = new Adapter($local, 'file', 300);
$adapter = new CachedAdapter($dropbox, $cache);
$filesystem = new Filesystem($adapter);
~~~
## Stash Caching Setup
~~~ php
use Stash\Pool;
use League\Flysystem\Adapter\Local as Adapter;
use League\Flysystem\Cached\CachedAdapter;
use League\Flysystem\Cached\Storage\Stash as Cache;
$pool = new Pool();
// you can optionally pass a driver (recommended, default: in-memory driver)
$cache = new Cache($pool, 'storageKey', 300);
// Storage Key and expire time are optional
$adapter = new CachedAdapter(new Adapter(__DIR__.'/path/to/root'), $cache);
$filesystem = new Filesystem($adapter);
~~~
For list of drivers and configuration options check their [documentation](http://www.stashphp.com/Drivers.html).

View File

@@ -0,0 +1,55 @@
---
layout: default
permalink: /core-concepts/
title: Core Concepts
---
# Core Concepts
In order to better understand how and why Flysystem works
the way it does, several concepts require some explanation.
## Overview
* [Adapters](#adapters)
* [Relative Paths](#relative-paths)
* [Files first](#files-first)
## Adapters
The main entry point for the file system API is the
FilesystemInterface. When working with file systems, this is
the class you'll want to be talking to.
Flysystem works the way it does because of its use of the
adapter pattern. The inconsistencies of the different file
systems are eliminated in these adapters.
While adapters have a public interface (publicly accessible
methods), they should be considered __internal__.
## Relative Paths
Portability is a very important concept within Flysystem. In order
to roll out this aspect to the fullest, all paths in Flysystem are
relative. File system root paths, whether remote or local, are viewed
as endpoints. Because of this, file systems are movable independently.
This allows parts of the application file handling to move to other
storage types, while the majority is in a centralized location.
Like the storage type, root paths are an implementation detail. When
root paths are defined as configuration, the stability of your code
improves.
## Files First
Flysystem has a files first approach. Storage systems like AWS S3
are linear file systems, this means the path to a file is used as an
identifier, rather than a representation of all the directories it's
nested in.
This means directories are second class citizens. Because of this,
directories will be automatically created on file systems that require
them when writing files. Not only does this make handling writes a lot
easier, it also ensures a consistent behaviors across all file system
types.

View File

@@ -0,0 +1,59 @@
---
layout: default
permalink: /creating-an-adapter/
title: Creating an adapter
---
# Creating an adapter
If you want to address a file system, and there's no
adapter available, you'll need to create your own.
## What is an adapter
An adapter can be seen as a plug - it bridges the gap
between initially incompatible API's. The job of the adapter
is to translate requests into calls the file system
understands and re-format responses to comply with
the interface of the generic file system.
An adapter should __NEVER__ be used directly. It should
__ONLY__ be used to create a `League\Flysystem\FilesystemInterface`
implementation instance.
## The main interface to implement
An adapter is required to be an implementation of
`League\Flysystem\AdapterInterface`. This interface
dictates all the methods that need to be implemented.
The interface of an adapter is similar to the
`League\Flysystem\FilesystemInterface`, the method
names are the same, but the response is often different.
Responses from adapters are often arrays containing the
requested value. This is done because many calls to
file systems return more values than initially requested
by the client. In order to be able to optimize file system
handling, all metadata is returned. For instance, when a
`listContents` call not only returns the paths, but also
timestamps or other related metadata, this information is
not lost. This information is returned through metadata, allowing
caching decorators to pick it up, and store for further use.
### Response values
key | description | type
----------- | ------------------------ | -----------
type | `file` or `dir` | `string`
path | path to the file or dir | `string`
contents | file contents | `string`
stream | file contents | `resource`
visibility | `public` or `private` | `string`
timestamp | modified time | `integer`
## Sharing the wealth
Have you created an adapter? Be sure to let us know!
Either create an issue on the GitHub repository, or
send a PR adding a link to the README. Contributions
are always very welcome.

View File

@@ -0,0 +1,40 @@
---
layout: default
permalink: /
title: Introduction
---
# Introduction
<span style="float: left; margin: 0 10px 0 0;">
[![SensioLabsInsight](//insight.sensiolabs.com/projects/9820f1af-2fd0-4ab6-b42a-03e0c821e0af/big.png)](//insight.sensiolabs.com/projects/9820f1af-2fd0-4ab6-b42a-03e0c821e0af)
</span>
[![Author](//img.shields.io/badge/author-@frankdejonge-blue.svg?style=flat-square)](//twitter.com/frankdejonge)
[![Source Code](//img.shields.io/badge/source-thephpleague/flysystem-blue.svg?style=flat-square)](//github.com/thephpleague/flysystem)
[![Latest Version](//img.shields.io/github/tag/thephpleague/flysystem.svg?style=flat-square)](//github.com/thephpleague/flysystem/releases)
[![Software License](//img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](//github.com/thephpleague/flysystem/blob/master/LICENSE)
[![Build Status](//img.shields.io/travis/thephpleague/flysystem/master.svg?style=flat-square)](//travis-ci.org/thephpleague/flysystem)
[![Coverage Status](//img.shields.io/scrutinizer/coverage/g/thephpleague/flysystem.svg?style=flat-square)](//scrutinizer-ci.com/g/thephpleague/flysystem/code-structure)
[![Quality Score](//img.shields.io/scrutinizer/g/thephpleague/flysystem.svg?style=flat-square)](//scrutinizer-ci.com/g/thephpleague/flysystem)
[![Total Downloads](//img.shields.io/packagist/dt/league/flysystem.svg?style=flat-square)](//packagist.org/packages/league/flysystem)
![php 5.5+](//img.shields.io/badge/php-min%205.5-red.svg?style=flat-square)
Flysystem is a filesystem abstraction which allows you to easily swap out a local filesystem for a remote one. Technical debt is reduced as is the chance of vendor lock-in.
## Goals
* Have a generic API for handling common tasks across multiple file storage engines.
* Have consistent output which you can rely on.
* Integrate well with other packages/frameworks.
* Be cacheable.
* Emulate directories in systems that support none, like AwsS3.
* Support third party plugins.
* Make it easy to test your filesystem interactions.
* Support streams for big file handling
## Questions?
Flysystem was created by Frank de Jonge, follow him on Twitter for updates: [@frankdejonge](//twitter.com/frankdejonge).
Please submit issues on [Github](//github.com/thephpleague/flysystem).

View File

@@ -0,0 +1,32 @@
---
layout: default
permalink: /installation/
title: Installation
---
# Installation
Through Composer, obviously:
~~~ bash
composer require league/flysystem
~~~
You can also use Flysystem without using Composer by registering an autoloader function:
~~~ php
spl_autoload_register(function($class) {
$prefix = 'League\\Flysystem\\';
if ( ! substr($class, 0, 17) === $prefix) {
return;
}
$class = substr($class, strlen($prefix));
$location = __DIR__ . 'path/to/flysystem/src/' . str_replace('\\', '/', $class) . '.php';
if (is_file($location)) {
require_once($location);
}
});
~~~

View File

@@ -0,0 +1,21 @@
---
layout: default
permalink: /integrations/
title: Integrations
---
# Integrations
Want to get started quickly? Check out some of these bridging packages:
* [Laravel integration](https://github.com/GrahamCampbell/Laravel-Flysystem)
* [Symfony integration](https://github.com/1up-lab/OneupFlysystemBundle)
* [Zend Framework integration](https://github.com/bushbaby/BsbFlysystem)
* [CakePHP integration](https://github.com/WyriHaximus/FlyPie)
* [Silex integration](https://github.com/WyriHaximus/SliFly)
* [Yii 2 integration](https://github.com/creocoder/yii2-flysystem)
* [Backup manager](https://github.com/heybigname/backup-manager)
### Other integrations
Laravel 5 will ship with Flysystem as the underlying engine for local and remote file handling.

View File

@@ -0,0 +1,80 @@
---
layout: default
permalink: /mount-manager/
title: Mount Manager
---
# Mount Manager
Flysystem comes with an wrapper class to easily work with multiple file system instances
from a single object. The `League\Flysystem\MountManager` is an easy to use container allowing
you to simplify more complex cross file system interactions.
Setting up a Mount Manager is easy:
~~~ php
$ftp = new League\Flysystem\Filesystem($ftpAdapter);
$s3 = new League\Flysystem\Filesystem($s3Adapter);
$local = new League\Flysystem\Filesystem($localAdapter);
// Add them in the constructor
$manager = new League\Flysystem\MountManager([
'ftp' => $ftp,
's3' => $s3,
]);
// Or mount them later
$manager->mountFilesystem('local', $local);
~~~
Now we do all the file operations we'd normally do on a `Flysystem\Filesystem` instance.
~~~ php
// Read from FTP
$contents = $manager->read('ftp://some/file.txt');
// And write to local
$manager->write('local://put/it/here.txt', $contents);
~~~
This makes it easy to code up simple sync strategies.
~~~ php
$contents = $manager->listContents('local://uploads', true);
foreach ($contents as $entry) {
$update = false;
if ( ! $manager->has('storage://'.$entry['path'])) {
$update = true;
} elseif ($manager->getTimestamp('local://'.$entry['path']) > $manager->getTimestamp('storage://'.$entry['path'])) {
$update = true;
}
if ($update) {
$manager->put('storage://'.$entry['path'], $manager->read('local://'.$entry['path']));
}
}
~~~
## Specialized calls
### Copy
The copy method provided by the Mount Manager takes the origin of the file into account.
When it detects the source and destination are located on a different file systems it'll
use a streamed upload instead, transparently.
~~~ php
$mountManager->copy('local://some/file.ext', 'backup://storage/location.ext');
~~~
### Move
The `move` call is the multi-file system counterpart to `rename`. Where rename must be used on
the same file system, the `move` call provides the same conceptual behavior, but then on two
different file systems.
~~~ php
$mountManager->move('local://some/upload.jpeg', 'cdn://users/1/profile-picture.jpeg');
~~~

View File

@@ -0,0 +1,26 @@
---
layout: default
permalink: /performance/
title: API
---
# Performance
Flysystem aims to be as reliable as possible. In some cases this means doing extra
checks to make sure the outcome will be as expected. For some adapter this means Flysystem
will make extra calls to assert whether or not a file exists. This improves the reliability
but also impacts performance. You can opt out of this behaviour.
~~~ php
new League\Flysystem\Config;
new League\Flysystem\Filesystem;
$local = Filesystem($localAdapter, new Config([
'disable_asserts' => true,
]));
~~~
This will disable the asserts which happen before the following calls: write, writeStream, update,
updateStream, copy (2x), and delete.
This functionality is available since `1.0.26`.

View File

@@ -0,0 +1,46 @@
---
layout: default
permalink: /plugins/
title: Plugins
---
# Plugins
Need a feature which is not included in Flysystem's bag of tricks? Write a plugin!
~~~ php
use League\Flysystem\FilesystemInterface;
use League\Flysystem\PluginInterface;
class MaximusAwesomeness implements PluginInterface
{
protected $filesystem;
public function setFilesystem(FilesystemInterface $filesystem)
{
$this->filesystem = $filesystem;
}
public function getMethod()
{
return 'getDown';
}
public function handle($path = null)
{
$contents = $this->filesystem->read($path);
return sha1($contents);
}
}
~~~
Now we're ready to use the plugin
~~~ php
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter;
$filesystem = new Filesystem(new Adapter\Local(__DIR__.'/path/to/files/'));
$filesystem->addPlugin(new MaximusAwesomeness);
$sha1 = $filesystem->getDown('path/to/file');
~~~

View File

@@ -0,0 +1,99 @@
---
layout: default
permalink: /recipes/
title: Recipes
---
# Recipes
Flysystem Recipes describe common tasks and/or describe prefered ways to deal with
a problem. Please consider contributing a recipe. Contributions are very welcome!
## Handling uploads
### Plain PHP Upload
~~~ php
$stream = fopen($_FILES[$uploadname]['tmp_name'], 'r+');
$filesystem->writeStream('uploads/'.$_FILES[$uploadname]['name'], $stream);
fclose($stream);
~~~
### Symfony Upload
~~~ php
/** @var Symfony\Component\HttpFoundation\Request $request */
/** @var Symfony\Component\HttpFoundation\File\UploadedFile $file */
$file = $request->files->get($uploadname);
if ($file->isValid()) {
$stream = fopen($file->getRealPath(), 'r+');
$filesystem->writeStream('uploads/'.$file->getClientOriginalName(), $stream);
fclose($stream);
}
~~~
### Laravel 5 - DI
~~~ php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
class UploadController extends Controller {
/**
* Upload a file.
*
* @param Request $request
* @return Response
*/
public function store(Request $request, FilesystemInterface $filesystem)
{
$file = $request->file('upload');
$stream = fopen($file->getRealPath(), 'r+');
$filesystem->writeStream('uploads/'.$file->getClientOriginalName(), $stream);
fclose($stream);
}
}
~~~
### Laravel 4/5 - Static-Access Proxy
~~~ php
$file = Request::file($uploadname);
if ($file->isValid()) {
$stream = fopen($file->getRealPath(), 'r+');
$filesystem->writeStream('uploads/'.$file->getClientOriginalName(), $stream);
fclose($stream);
}
~~~
### Yii 2 Upload
~~~ php
<?php
namespace app\controllers;
use yii\web\Controller;
use yii\web\UploadedFile;
class FileController extends Controller
{
public function actionUpload()
{
$file = UploadedFile::getInstanceByName($uploadname);
if ($file->error === UPLOAD_ERR_OK) {
$stream = fopen($file->tempName, 'r+');
$filesystem->writeStream('uploads/'.$file->name, $stream);
fclose($stream);
}
}
}
~~~

View File

@@ -0,0 +1,66 @@
---
layout: default
permalink: /upgrade-to-1.0.0/
title: Upgrade to 1.0.0
---
# Upgrade to 1.0.0
While version 1.0.0 is largely backwards compatible from earlier versions in every
day usage, some parts require a different boostrapping.
## Relocated Adapters
In order to have better dependency management, and to remove some of the
version contstraints, some of the adapters have been moved out of the main
repository. These adapters are:
* [AwsS3: AWS SDK V2 Adapter](/adapter/aws-s3-v2/)
* [AwsS3V3: AWS SDK V3 Adapter](/adapter/aws-s3-v3/)
* [Dropbox](/adapter/dropbox/)
* [Rackspace](/adapter/rackspace/)
* [GridFS](/adapter/gridfs/)
* [Sftp](/adapter/sftp/)
* [WebDAV](/adapter/webdav/)
* [ZipArchive](/adapter/zip-archive/)
## Caching
Caching has been removed from the main Filesystem class and is now implemented
as an adapter decorator.
### Version 0.x
~~~ php
$filesystem = new Filesystem($adapter, $cacheAdapter);
~~~
### Version 1.0.0
Install the required adapter decorator:
~~~ bash
composer require league/flysystem-cached-adapter
~~~
And convert the bootstrapping to:
~~~ php
use League\Flysystem\Adapter\Local;
use League\Flysystem\Cached\CachedAdapter;
$decoratedAdapter = new CachedAdapter($adapter, $cacheAdapter);
$filesystem = new Filesystem($decoratedAdapter);
~~~
## Helper Methods
In order to clean up the Filsystem class, some helper functions have been moved to plugins.
* ListWith
* ListPaths
* ListFiles
* GetWithMetadata
* EmptyDir (new)