Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

fixes #328 #335

Merged
merged 2 commits into from
Aug 6, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"require-dev": {
"aws/aws-sdk-php" : "^3.18",
"cache/array-adapter" : "^0.4",
"cache/filesystem-adapter" : "^0.3",
"cache/session-handler" : "^0.1",
"cache/void-adapter" : "^0.3",
"fzaninotto/faker" : "^1.6",
Expand Down
10 changes: 2 additions & 8 deletions src/Viserio/Cache/CacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ protected function createApcuDriver(array $config): ApcuCachePool
* @param array $config
*
* @return \Cache\Adapter\PHPArray\ArrayCachePool
*
* @codeCoverageIgnore
*/
protected function createArrayDriver(array $config): ArrayCachePool
{
Expand Down Expand Up @@ -171,16 +169,12 @@ protected function createPredisDriver(array $config): PredisCachePool
* @param array $config
*
* @return \Cache\Adapter\Filesystem\FilesystemCachePool
*
* @codeCoverageIgnore
*/
protected function createFilesystemDriver(array $config): FilesystemCachePool
{
$adapter = new FilesystemManager($this->config);

$filesystem = new Flysystem($adapter->connection($config['connection']));
$adapter = $this->getContainer()->get($config['connection']);

return new FilesystemCachePool($filesystem);
return new FilesystemCachePool(new Flysystem($adapter));
}

/**
Expand Down
32 changes: 31 additions & 1 deletion src/Viserio/Cache/Tests/CacheManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
declare(strict_types=1);
namespace Viserio\Cache\Tests;

use Interop\Container\ContainerInterface;
use League\Flysystem\Adapter\Local;
use Narrowspark\TestingHelper\Traits\MockeryTrait;
use Viserio\Cache\CacheManager;
use Viserio\Contracts\Config\Manager as ConfigManager;
use Cache\Adapter\{
PHPArray\ArrayCachePool,
Void\VoidCachePool,
Chain\CachePoolChain
Chain\CachePoolChain,
Filesystem\FilesystemCachePool
};
use Cache\SessionHandler\Psr6SessionHandler;
use Cache\Namespaced\NamespacedCachePool;
Expand Down Expand Up @@ -108,4 +111,31 @@ public function testChain()

$this->assertInstanceOf(CachePoolChain::class, $chain);
}

public function testFilesystem()
{
$this->manager->getConfig()->shouldReceive('get')
->once()
->with('cache.drivers', [])
->andReturn([
'filesystem' => [
'connection' => 'local'
]
]);

$this->manager->getConfig()->shouldReceive('get')
->once()
->with('cache.namespace')
->andReturn(null);

$container = $this->mock(ContainerInterface::class);
$container->shouldReceive('get')
->once()
->with('local')
->andReturn(new Local(__DIR__ . '/'));

$this->manager->setContainer($container);

$this->assertInstanceOf(FilesystemCachePool::class, $this->manager->driver('filesystem'));
}
}
4 changes: 2 additions & 2 deletions src/Viserio/Cache/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"cache/array-adapter" : "^0.2",
"cache/session-handler" : "^0.1",
"cache/void-adapter" : "^0.3",
"cache/filesystem-adapter" : "^0.3",
"narrowspark/php-cs-fixer-config" : "^1.1",
"narrowspark/testing-helper" : "^1.5",
"phpunit/phpunit" : "^5.1"
Expand Down Expand Up @@ -82,8 +83,7 @@
"cache/mongodb-adapter" : "Required to use the Mongodb cache (^0.3).",
"cache/predis-adapter" : "Required to use the Predis cache (^0.4).",
"cache/session-handler" : "Required to use the Session cache (^0.1).",
"cache/void-adapter" : "Required to use the Void cache (^0.3).",
"viserio/filesystem" : "Required to use the Filesystem cache. (self.version)"
"cache/void-adapter" : "Required to use the Void cache (^0.3)."
},
"minimum-stability" : "dev",
"prefer-stable" : true
Expand Down
7 changes: 5 additions & 2 deletions src/Viserio/Filesystem/Adapters/AwsS3Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

use Aws\S3\S3Client;
use InvalidArgumentException;
use League\Flysystem\AwsS3v3\AwsS3Adapter as AwsS3v3;
use League\Flysystem\{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There must be one USE keyword per declaration

AdapterInterface,
AwsS3v3\AwsS3Adapter as AwsS3v3
};
use Narrowspark\Arr\StaticArr as Arr;

class AwsS3Connector extends AbstractConnector
Expand Down Expand Up @@ -72,7 +75,7 @@ protected function getConfig(array $config): array
/**
* {@inheritdoc}
*/
protected function getAdapter($client, array $config): \League\Flysystem\AdapterInterface
protected function getAdapter($client, array $config): AdapterInterface
{
return new AwsS3v3($client, $config['bucket'], $config['prefix'], $config['options']);
}
Expand Down
12 changes: 12 additions & 0 deletions src/Viserio/Filesystem/FilesystemManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ public function getDefaultConnection(): string
return $this->config->get($this->getConfigName() . '.default', 'local');
}

/**
* Get the clean flysystem adapter.
*
* @param string|null $name
*
* @return \League\Flysystem\AdapterInterface
*/
public function getFlysystemAdapter(string $name = null): AdapterInterface
{
return parent::connection($name);
}

/**
* {@inheritdoc}
*/
Expand Down
21 changes: 21 additions & 0 deletions src/Viserio/Filesystem/Tests/FilesystemManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Guzzle\Http\Exception\ClientErrorResponseException;
use Guzzle\Http\Exception\CurlException;
use League\Flysystem\AdapterInterface;
use MongoConnectionException;
use Narrowspark\TestingHelper\Traits\MockeryTrait;
use Viserio\Contracts\Config\Manager as ConfigManger;
Expand Down Expand Up @@ -267,4 +268,24 @@ public function testZipConnectorDriver()
$manager->connection('zip')
);
}

public function testgetFlysystemAdapter()
{
$config = $this->mock(ConfigManger::class);
$config->shouldReceive('get')
->once()
->with('filesystem.connections', [])
->andReturn([
'zip' => [
'path' => __DIR__ . '\Adapters\stubs\test.zip',
],
]);

$manager = new FilesystemManager($config);

$this->assertInstanceOf(
AdapterInterface::class,
$manager->getFlysystemAdapter('zip')
);
}
}