2011-05-08 21:04:37 +00:00
Gaufrette Bundle
================
Provides a [Gaufrette][gaufrette-homepage] integration for your Symfony projects.
2011-05-13 15:49:11 +00:00
About Gaufrette
---------------
Gaufrette is a PHP 5.3+ library providing a filesystem abstraction layer.
This abstraction layer permits you to develop your applications without the need to know were all their medias will be stored and how.
Documentation is available the [official page of Gaufrette][gaufrette-homepage].
2011-05-08 21:04:37 +00:00
Installation
------------
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.
## Download the bundle
2011-07-03 09:38:38 +00:00
You can download an archive of the bundle and unpack it in the `vendor/bundles/Knp/Bundle/GaufretteBundle` directory of your application.
2011-05-08 21:04:37 +00:00
2011-10-03 06:51:48 +00:00
### Standard Edition Style
If you are using the `deps` file to manage your project's dependencies,
you must add the following lines to it:
[gaufrette]
git=http://github.com/knplabs/Gaufrette.git
[KnpGaufretteBundle]
git=http://github.com/knplabs/KnpGaufretteBundle.git
2011-11-15 11:07:24 +00:00
target=/bundles/Knp/Bundle/GaufretteBundle
2011-10-03 06:51:48 +00:00
### Git Submodule Style
If you are versioning your project with git, you had better to embed it
as a submodule:
2011-05-08 21:04:37 +00:00
2011-07-03 09:38:38 +00:00
$ git submodule add https://github.com/knplabs/KnpGaufretteBundle.git vendor/bundles/Knp/Bundle/GaufretteBundle
2011-05-08 21:04:37 +00:00
## Add the namespace in the autoloader
2011-10-03 07:02:13 +00:00
You must register both Gaufrette and the KnpGaufretteBundle in your autoloader:
2011-05-08 21:04:37 +00:00
``` php
< ?php
// app/autoload.php
$loader->registerNamespaces(array(
2011-10-03 06:51:48 +00:00
'Knp\Bundle' => __DIR__ .'/../vendor/bundles',
'Gaufrette' => __DIR__ .'/../vendor/gaufrette/src',
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(
// ...
2011-07-03 09:38:38 +00:00
new Knp\Bundle\GaufretteBundle\KnpGaufretteBundle()
2011-05-08 21:04:37 +00:00
);
// ...
}
```
Configuration
-------------
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
2011-07-03 09:38:38 +00:00
knp_gaufrette:
2011-05-08 21:04:37 +00:00
adapters:
foo:
local:
directory: /path/to/my/filesystem
```
The defined adapters are usable to create the filesystems.
## Configuring the Filesystems
``` yaml
# app/config/config.yml
2011-07-03 09:38:38 +00:00
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 the key of an adapter as value.
2011-05-13 04:53:07 +00:00
The filesystem defined above with result in a service with id `gaufrette.bar_filesystem` .
2011-05-08 21:04:37 +00:00
The `alias` parameter permits to also defines an alias for it.
2011-06-18 18:49:55 +00:00
The filesystem map
------------------
You can access to all declared filesystems through the map service.
In the previous exemple, we declared a `bar` filesystem:
``` php
2011-07-03 09:38:38 +00:00
$container->get('knp_gaufrette.filesystem_map')->get('bar');
2011-06-18 18:49:55 +00:00
```
Returns the instance of `Gaufrette\Filesystem` for `bar` .
2011-05-08 21:04:37 +00:00
Adapters Reference
------------------
## Local Adapter
A simple local filesystem based adapter.
### Parameters
* `directory` The directory of the filesystem *(required)*
* `create` Whether to create the directory if it does not exist *(default true)*
2011-10-03 13:11:44 +00:00
### Example
2011-05-08 21:04:37 +00:00
``` yaml
# app/config/config.yml
2011-07-03 09:38:38 +00:00
knp_gaufrette:
2011-05-08 21:04:37 +00:00
adapters:
foo:
local:
directory: /path/to/my/filesystem
create: true
```
## Safe Local Adapter (safe\_local)
Almost as simple as the **local** adapter, but it encodes key to avoid having to deal with the directories structure.
### Parameters
* `directory` The directory of the filesystem *(required)*
* `create` Whether to create the directory if it does not exist *(default true)*
2011-10-03 13:11:44 +00:00
### Example
2011-05-08 21:04:37 +00:00
``` yaml
2011-05-13 15:49:11 +00:00
# app/config/config.yml
2011-07-03 09:38:38 +00:00
knp_gaufrette:
2011-05-13 15:49:11 +00:00
adapters:
foo:
safe_local:
directory: /path/to/my/filesystem
create: true
2011-05-08 21:04:37 +00:00
```
## Service (service)
Allows you to use a user defined adapter service.
### Parameters
* `id` The id of the service *(required)*
2011-10-03 13:11:44 +00:00
### Example
2011-05-08 21:04:37 +00:00
``` yaml
2011-05-13 15:49:11 +00:00
# app/config/config.yml
2011-07-03 09:38:38 +00:00
knp_gaufrette:
2011-05-13 15:49:11 +00:00
adapters:
foo:
service:
id: my.adapter.service
2011-05-08 21:04:37 +00:00
```
## In Memory (in\_memory)
Adapter for test purposes, it stores files in an internal array.
### Parameters
* `files` An array of files *(optional)*
The `files` is an array of files where each file is a sub-array having the `content` , `checksum` and `mtime` optional keys.
2011-10-03 13:11:44 +00:00
### Example
2011-05-08 21:04:37 +00:00
``` yaml
2011-05-13 15:49:11 +00:00
# app/config/config.yml
2011-07-03 09:38:38 +00:00
knp_gaufrette:
2011-05-13 15:49:11 +00:00
adapters:
foo:
in_memory:
files:
'file1.txt': ~
'file2.txt':
content: Some content
checksum: abc1efg2hij3
mtime: 123456890123
2011-05-08 21:04:37 +00:00
```
2011-05-13 04:53:07 +00:00
2011-10-03 13:11:44 +00:00
## GridFS (gridfs)
2011-10-12 06:26:48 +00:00
Adapter that allows you to use a MongoDB GridFS for storing files.
2011-10-03 13:11:44 +00:00
### Parameters
* `mongogridfs_id` The id of the service that provides MongoGridFS object instance for adapter *(required)*
### Example
``` yaml
# app/config/config.yml
knp_gaufrette:
adapters:
foo:
gridfs:
mongogridfs_id: acme_test.gridfs
```
In your AcmeTestBundle, add following service definitions:
``` yaml
2011-10-03 13:19:08 +00:00
# src/Acme/TestBundle/Resources/config/services.yml
2011-10-03 13:11:44 +00:00
parameters:
acme_test.mongo.server: "mongodb://localhost:27017"
acme_test.mongo.options:
connect: true
acme_test.mongodb.name: "test_database"
acme_test.gridfs.prefix: "fs" #Default
services:
acme_test.mongo:
class: Mongo
arguments: [%acme_test.mongo.server%, %acme_test.mongo.options%]
acme_test.mongodb:
class: MongoDB
arguments: [@acme_test.mongo, %acme_test.mongodb.name%]
acme_test.gridfs:
class: MongoGridFS
arguments: [@acme_test.mongodb, %acme_test.gridfs.prefix%]
```
2011-10-12 06:47:11 +00:00
Note that it is possible to prepare MongoGridFS service anyway you like. This is just one way to do it.
2011-10-12 06:40:44 +00:00
2011-10-11 12:29:12 +00:00
## MogileFS (mogilefs)
2011-10-12 06:26:48 +00:00
Adapter that allows you to use MogileFS for storing files.
2011-10-11 12:29:12 +00:00
### Parameters
* `domain` MogileFS domain
* `hosts` Available trackers
### Example
``` yaml
# app/config/config.yml
knp_gaufrette:
adapters:
foo:
mogilefs:
domain: foobar
hosts: ["192.168.0.1:7001", "192.168.0.2:7001"]
```
2011-10-03 13:11:44 +00:00
2011-05-13 04:53:07 +00:00
[gaufrette-homepage]: https://github.com/knplabs/Gaufrette