rector/packages/Caching/CacheFactory.php
2021-06-17 09:46:43 +00:00

36 lines
1.4 KiB
PHP

<?php
declare (strict_types=1);
namespace Rector\Caching;
use Rector\Caching\ValueObject\Storage\FileCacheStorage;
use Rector\Core\Configuration\Option;
use RectorPrefix20210617\Symplify\PackageBuilder\Parameter\ParameterProvider;
use RectorPrefix20210617\Symplify\SmartFileSystem\SmartFileSystem;
final class CacheFactory
{
/**
* @var \Symplify\PackageBuilder\Parameter\ParameterProvider
*/
private $parameterProvider;
/**
* @var \Symplify\SmartFileSystem\SmartFileSystem
*/
private $smartFileSystem;
public function __construct(\RectorPrefix20210617\Symplify\PackageBuilder\Parameter\ParameterProvider $parameterProvider, \RectorPrefix20210617\Symplify\SmartFileSystem\SmartFileSystem $smartFileSystem)
{
$this->parameterProvider = $parameterProvider;
$this->smartFileSystem = $smartFileSystem;
}
public function create() : \Rector\Caching\Cache
{
$cacheDirectory = $this->parameterProvider->provideStringParameter(\Rector\Core\Configuration\Option::CACHE_DIR);
// 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);
}
}