Using Gaufrette Stream Wrappers with AsseticBundle

1.2k Views Asked by At

I'm trying to use a Gaufrette Stream Wrapper to tell the AsseticBundle where to dump the project assets but I can't make it recognize them.

This is how the knp_gaufrette section of my config_dev.yml looks like:

knp_gaufrette:
    adapters:
        dev_adapter:
            local:
                directory: /vagrant/test
                create: true

    filesystems:
        dev_adapter:
            adapter: dev_adapter

    stream_wrapper: ~

I tested the wrapper using a simple action to make sure that it is properly registered, and it works fine:

public function thanksAction()
{
    file_put_contents('gaufrette://dev_adapter/test.txt', "ABC\n", FILE_APPEND);

    return new Response(file_get_contents('gaufrette://dev_adapter/test.txt'));
}

Then I set up the assetic bundle configuration like this (in config_dev.yml too):

assetic:
    read_from: gaufrette://dev_adapter
    write_to: gaufrette://dev_adapter

However, when I try to dump the assets using console assetic:dump --env=dev I get this error:

Dumping all dev assets.
Debug mode is on.

10:53:28 [dir+] gaufrette://dev_adapter/css



  [RuntimeException]                                      
  Unable to create directory gaufrette://dev_adapter/css  



assetic:dump [--watch] [--force] [--period="..."] [write_to]

Further information:

symfony/symfony: 2.5.0
symfony/assetic-bundle: 2.3.0
knplabs/knp-gaufrette-bundle: 0.1.7

1

There are 1 best solutions below

0
On

I was having the same issue hooking up an Amazon S3 stream wrapper.

My final solution was to comment out the call to mkdir() and the check of it's return value Assetic's DumpCommand.

private function doDump(AssetInterface $asset, OutputInterface $stdout)
{
    // ...

    //if (false === @mkdir($dir, 0777, true)) {
    //    throw new \RuntimeException('Unable to create directory '.$dir);
    //}

    // ...
}

If you're using a dependency manager, copy the command into a new command class, comment out the necessary lines.

I think any directories/resources that don't exist in the path are created automatically.

Example: Directory has an assets folder that is empty. Pushing to s3://bucket-name/assets/css/style.css will create the css folder and style.css file.