mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-03 09:50:49 +00:00
aae549741f
0cb3fd0feb
[Php73] Handle crash Type Error on JsonThrowOnErrorRector (#4626)
43 lines
1.5 KiB
PHP
43 lines
1.5 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 Rector\Core\Configuration\Parameter\SimpleParameterProvider;
|
|
use RectorPrefix202308\Symfony\Component\Filesystem\Filesystem;
|
|
final class CacheFactory
|
|
{
|
|
/**
|
|
* @readonly
|
|
* @var \Symfony\Component\Filesystem\Filesystem
|
|
*/
|
|
private $fileSystem;
|
|
public function __construct(Filesystem $fileSystem)
|
|
{
|
|
$this->fileSystem = $fileSystem;
|
|
}
|
|
/**
|
|
* @api config factory
|
|
*/
|
|
public function create() : \Rector\Caching\Cache
|
|
{
|
|
$cacheDirectory = SimpleParameterProvider::provideStringParameter(Option::CACHE_DIR);
|
|
$cacheClass = FileCacheStorage::class;
|
|
if (SimpleParameterProvider::hasParameter(Option::CACHE_CLASS)) {
|
|
$cacheClass = SimpleParameterProvider::provideStringParameter(Option::CACHE_CLASS);
|
|
}
|
|
if ($cacheClass === FileCacheStorage::class) {
|
|
// ensure cache directory exists
|
|
if (!$this->fileSystem->exists($cacheDirectory)) {
|
|
$this->fileSystem->mkdir($cacheDirectory);
|
|
}
|
|
$fileCacheStorage = new FileCacheStorage($cacheDirectory, $this->fileSystem);
|
|
return new \Rector\Caching\Cache($fileCacheStorage);
|
|
}
|
|
return new \Rector\Caching\Cache(new MemoryCacheStorage());
|
|
}
|
|
}
|