how to use Gaufrette Stream Wrappers?

1.7k Views Asked by At

If i have defined as below a stream wrapper in my symfony2 config.yml:

knp_gaufrette:
    adapters:
        my_drive:
            local:
                directory: %my_drive_path%
                create:     true
    filesystems:
        user_fs:
            adapter:    my_drive
            alias:      my_drive_filesystem
    stream_wrapper:
        protocol: data

how can i use it in my controller for download the file ?

i have something like this:

$response = new BinaryFileResponse("data://user_fs/" . $key);

so i call my file using the addres: "data://user_fs/" haw can i change it to dont use it, couse if i change name in config i will also have to change it in my controller. and i want to manage it only in one file (config)

1

There are 1 best solutions below

0
On

You can define path as a parameter in your parameters.yml:

parameters:
    data_protocol: data
    data_filesystem: user_fs
    data_path: "%data_protocol%://%data_filesystem%/"

and get it from container:

$path = $this->get('system_container')->getParameter('data_path')
$response = new BinaryResponse($path . $key);