Skip to content

Carpe-Hora/sfGaufrettePlugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sfGaufrettePlugin

The sfGaufrettePlugin integrates Gaufrette in a symfony project.

Build Status

What's cool with this plugin?

First, it uses a cool project. Then, it's cool because it allows you to define "gaufrettes" directly from the config/gaufrettes.yml configuration file and use them easily everywhere in your applications.

It also provides a way to map filesystem resources (files) to their URL.

Examples

Gaufrettes definition

# config/gaufrettes.yml
all:                                    # the environment
  my_filesystem:
    adapter:                            # create a ftp filesystem
      class:  \Gaufrette\Adapter\Ftp
      param:
        path:     /home/joe
        host:     foo.com
        username: joe
        password: joe
    cache:                              # cache it locally
      class:  \Gaufrette\Adapter\Local
      param:
        destination: %SF_CACHE_DIR%/gaufrette/cache
      ttl:    3600
    url_resolver:                       # and define the URL resolver
      class:  sfPrefixUrlResolver
      param:
        prefix: /uploads/
  my_s3_filesystem:
    adapter:                            # create a ftp filesystem
      class:  \AmazonS3Adapter
      param:
        amazon:
          class:  \AmazonS3
          param:
            options:
              key: <AMAZON-ACCESS-KEY>
              secret: <AMAZON-ACCESS-SECRET>
        bucket: <BUCKET-NAME>
        options:
          region: s3-eu-west-1.amazonaws.com
    cache:                              # cache it locally
      class:  \Gaufrette\Adapter\Local
      param:
        destination: %SF_CACHE_DIR%/gaufrette/cache
      ttl:    3600
    url_resolver:                       # and define the URL resolver
      class:  sfPrefixUrlResolver
      param:
        prefix: http://<bucket-name>.s3-website-eu-west-1.amazonaws.com/

Gaufrette usage

The previous configuration creates a gaufrette named my_filesystem and exposes it through the context:

<?php
// myAction.class.php
$myFilesystem = $this->getContext()->getGaufrette('my_filesystem');

$url = $myFilesystem->getUrl('my_resource_key');
$content = $myFilesystem->read('my/file.ext');
$myFilesystem->write('my/file.ext.bck', $content);

Once you have retrieved the gaufrette, you can use it as described in the Gaufrette README.

The URL resolvers

The URL resolvers are the entities that map files to URL. There are currently two of them included in the plugin:

  • sfPrefixUrlResolver: the url is the concatenation of a prefix and a filename
  • ̀sfAmazonS3UrlResolver: turns informations of a bucket and a filename into a public url

Form integration

We provide a validator to use instead of the sfValidatorFile to ease the integration in forms. See the sfGaufretteFileValidator class for more information.

Installation

Install the behavior in your plugins directory:

git submodule add git://github.com/Carpe-Hora/sfGaufrettePlugin.git
git submodule update --init --recursive

As Gaufrette is bundled with the plugin, you have to initialize the submodules, at least for the sfGaufrettePlugin.

And now, enable the plugin in your project's configuration.

<?php
// config/ProjectConfiguration.class.php

class ProjectConfiguration extends sfProjectConfiguration
{
  public function setup()
  {
    $this->enablePlugins(array(
      // ...
      'sfGaufrettePlugin',
      // ...
    ));
  }
}

Licence

sfGaufrettePlugin is released under the MIT License. See the bundled LICENSE file for details.

About

gaufrette integration for symfony 1.4

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •