Permalink
Browse files

Add new "group cache in folders" option.

  • Loading branch information...
reinink committed Dec 24, 2015
1 parent c45cef0 commit ec5c79a7013944700261862e8797acd81069ffff
Showing with 74 additions and 1 deletion.
  1. +25 −1 src/Server.php
  2. +14 −0 src/ServerFactory.php
  3. +13 −0 tests/ServerFactoryTest.php
  4. +22 −0 tests/ServerTest.php
@@ -36,6 +36,12 @@ class Server
*/
protected $cachePathPrefix;
/**
* Whether to group cache in folders.
* @var bool
*/
protected $groupCacheInFolders = true;
/**
* Image manipulation API.
* @var ApiInterface
@@ -204,6 +210,24 @@ public function getCachePathPrefix()
return $this->cachePathPrefix;
}
/**
* Set the group cache in folders setting.
* @param bool $groupCacheInFolders Whether to group cache in folders.
*/
public function setGroupCacheInFolders($groupCacheInFolders)
{
$this->groupCacheInFolders = $groupCacheInFolders;
}
/**
* Get the group cache in folders setting.
* @return bool Whether to group cache in folders.
*/
public function getGroupCacheInFolders()
{
return $this->groupCacheInFolders;
}
/**
* Get cache path.
* @param string $path Image path.
@@ -224,7 +248,7 @@ public function getCachePath($path, array $params = [])
$md5 = md5($sourcePath.'?'.http_build_query($params));
$path = $sourcePath.'/'.$md5;
$path = $this->groupCacheInFolders ? $sourcePath.'/'.$md5 : $md5;
if ($this->cachePathPrefix) {
$path = $this->cachePathPrefix.'/'.$path;
@@ -55,6 +55,7 @@ public function getServer()
$server->setSourcePathPrefix($this->getSourcePathPrefix());
$server->setCachePathPrefix($this->getCachePathPrefix());
$server->setGroupCacheInFolders($this->getGroupCacheInFolders());
$server->setDefaults($this->getDefaults());
$server->setPresets($this->getPresets());
$server->setBaseUrl($this->getBaseUrl());
@@ -123,6 +124,19 @@ public function getCachePathPrefix()
}
}
/**
* Get the group cache in folders setting.
* @return bool Whether to group cache in folders.
*/
public function getGroupCacheInFolders()
{
if (isset($this->config['group_cache_in_folders'])) {
return $this->config['group_cache_in_folders'];
}
return true;
}
/**
* Get watermarks file system.
* @return FilesystemInterface|null Watermarks file system.
@@ -92,6 +92,19 @@ public function testGetCachePathPrefix()
$this->assertSame('cache', $server->getCachePathPrefix());
}
public function testGetGroupCacheInFolders()
{
$server = new ServerFactory();
$this->assertTrue($server->getGroupCacheInFolders());
$server = new ServerFactory([
'group_cache_in_folders' => false,
]);
$this->assertFalse($server->getGroupCacheInFolders());
}
public function testGetWatermarks()
{
$server = new ServerFactory([
@@ -135,6 +135,18 @@ public function testGetCachePathPrefix()
$this->assertEquals('', $this->server->getCachePathPrefix());
}
public function testSetGroupCacheInFolders()
{
$this->server->setGroupCacheInFolders(false);
$this->assertFalse($this->server->getGroupCacheInFolders());
}
public function testGetGroupCacheInFolders()
{
$this->assertTrue($this->server->getGroupCacheInFolders());
}
public function testGetCachePath()
{
$this->assertEquals(
@@ -143,6 +155,16 @@ public function testGetCachePath()
);
}
public function testGetCachePathWithNoFolderGrouping()
{
$this->server->setGroupCacheInFolders(false);
$this->assertEquals(
'e863e008b6f09807c3b0aa3805bc9c63',
$this->server->getCachePath('image.jpg', ['w' => '100'])
);
}
public function testGetCachePathWithPrefix()
{
$this->server->setCachePathPrefix('img/');

0 comments on commit ec5c79a

Please sign in to comment.