2018-10-12 05:00:32 +02:00
|
|
|
<?php
|
2018-11-12 16:57:05 +01:00
|
|
|
namespace Psalm\Tests\Internal\Provider;
|
2018-10-12 05:00:32 +02:00
|
|
|
|
|
|
|
use Psalm\Storage\FileStorage;
|
2019-06-26 22:52:29 +02:00
|
|
|
use function strtolower;
|
2018-10-12 05:00:32 +02:00
|
|
|
|
2018-11-06 03:57:36 +01:00
|
|
|
class FileStorageInstanceCacheProvider extends \Psalm\Internal\Provider\FileStorageCacheProvider
|
2018-10-12 05:00:32 +02:00
|
|
|
{
|
|
|
|
/** @var array<string, FileStorage> */
|
|
|
|
private $cache = [];
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $file_contents
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function writeToCache(FileStorage $storage, $file_contents)
|
|
|
|
{
|
|
|
|
$file_path = strtolower($storage->file_path);
|
|
|
|
$this->cache[$file_path] = $storage;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $file_path
|
|
|
|
* @param string $file_contents
|
|
|
|
*
|
|
|
|
* @return FileStorage|null
|
|
|
|
*/
|
|
|
|
public function getLatestFromCache($file_path, $file_contents)
|
|
|
|
{
|
|
|
|
$cached_value = $this->loadFromCache(strtolower($file_path));
|
|
|
|
|
|
|
|
if (!$cached_value) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $cached_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $file_path
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function removeCacheForFile($file_path)
|
|
|
|
{
|
|
|
|
unset($this->cache[strtolower($file_path)]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $file_path
|
|
|
|
*
|
|
|
|
* @return FileStorage|null
|
|
|
|
*/
|
|
|
|
private function loadFromCache($file_path)
|
|
|
|
{
|
|
|
|
return $this->cache[strtolower($file_path)] ?? null;
|
|
|
|
}
|
|
|
|
}
|