mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-03 01:40:49 +00:00
fc10fce13d
* re-enable rectify and ecs * [Rectify] [Php81] Enable Rectify on Readonly Property only * comment * [ci-review] Rector Rectify * [ci-review] Rector Rectify * [ci-review] Rector Rectify * [ci-review] Rector Rectify * [ci-review] Rector Rectify Co-authored-by: GitHub Action <action@github.com>
43 lines
1.3 KiB
PHP
43 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Rector\Caching;
|
|
|
|
use Rector\Caching\ValueObject\Storage\FileCacheStorage;
|
|
use Rector\Caching\ValueObject\Storage\MemoryCacheStorage;
|
|
use Rector\Core\Configuration\Option;
|
|
use Symplify\PackageBuilder\Parameter\ParameterProvider;
|
|
use Symplify\SmartFileSystem\SmartFileSystem;
|
|
|
|
final class CacheFactory
|
|
{
|
|
public function __construct(
|
|
private readonly ParameterProvider $parameterProvider,
|
|
private readonly SmartFileSystem $smartFileSystem
|
|
) {
|
|
}
|
|
|
|
public function create(): Cache
|
|
{
|
|
$cacheDirectory = $this->parameterProvider->provideStringParameter(Option::CACHE_DIR);
|
|
|
|
$cacheClass = FileCacheStorage::class;
|
|
if ($this->parameterProvider->hasParameter(Option::CACHE_CLASS)) {
|
|
$cacheClass = $this->parameterProvider->provideStringParameter(Option::CACHE_CLASS);
|
|
}
|
|
|
|
if ($cacheClass === FileCacheStorage::class) {
|
|
// ensure cache directory exists
|
|
if (! $this->smartFileSystem->exists($cacheDirectory)) {
|
|
$this->smartFileSystem->mkdir($cacheDirectory);
|
|
}
|
|
|
|
$fileCacheStorage = new FileCacheStorage($cacheDirectory, $this->smartFileSystem);
|
|
return new Cache($fileCacheStorage);
|
|
}
|
|
|
|
return new Cache(new MemoryCacheStorage());
|
|
}
|
|
}
|