Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for directory visiblity #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
"League\\Flysystem\\Memory\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"League\\Flysystem\\Memory\\Tests\\": "tests/"
}
},
"config": {
"bin-dir": "bin"
},
Expand Down
2 changes: 2 additions & 0 deletions src/MemoryAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function __construct(Config $config = null)
$config = $config ?: new Config();

$this->storage['']['timestamp'] = $config->get('timestamp', time());
$this->storage['']['visibility'] = $config->get('visibility', AdapterInterface::VISIBILITY_PUBLIC);
}

/**
Expand Down Expand Up @@ -268,6 +269,7 @@ protected function doCreateDir($dirname, Config $config)

$this->storage[$dirname]['type'] = 'dir';
$this->storage[$dirname]['timestamp'] = $config->get('timestamp', time());
$this->storage[$dirname]['visibility'] = $config->get('visibility', AdapterInterface::VISIBILITY_PUBLIC);

return true;
}
Expand Down
16 changes: 14 additions & 2 deletions tests/MemoryAdapterTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

namespace League\Flysystem\Memory\Tests;

use League\Flysystem\AdapterInterface;
use League\Flysystem\Config;
use League\Flysystem\Memory\MemoryAdapter;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -38,21 +41,30 @@ public function testCopy()
public function testCreateDir()
{
$result = $this->adapter->createDir('dir/subdir', new Config());
$this->assertSame(3, count($result));
$this->assertSame(4, count($result));
$this->assertSame('dir/subdir', $result['path']);
$this->assertSame('dir', $result['type']);
$this->arrayHasKey($result, 'timestamp');
$this->arrayHasKey($result, 'visibility');

$this->assertTrue($this->adapter->has('dir'));
$this->assertTrue($this->adapter->has('dir/subdir'));

$result = $this->adapter->createDir('dir', new Config());
$this->assertSame(3, count($result));
$this->assertSame(4, count($result));
$this->assertSame('dir', $result['path']);
$this->assertSame('dir', $result['type']);
$this->arrayHasKey($result, 'timestamp');
$this->arrayHasKey($result, 'visibility');

$this->assertFalse($this->adapter->createDir('file.txt', new Config()));
$this->assertFalse($this->adapter->createDir('file.txt/dir', new Config()));

$this->adapter->createDir('public', new Config());
$this->assertEquals(AdapterInterface::VISIBILITY_PUBLIC, $this->adapter->getVisibility('public')['visibility']);

$this->adapter->createDir('private', new Config(['visibility' => AdapterInterface::VISIBILITY_PRIVATE]));
$this->assertEquals(AdapterInterface::VISIBILITY_PRIVATE, $this->adapter->getVisibility('private')['visibility']);
}

public function testDelete()
Expand Down