KnpGaufretteBundle/README.md

128 lines
3.6 KiB
Markdown
Raw Normal View History

2011-05-08 21:04:37 +00:00
Gaufrette Bundle
================
2016-01-16 00:12:11 +00:00
[![Build Status](https://travis-ci.org/KnpLabs/KnpGaufretteBundle.svg?branch=master)](https://travis-ci.org/KnpLabs/KnpGaufretteBundle)
2011-05-08 21:04:37 +00:00
Provides a [Gaufrette][gaufrette-homepage] integration for your Symfony projects.
2011-05-13 15:49:11 +00:00
About Gaufrette
2017-01-16 13:00:11 +00:00
===============
2011-05-13 15:49:11 +00:00
Gaufrette is a PHP 5.3+ library providing a filesystem abstraction layer.
This abstraction layer allows you to develop applications without needing to know where all their media files will be stored or how.
2011-05-13 15:49:11 +00:00
Documentation is available the [official page of Gaufrette][gaufrette-homepage].
2011-05-08 21:04:37 +00:00
Installation
2017-01-16 13:00:11 +00:00
============
2011-05-08 21:04:37 +00:00
2011-06-18 18:49:55 +00:00
## Prerequisites
2011-05-08 21:04:37 +00:00
As this bundle is an integration for Symfony of the [Gaufrette][gaufrette-homepage] library, it requires you to first install [Gaufrette][gaufrette-homepage] in a Symfony project.
## With composer
2011-05-08 21:04:37 +00:00
This bundle can be installed using [composer](http://getcomposer.org) by adding the following in the `require` section of your `composer.json` file:
2011-05-08 21:04:37 +00:00
``` json
"require": {
...
2016-01-16 01:46:04 +00:00
"knplabs/knp-gaufrette-bundle": "~0.3"
},
```
2011-05-08 21:04:37 +00:00
## Register the bundle
You must register the bundle in your kernel:
``` php
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Knp\Bundle\GaufretteBundle\KnpGaufretteBundle()
2011-05-08 21:04:37 +00:00
);
// ...
}
```
Configuration
2017-01-16 13:00:11 +00:00
=============
2011-05-08 21:04:37 +00:00
The Gaufrette bundle allows you to declare your filesystems as services without having to reach into the famous "Service Container".
Indeed, you can do it with the configuration!
The configuration of the Gaufrette bundle is divided into two parts: the `adapters` and the `filesystems`.
## Configuring the Adapters
``` yaml
# app/config/config.yml
knp_gaufrette:
2011-05-08 21:04:37 +00:00
adapters:
foo:
local:
directory: /path/to/my/filesystem
```
The defined adapters are then used to create the filesystems.
2011-05-08 21:04:37 +00:00
2017-01-16 13:00:11 +00:00
You can use on of these adapters:
* [Local Adapter](Resources/docs/adapters/local.md)
* [Safe Local Adapter](docs/safe_local.md)
* [Service](Resources/docs/adapters/service.md)
* [In Memory](Resources/docs/adapters/memory.md)
* [Azure Blob Storage](Resources/docs/adapters/azure.md)
* [GridFS](Resources/docs/adapters/gridfs.md)
* [MogileFS](Resources/docs/adapters/mogilefs.md)
* [Ftp](Resources/docs/adapters/ftp.md)
* [Sftp](Resources/docs/adapters/sftp.md)
* [Phpseclib Sftp](Resources/docs/adapters/phpseclib_sftp.md)
* [Apc](Resources/docs/adapters/apc.md)
* [Amazon S3](Resources/docs/adapters/amazon_s3.md)
* [AwsS3](Resources/docs/adapters/awss3.md)
* [Open Cloud](Resources/docs/adapters/opencloud.md)
* [GoogleCloudStorage](Resources/docs/adapters/googlecloud.md)
* [Cache](Resources/docs/adapters/cache.md)
* [Stream Wrapper](Resources/docs/adapters/stream.md)
* [Doctrine DBAL](Resources/docs/adapters/doctrine_dbal.md)
* [Dropbox](Resources/docs/adapters/dropbox.md)
2011-05-08 21:04:37 +00:00
## Configuring the Filesystems
``` yaml
# app/config/config.yml
knp_gaufrette:
2011-05-08 21:04:37 +00:00
adapters:
# ...
filesystems:
bar:
adapter: foo
alias: foo_filesystem
```
Each defined filesystem must have an `adapter` with its value set to an adapter's key.
The filesystem defined above will result in a service with id `gaufrette.bar_filesystem`.
The `alias` parameter allows us to define an alias for it (`foo_filesystem` in this case).
2011-05-08 21:04:37 +00:00
2011-06-18 18:49:55 +00:00
The filesystem map
2017-01-16 13:00:11 +00:00
==================
2011-06-18 18:49:55 +00:00
You can access all declared filesystems through the map service.
2011-06-18 18:49:55 +00:00
In the previous exemple, we declared a `bar` filesystem:
``` php
$container->get('knp_gaufrette.filesystem_map')->get('bar');
2011-06-18 18:49:55 +00:00
```
Returns the `bar` instance of `Gaufrette\Filesystem`.
2011-06-18 18:49:55 +00:00
[gaufrette-homepage]: https://github.com/KnpLabs/Gaufrette