2021-03-18 01:11:54 +00:00
|
|
|
<?php
|
|
|
|
|
2021-05-09 20:15:43 +00:00
|
|
|
declare (strict_types=1);
|
2021-06-11 11:03:31 +00:00
|
|
|
namespace Rector\Caching;
|
2021-03-18 01:11:54 +00:00
|
|
|
|
2021-06-11 11:03:31 +00:00
|
|
|
use Rector\Caching\ValueObject\Storage\FileCacheStorage;
|
2021-07-28 07:05:44 +00:00
|
|
|
use Rector\Caching\ValueObject\Storage\MemoryCacheStorage;
|
2021-03-18 01:11:54 +00:00
|
|
|
use Rector\Core\Configuration\Option;
|
2021-08-08 00:26:40 +00:00
|
|
|
use RectorPrefix20210808\Symplify\PackageBuilder\Parameter\ParameterProvider;
|
|
|
|
use RectorPrefix20210808\Symplify\SmartFileSystem\SmartFileSystem;
|
2021-06-11 11:03:31 +00:00
|
|
|
final class CacheFactory
|
2021-03-18 01:11:54 +00:00
|
|
|
{
|
|
|
|
/**
|
2021-05-10 23:39:21 +00:00
|
|
|
* @var \Symplify\PackageBuilder\Parameter\ParameterProvider
|
2021-03-18 01:11:54 +00:00
|
|
|
*/
|
|
|
|
private $parameterProvider;
|
|
|
|
/**
|
2021-05-10 23:39:21 +00:00
|
|
|
* @var \Symplify\SmartFileSystem\SmartFileSystem
|
2021-03-18 01:11:54 +00:00
|
|
|
*/
|
|
|
|
private $smartFileSystem;
|
2021-08-08 00:26:40 +00:00
|
|
|
public function __construct(\RectorPrefix20210808\Symplify\PackageBuilder\Parameter\ParameterProvider $parameterProvider, \RectorPrefix20210808\Symplify\SmartFileSystem\SmartFileSystem $smartFileSystem)
|
2021-03-18 01:11:54 +00:00
|
|
|
{
|
|
|
|
$this->parameterProvider = $parameterProvider;
|
|
|
|
$this->smartFileSystem = $smartFileSystem;
|
|
|
|
}
|
2021-06-11 11:03:31 +00:00
|
|
|
public function create() : \Rector\Caching\Cache
|
2021-03-18 01:11:54 +00:00
|
|
|
{
|
2021-05-10 22:23:08 +00:00
|
|
|
$cacheDirectory = $this->parameterProvider->provideStringParameter(\Rector\Core\Configuration\Option::CACHE_DIR);
|
2021-07-28 07:05:44 +00:00
|
|
|
$cacheClass = \Rector\Caching\ValueObject\Storage\FileCacheStorage::class;
|
|
|
|
if ($this->parameterProvider->hasParameter(\Rector\Core\Configuration\Option::CACHE_CLASS)) {
|
|
|
|
$cacheClass = $this->parameterProvider->provideStringParameter(\Rector\Core\Configuration\Option::CACHE_CLASS);
|
2021-03-18 01:11:54 +00:00
|
|
|
}
|
2021-07-28 07:05:44 +00:00
|
|
|
if ($cacheClass === \Rector\Caching\ValueObject\Storage\FileCacheStorage::class) {
|
|
|
|
// ensure cache directory exists
|
|
|
|
if (!$this->smartFileSystem->exists($cacheDirectory)) {
|
|
|
|
$this->smartFileSystem->mkdir($cacheDirectory);
|
|
|
|
}
|
|
|
|
$fileCacheStorage = new \Rector\Caching\ValueObject\Storage\FileCacheStorage($cacheDirectory, $this->smartFileSystem);
|
|
|
|
return new \Rector\Caching\Cache($fileCacheStorage);
|
|
|
|
}
|
|
|
|
return new \Rector\Caching\Cache(new \Rector\Caching\ValueObject\Storage\MemoryCacheStorage());
|
2021-03-18 01:11:54 +00:00
|
|
|
}
|
|
|
|
}
|