Using Gaufrette Stream Wrappers with AsseticBundle
Asked Answered
K

1

9

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

Kellar answered 17/6, 2014 at 11:17 Comment(3)
Did you resolve this issue?Eggnog
In my case it pops up because the assetic:dump command can't create a directory (mkdir() in php). I'm using the wrapper to upload files to an object store (OpenStack swift) which doesn't support directories. Don't know how to solve this issue at the moment :(Eggnog
Maybe you could try to rerun the same command using the -vvv option in order to increase the verbosity of your error message.Thymic
D
0

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.

Degraded answered 13/9, 2014 at 20:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.