Search by

knplabs / knp-gaufrette-bundle

HerzultKnpLabs

Allows to easily use the Gaufrette library in a Symfony project

Package info

github.com/KnpLabs/KnpGaufretteBundle

Homepage

Type:symfony-bundle

pkg:composer/knplabs/knp-gaufrette-bundle

Statistics

Installs: 32 675 194

Dependents: 95

Suggesters: 19

Stars: 721

Open Issues: 30

v1.1.0 2026-12-02 13:50 UTC

README

Build Status

Provides a Gaufrette integration for your Symfony projects.

SWUbanner

About Gaufrette

Gaufrette is a PHP 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.

Documentation is available the official page of Gaufrette.

Installation

Prerequisites

As this bundle is an integration for Symfony of the Gaufrette library, it requires you to first install Gaufrette in your project.

Note that, you need to install separately the adapters you want to use. You can find more details about these packages here, and the full list adapters on packagist.

With composer

composer require knplabs/knp-gaufrette-bundle

Register the bundle

You must register the bundle in your kernel:

<?php

return [
    // ...
    Knp\Bundle\GaufretteBundle\KnpGaufretteBundle::class => ['all' => true],
];

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

# config/packages/knp_gaufrette.yaml
knp_gaufrette:
    adapters:
        foo:
            local:
                directory: /path/to/my/filesystem

The defined adapters are then used to create the filesystems.

You can use on of these adapters:

Configuring the Filesystems

# config/packages/knp_gaufrette.yaml
knp_gaufrette:
    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).

Autowiring filesystems

To inject a filesystem into an autowired service, type-hint Gaufrette\FilesystemInterface. The bundle converts the filesystem key to camel case and appends Filesystem, so a filesystem configured under knp_gaufrette.filesystems.product_images has the named alias productImagesFilesystem.

With Symfony 5.3 or later, pass that alias to #[Target]. The constructor parameter can have any name, such as $source.

use Gaufrette\FilesystemInterface;
use Symfony\Component\DependencyInjection\Attribute\Target;

final class ProductImageService
{
    public function __construct(
        #[Target('productImagesFilesystem')] private FilesystemInterface $source,
    ) {
    }
}

With Symfony 5.1 or 5.2, name the parameter $productImagesFilesystem to match the alias. Matching by parameter name alone is deprecated as of Symfony 8.1.

The filesystem map

You can access all declared filesystems through the map service. In the previous exemple, we declared a bar filesystem:

$container->get('knp_gaufrette.filesystem_map')->get('bar');

Returns the bar instance of Gaufrette\Filesystem.

Use cases

Check out basic examples of the library.

Maintainers

KNPLabs is looking for maintainers (see why).

If you are interested, feel free to open a PR to ask to be added as a maintainer.

We’ll be glad to hear from you :)