Skip to content

Commit

Permalink
Fixed directory listings for Noop caching
Browse files Browse the repository at this point in the history
  • Loading branch information
frankdejonge committed Mar 9, 2014
1 parent 78cd781 commit b6cdd39
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/Cache/Noop.php
Expand Up @@ -2,6 +2,8 @@

namespace League\Flysystem\Cache;

use League\Flysystem\Util;

class Noop extends AbstractCache
{
/**
Expand Down Expand Up @@ -38,9 +40,33 @@ public function setComplete($dirname, $recursive)
*/
public function storeContents($directory, array $contents, $recursive)
{
if ($recursive) {
return $contents;
}

foreach ($contents as $index => $object) {
$pathinfo = Util::pathinfo($object['path']);
$object = array_merge($pathinfo, $object);

if ( ! $recursive && $object['dirname'] !== $directory) {
unset($contents[$index]);
continue;
}

$contents[$index] = $object;
}

return $contents;
}

/**
* {@inheritdoc}
*/
public function storeMiss($path)
{
return $this;
}

/**
* {@inheritdoc}
*/
Expand Down
5 changes: 5 additions & 0 deletions tests/FilesystemTests.php
Expand Up @@ -390,6 +390,7 @@ public function testNoop()
$filesystem->write('test.txt', 'contents');
$this->assertTrue($filesystem->has('test.txt'));
$this->assertInternalType('array', $filesystem->listContents());
$this->assertInternalType('array', $filesystem->listContents('', true));
$cache = $filesystem->getCache();
$cache->setComplete('', false);
$cache->flush();
Expand All @@ -403,6 +404,10 @@ public function testNoop()
$this->assertFalse($cache->getVisibility('something'));
$this->assertFalse($cache->listContents('', false));
$filesystem->delete('test.txt');

$this->assertEquals(array(), $cache->storeContents('unknwon', array(
array('path' => 'some/file.txt'),
), false));
}

/**
Expand Down

0 comments on commit b6cdd39

Please sign in to comment.