rector/packages/Caching/CacheFactory.php
Abdul Malik Ikhsan fc10fce13d
[Rectify] [Php81] Enable Rectify on Readonly Property only (#1384)
* 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>
2021-12-04 15:32:52 +03:00

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());
}
}