listKeys and keys does not show empty directories

104 Views Asked by At

This seems like such a straightforward thing, but I'm struggling to find any information about this in the documentation or anywhere else.

I'm using KnpGaufretteBundle with the following settings in my config.yml

knp_gaufrette:
    adapters:
        images:
            local:
                directory:  "%kernel.root_dir%/../web/uploads/images"
    filesystems:
        images:
            adapter: images

The file structure at the path indicated above is

- images
  - test1.gif
  - test2.gif
  - sub_directory1
    - test3.gif
  - sub_directory2

Note that there are two directories in the images folder, though one of them is empty. If I run listKeys() on the file mapper I get.

array:2 [
  "keys" => array:3 [
    0 => "sub_directory1/test3.gif"
    1 => "test1.gif"
    2 => "test2.gif"
  ]
  "dirs" => array:1 [
    0 => "sub_directory1"
  ]
]

The empty directory is now shown. Is there any way to get this information using Gaufrette?

1

There are 1 best solutions below

0
On

I've taken a closer look at this, and I think I have an answer to my question. It's related to the fact that RecursiveDirectoryIterator doesn't show empty directories when it's implemented in the fashion it is implemented in Gaufrette's Local adapter (as described in the link below).

RecursiveDirectoryIterator() not showing empty directories

I'm sure that this has been done for a reason, but it doesn't really meet with my requirements. It looks like it's not possible to write my own adapter at the moment, though from the looks of things they are part-way through implementing a compiler pass for adapters.

I guess for now I'll opt for a different file abstraction layer, though I have to admit I'm somewhat disappointed.