2017-02-18 19:41:27 +01:00
|
|
|
<?php
|
2018-11-06 03:57:36 +01:00
|
|
|
namespace Psalm\Internal\Provider;
|
2017-02-18 19:41:27 +01:00
|
|
|
|
2019-06-26 22:52:29 +02:00
|
|
|
use const DIRECTORY_SEPARATOR;
|
2019-07-05 22:24:00 +02:00
|
|
|
use function error_log;
|
|
|
|
use function file_exists;
|
|
|
|
use function file_get_contents;
|
|
|
|
use function file_put_contents;
|
2019-06-26 22:52:29 +02:00
|
|
|
use function filemtime;
|
2019-07-05 22:24:00 +02:00
|
|
|
use function gettype;
|
|
|
|
use function igbinary_serialize;
|
2019-06-26 22:52:29 +02:00
|
|
|
use function igbinary_unserialize;
|
|
|
|
use function is_array;
|
|
|
|
use function is_dir;
|
2019-07-05 22:24:00 +02:00
|
|
|
use function is_readable;
|
|
|
|
use function is_writable;
|
|
|
|
use function json_decode;
|
2019-06-26 22:52:29 +02:00
|
|
|
use function json_encode;
|
2019-07-05 22:24:00 +02:00
|
|
|
use function md5;
|
|
|
|
use function mkdir;
|
|
|
|
use PhpParser;
|
|
|
|
use Psalm\Config;
|
2019-06-26 22:52:29 +02:00
|
|
|
use function scandir;
|
2019-07-05 22:24:00 +02:00
|
|
|
use function serialize;
|
|
|
|
use function touch;
|
2019-06-26 22:52:29 +02:00
|
|
|
use function unlink;
|
2019-07-05 22:24:00 +02:00
|
|
|
use function unserialize;
|
2017-02-18 19:41:27 +01:00
|
|
|
|
2018-12-02 00:37:49 +01:00
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
*/
|
2017-10-15 17:57:44 +02:00
|
|
|
class ParserCacheProvider
|
2017-02-18 19:41:27 +01:00
|
|
|
{
|
2017-03-16 15:58:13 +01:00
|
|
|
const FILE_HASHES = 'file_hashes_json';
|
2017-02-18 19:41:27 +01:00
|
|
|
const PARSER_CACHE_DIRECTORY = 'php-parser';
|
2018-09-26 00:37:24 +02:00
|
|
|
const FILE_CONTENTS_CACHE_DIRECTORY = 'file-caches';
|
2017-02-18 19:41:27 +01:00
|
|
|
const GOOD_RUN_NAME = 'good_run';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var int|null
|
|
|
|
*/
|
2018-10-17 17:03:32 +02:00
|
|
|
private $last_good_run = null;
|
2017-02-18 19:41:27 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A map of filename hashes to contents hashes
|
|
|
|
*
|
2018-10-15 17:29:57 +02:00
|
|
|
* @var array<string, string>|null
|
|
|
|
*/
|
2018-10-17 17:03:32 +02:00
|
|
|
private $existing_file_content_hashes = null;
|
2018-10-15 17:29:57 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A map of recently-added filename hashes to contents hashes
|
|
|
|
*
|
2018-10-09 02:04:05 +02:00
|
|
|
* @var array<string, string>
|
2017-02-18 19:41:27 +01:00
|
|
|
*/
|
2018-10-17 17:03:32 +02:00
|
|
|
private $new_file_content_hashes = [];
|
2017-02-18 19:41:27 +01:00
|
|
|
|
2017-10-15 18:38:47 +02:00
|
|
|
/** @var bool */
|
2018-10-16 21:59:11 +02:00
|
|
|
private $use_igbinary;
|
|
|
|
|
|
|
|
public function __construct(Config $config)
|
|
|
|
{
|
|
|
|
$this->use_igbinary = $config->use_igbinary;
|
|
|
|
}
|
2017-10-15 18:38:47 +02:00
|
|
|
|
2017-02-18 19:41:27 +01:00
|
|
|
/**
|
2018-02-18 23:55:11 +01:00
|
|
|
* @param int $file_modified_time
|
2017-02-18 19:41:27 +01:00
|
|
|
* @param string $file_content_hash
|
2018-10-16 21:59:11 +02:00
|
|
|
* @param string $file_path
|
2017-05-27 02:16:18 +02:00
|
|
|
*
|
2017-02-18 19:41:27 +01:00
|
|
|
* @return array<int, PhpParser\Node\Stmt>|null
|
2017-10-15 18:38:47 +02:00
|
|
|
*
|
|
|
|
* @psalm-suppress UndefinedFunction
|
2017-02-18 19:41:27 +01:00
|
|
|
*/
|
2018-10-16 21:59:11 +02:00
|
|
|
public function loadStatementsFromCache($file_path, $file_modified_time, $file_content_hash)
|
2017-02-18 19:41:27 +01:00
|
|
|
{
|
|
|
|
$root_cache_directory = Config::getInstance()->getCacheDirectory();
|
|
|
|
|
|
|
|
if (!$root_cache_directory) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-16 21:59:11 +02:00
|
|
|
$file_cache_key = $this->getParserCacheKey(
|
|
|
|
$file_path
|
|
|
|
);
|
|
|
|
|
2017-02-18 19:41:27 +01:00
|
|
|
$parser_cache_directory = $root_cache_directory . DIRECTORY_SEPARATOR . self::PARSER_CACHE_DIRECTORY;
|
|
|
|
|
2018-10-15 17:29:57 +02:00
|
|
|
$file_content_hashes = $this->new_file_content_hashes + $this->getExistingFileContentHashes();
|
2017-02-18 19:41:27 +01:00
|
|
|
|
|
|
|
$cache_location = $parser_cache_directory . DIRECTORY_SEPARATOR . $file_cache_key;
|
|
|
|
|
2018-10-09 01:41:32 +02:00
|
|
|
if (isset($file_content_hashes[$file_cache_key])
|
|
|
|
&& $file_content_hash === $file_content_hashes[$file_cache_key]
|
|
|
|
&& is_readable($cache_location)
|
|
|
|
&& filemtime($cache_location) > $file_modified_time
|
2017-02-18 19:41:27 +01:00
|
|
|
) {
|
2017-10-15 18:38:47 +02:00
|
|
|
if ($this->use_igbinary) {
|
|
|
|
/** @var array<int, \PhpParser\Node\Stmt> */
|
2018-10-09 01:41:32 +02:00
|
|
|
$stmts = igbinary_unserialize((string)file_get_contents($cache_location));
|
|
|
|
} else {
|
|
|
|
/** @var array<int, \PhpParser\Node\Stmt> */
|
|
|
|
$stmts = unserialize((string)file_get_contents($cache_location));
|
2017-10-15 18:38:47 +02:00
|
|
|
}
|
|
|
|
|
2018-10-09 01:41:32 +02:00
|
|
|
return $stmts;
|
2017-02-18 19:41:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-26 00:37:24 +02:00
|
|
|
/**
|
2018-10-16 21:59:11 +02:00
|
|
|
* @param string $file_path
|
2018-09-26 00:37:24 +02:00
|
|
|
*
|
|
|
|
* @return array<int, PhpParser\Node\Stmt>|null
|
|
|
|
*
|
|
|
|
* @psalm-suppress UndefinedFunction
|
|
|
|
*/
|
2018-10-16 21:59:11 +02:00
|
|
|
public function loadExistingStatementsFromCache($file_path)
|
2018-09-26 00:37:24 +02:00
|
|
|
{
|
|
|
|
$root_cache_directory = Config::getInstance()->getCacheDirectory();
|
|
|
|
|
|
|
|
if (!$root_cache_directory) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-16 21:59:11 +02:00
|
|
|
$file_cache_key = $this->getParserCacheKey(
|
|
|
|
$file_path
|
|
|
|
);
|
|
|
|
|
2018-09-26 00:37:24 +02:00
|
|
|
$parser_cache_directory = $root_cache_directory . DIRECTORY_SEPARATOR . self::PARSER_CACHE_DIRECTORY;
|
|
|
|
|
|
|
|
$cache_location = $parser_cache_directory . DIRECTORY_SEPARATOR . $file_cache_key;
|
|
|
|
|
|
|
|
if (is_readable($cache_location)) {
|
|
|
|
if ($this->use_igbinary) {
|
|
|
|
/** @var array<int, \PhpParser\Node\Stmt> */
|
|
|
|
return igbinary_unserialize((string)file_get_contents($cache_location)) ?: null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @var array<int, \PhpParser\Node\Stmt> */
|
|
|
|
return unserialize((string)file_get_contents($cache_location)) ?: null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-10-16 21:59:11 +02:00
|
|
|
* @param string $file_path
|
2018-09-26 00:37:24 +02:00
|
|
|
*
|
|
|
|
* @return string|null
|
|
|
|
*/
|
2018-10-16 21:59:11 +02:00
|
|
|
public function loadExistingFileContentsFromCache($file_path)
|
2018-09-26 00:37:24 +02:00
|
|
|
{
|
|
|
|
$root_cache_directory = Config::getInstance()->getCacheDirectory();
|
|
|
|
|
|
|
|
if (!$root_cache_directory) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-16 21:59:11 +02:00
|
|
|
$file_cache_key = $this->getParserCacheKey(
|
|
|
|
$file_path
|
|
|
|
);
|
|
|
|
|
2018-09-26 00:37:24 +02:00
|
|
|
$parser_cache_directory = $root_cache_directory . DIRECTORY_SEPARATOR . self::FILE_CONTENTS_CACHE_DIRECTORY;
|
|
|
|
|
|
|
|
$cache_location = $parser_cache_directory . DIRECTORY_SEPARATOR . $file_cache_key;
|
|
|
|
|
|
|
|
if (is_readable($cache_location)) {
|
|
|
|
return file_get_contents($cache_location);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-18 19:41:27 +01:00
|
|
|
/**
|
|
|
|
* @return array<string, string>
|
|
|
|
*/
|
2018-10-15 17:29:57 +02:00
|
|
|
private function getExistingFileContentHashes()
|
2017-02-18 19:41:27 +01:00
|
|
|
{
|
|
|
|
$config = Config::getInstance();
|
|
|
|
$root_cache_directory = $config->getCacheDirectory();
|
|
|
|
|
2018-10-15 17:29:57 +02:00
|
|
|
if ($this->existing_file_content_hashes === null) {
|
2017-02-18 19:41:27 +01:00
|
|
|
$file_hashes_path = $root_cache_directory . DIRECTORY_SEPARATOR . self::FILE_HASHES;
|
2018-10-09 01:41:32 +02:00
|
|
|
|
|
|
|
if ($root_cache_directory && is_readable($file_hashes_path)) {
|
|
|
|
$hashes_encoded = (string) file_get_contents($file_hashes_path);
|
|
|
|
|
|
|
|
if (!$hashes_encoded) {
|
|
|
|
error_log('Unexpected value when loading from file content hashes');
|
2018-10-15 17:29:57 +02:00
|
|
|
$this->existing_file_content_hashes = [];
|
2019-07-05 22:24:00 +02:00
|
|
|
|
2018-10-15 17:29:57 +02:00
|
|
|
return [];
|
2018-10-09 01:41:32 +02:00
|
|
|
}
|
|
|
|
|
2018-10-09 02:04:05 +02:00
|
|
|
/** @psalm-suppress MixedAssignment */
|
2018-10-09 01:41:32 +02:00
|
|
|
$hashes_decoded = json_decode($hashes_encoded, true);
|
|
|
|
|
|
|
|
if (!is_array($hashes_decoded)) {
|
|
|
|
error_log('Unexpected value ' . gettype($hashes_decoded));
|
2018-10-15 17:29:57 +02:00
|
|
|
$this->existing_file_content_hashes = [];
|
2019-07-05 22:24:00 +02:00
|
|
|
|
2018-10-15 17:29:57 +02:00
|
|
|
return [];
|
2018-10-09 01:41:32 +02:00
|
|
|
}
|
|
|
|
|
2018-10-09 02:04:05 +02:00
|
|
|
/** @var array<string, string> $hashes_decoded */
|
2018-10-15 17:29:57 +02:00
|
|
|
$this->existing_file_content_hashes = $hashes_decoded;
|
|
|
|
} else {
|
|
|
|
$this->existing_file_content_hashes = [];
|
2018-10-09 01:41:32 +02:00
|
|
|
}
|
2017-02-18 19:41:27 +01:00
|
|
|
}
|
|
|
|
|
2018-10-15 17:29:57 +02:00
|
|
|
return $this->existing_file_content_hashes;
|
2017-02-18 19:41:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-10-16 21:59:11 +02:00
|
|
|
* @param string $file_path
|
2017-02-18 19:41:27 +01:00
|
|
|
* @param string $file_content_hash
|
|
|
|
* @param array<int, PhpParser\Node\Stmt> $stmts
|
|
|
|
* @param bool $touch_only
|
2017-05-27 02:16:18 +02:00
|
|
|
*
|
2017-02-18 19:41:27 +01:00
|
|
|
* @return void
|
2017-10-15 18:38:47 +02:00
|
|
|
*
|
|
|
|
* @psalm-suppress UndefinedFunction
|
2017-02-18 19:41:27 +01:00
|
|
|
*/
|
2018-10-16 21:59:11 +02:00
|
|
|
public function saveStatementsToCache($file_path, $file_content_hash, array $stmts, $touch_only)
|
2017-02-18 19:41:27 +01:00
|
|
|
{
|
|
|
|
$root_cache_directory = Config::getInstance()->getCacheDirectory();
|
|
|
|
|
|
|
|
if (!$root_cache_directory) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-16 21:59:11 +02:00
|
|
|
$file_cache_key = $this->getParserCacheKey(
|
|
|
|
$file_path
|
|
|
|
);
|
|
|
|
|
2017-02-18 19:41:27 +01:00
|
|
|
$parser_cache_directory = $root_cache_directory . DIRECTORY_SEPARATOR . self::PARSER_CACHE_DIRECTORY;
|
|
|
|
|
|
|
|
$cache_location = $parser_cache_directory . DIRECTORY_SEPARATOR . $file_cache_key;
|
|
|
|
|
|
|
|
if ($touch_only) {
|
|
|
|
touch($cache_location);
|
|
|
|
} else {
|
|
|
|
if (!is_dir($parser_cache_directory)) {
|
|
|
|
mkdir($parser_cache_directory, 0777, true);
|
|
|
|
}
|
|
|
|
|
2017-10-15 18:38:47 +02:00
|
|
|
if ($this->use_igbinary) {
|
|
|
|
file_put_contents($cache_location, igbinary_serialize($stmts));
|
|
|
|
} else {
|
|
|
|
file_put_contents($cache_location, serialize($stmts));
|
|
|
|
}
|
2017-02-18 19:41:27 +01:00
|
|
|
|
2018-10-15 17:29:57 +02:00
|
|
|
$this->new_file_content_hashes[$file_cache_key] = $file_content_hash;
|
|
|
|
}
|
|
|
|
}
|
2018-10-09 01:41:32 +02:00
|
|
|
|
2018-10-15 17:29:57 +02:00
|
|
|
/**
|
|
|
|
* @return array<string, string>
|
|
|
|
*/
|
|
|
|
public function getNewFileContentHashes()
|
|
|
|
{
|
|
|
|
return $this->new_file_content_hashes;
|
|
|
|
}
|
2018-10-09 01:41:32 +02:00
|
|
|
|
2018-10-15 17:29:57 +02:00
|
|
|
/**
|
|
|
|
* @param array<string, string> $file_content_hashes
|
2019-07-05 22:24:00 +02:00
|
|
|
*
|
2018-10-15 17:29:57 +02:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function addNewFileContentHashes(array $file_content_hashes)
|
|
|
|
{
|
|
|
|
$this->new_file_content_hashes = $file_content_hashes + $this->new_file_content_hashes;
|
|
|
|
}
|
2017-02-18 19:41:27 +01:00
|
|
|
|
2018-10-15 17:29:57 +02:00
|
|
|
/**
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function saveFileContentHashes()
|
|
|
|
{
|
|
|
|
$root_cache_directory = Config::getInstance()->getCacheDirectory();
|
2018-10-09 04:42:45 +02:00
|
|
|
|
2018-10-15 17:29:57 +02:00
|
|
|
if (!$root_cache_directory) {
|
|
|
|
return;
|
2017-02-18 19:41:27 +01:00
|
|
|
}
|
2018-10-15 17:29:57 +02:00
|
|
|
|
|
|
|
$file_content_hashes = $this->new_file_content_hashes + $this->getExistingFileContentHashes();
|
|
|
|
|
|
|
|
$file_hashes_path = $root_cache_directory . DIRECTORY_SEPARATOR . self::FILE_HASHES;
|
|
|
|
|
|
|
|
file_put_contents(
|
|
|
|
$file_hashes_path,
|
|
|
|
json_encode($file_content_hashes)
|
|
|
|
);
|
2017-02-18 19:41:27 +01:00
|
|
|
}
|
|
|
|
|
2018-09-26 00:37:24 +02:00
|
|
|
/**
|
2018-10-16 21:59:11 +02:00
|
|
|
* @param string $file_path
|
2018-09-26 00:37:24 +02:00
|
|
|
* @param string $file_contents
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2018-10-16 21:59:11 +02:00
|
|
|
public function cacheFileContents($file_path, $file_contents)
|
2018-09-26 00:37:24 +02:00
|
|
|
{
|
|
|
|
$root_cache_directory = Config::getInstance()->getCacheDirectory();
|
|
|
|
|
|
|
|
if (!$root_cache_directory) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-16 21:59:11 +02:00
|
|
|
$file_cache_key = $this->getParserCacheKey(
|
|
|
|
$file_path
|
|
|
|
);
|
|
|
|
|
2018-09-26 00:37:24 +02:00
|
|
|
$parser_cache_directory = $root_cache_directory . DIRECTORY_SEPARATOR . self::FILE_CONTENTS_CACHE_DIRECTORY;
|
|
|
|
|
|
|
|
$cache_location = $parser_cache_directory . DIRECTORY_SEPARATOR . $file_cache_key;
|
|
|
|
|
|
|
|
if (!is_dir($parser_cache_directory)) {
|
|
|
|
mkdir($parser_cache_directory, 0777, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
file_put_contents($cache_location, $file_contents);
|
|
|
|
}
|
|
|
|
|
2017-02-18 19:41:27 +01:00
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
2017-07-25 22:11:02 +02:00
|
|
|
public function canDiffFiles()
|
2017-02-18 19:41:27 +01:00
|
|
|
{
|
|
|
|
$cache_directory = Config::getInstance()->getCacheDirectory();
|
|
|
|
|
|
|
|
return $cache_directory && file_exists($cache_directory . DIRECTORY_SEPARATOR . self::GOOD_RUN_NAME);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-01-09 17:49:10 +01:00
|
|
|
* @param float $start_time
|
2017-05-27 02:16:18 +02:00
|
|
|
*
|
2017-02-18 19:41:27 +01:00
|
|
|
* @return void
|
|
|
|
*/
|
2017-07-25 22:11:02 +02:00
|
|
|
public function processSuccessfulRun($start_time)
|
2017-02-18 19:41:27 +01:00
|
|
|
{
|
|
|
|
$cache_directory = Config::getInstance()->getCacheDirectory();
|
|
|
|
|
|
|
|
if (!$cache_directory) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$run_cache_location = $cache_directory . DIRECTORY_SEPARATOR . self::GOOD_RUN_NAME;
|
|
|
|
|
2018-01-09 17:49:10 +01:00
|
|
|
touch($run_cache_location, (int)$start_time);
|
2017-02-18 19:41:27 +01:00
|
|
|
|
|
|
|
$cache_directory .= DIRECTORY_SEPARATOR . self::PARSER_CACHE_DIRECTORY;
|
|
|
|
|
|
|
|
if (is_dir($cache_directory)) {
|
|
|
|
$directory_files = scandir($cache_directory);
|
|
|
|
|
|
|
|
foreach ($directory_files as $directory_file) {
|
|
|
|
$full_path = $cache_directory . DIRECTORY_SEPARATOR . $directory_file;
|
|
|
|
|
|
|
|
if ($directory_file[0] === '.') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
touch($full_path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
2017-07-25 22:11:02 +02:00
|
|
|
public function getLastGoodRun()
|
2017-02-18 19:41:27 +01:00
|
|
|
{
|
2017-07-25 22:11:02 +02:00
|
|
|
if ($this->last_good_run === null) {
|
2017-02-18 19:41:27 +01:00
|
|
|
$cache_directory = Config::getInstance()->getCacheDirectory();
|
|
|
|
|
2018-10-17 17:03:32 +02:00
|
|
|
if (file_exists($cache_directory . DIRECTORY_SEPARATOR . self::GOOD_RUN_NAME)) {
|
|
|
|
$this->last_good_run = filemtime($cache_directory . DIRECTORY_SEPARATOR . self::GOOD_RUN_NAME);
|
|
|
|
} else {
|
|
|
|
$this->last_good_run = 0;
|
|
|
|
}
|
2017-02-18 19:41:27 +01:00
|
|
|
}
|
|
|
|
|
2017-07-25 22:11:02 +02:00
|
|
|
return $this->last_good_run;
|
2017-02-18 19:41:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param float $time_before
|
2017-05-27 02:16:18 +02:00
|
|
|
*
|
2017-02-18 19:41:27 +01:00
|
|
|
* @return int
|
|
|
|
*/
|
2017-07-25 22:11:02 +02:00
|
|
|
public function deleteOldParserCaches($time_before)
|
2017-02-18 19:41:27 +01:00
|
|
|
{
|
|
|
|
$cache_directory = Config::getInstance()->getCacheDirectory();
|
|
|
|
|
|
|
|
if ($cache_directory) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
$removed_count = 0;
|
|
|
|
|
|
|
|
$cache_directory .= DIRECTORY_SEPARATOR . self::PARSER_CACHE_DIRECTORY;
|
|
|
|
|
|
|
|
if (is_dir($cache_directory)) {
|
|
|
|
$directory_files = scandir($cache_directory);
|
|
|
|
|
|
|
|
foreach ($directory_files as $directory_file) {
|
|
|
|
$full_path = $cache_directory . DIRECTORY_SEPARATOR . $directory_file;
|
|
|
|
|
|
|
|
if ($directory_file[0] === '.') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (filemtime($full_path) < $time_before && is_writable($full_path)) {
|
|
|
|
unlink($full_path);
|
2017-05-27 02:05:57 +02:00
|
|
|
++$removed_count;
|
2017-02-18 19:41:27 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $removed_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array<string> $file_names
|
|
|
|
* @param int $min_time
|
2017-05-27 02:16:18 +02:00
|
|
|
*
|
2017-02-18 19:41:27 +01:00
|
|
|
* @return void
|
|
|
|
*/
|
2017-07-25 22:11:02 +02:00
|
|
|
public function touchParserCaches(array $file_names, $min_time)
|
2017-02-18 19:41:27 +01:00
|
|
|
{
|
|
|
|
$cache_directory = Config::getInstance()->getCacheDirectory();
|
|
|
|
|
|
|
|
if (!$cache_directory) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$cache_directory .= DIRECTORY_SEPARATOR . self::PARSER_CACHE_DIRECTORY;
|
|
|
|
|
|
|
|
if (is_dir($cache_directory)) {
|
|
|
|
foreach ($file_names as $file_name) {
|
2018-10-16 21:59:11 +02:00
|
|
|
$hash_file_name = $cache_directory . DIRECTORY_SEPARATOR . $this->getParserCacheKey($file_name);
|
2017-02-18 19:41:27 +01:00
|
|
|
|
|
|
|
if (file_exists($hash_file_name)) {
|
|
|
|
if (filemtime($hash_file_name) < $min_time) {
|
|
|
|
touch($hash_file_name, $min_time);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-02-19 17:14:07 +01:00
|
|
|
* @param string $file_name
|
2017-05-27 02:16:18 +02:00
|
|
|
*
|
2017-02-18 19:41:27 +01:00
|
|
|
* @return string
|
|
|
|
*/
|
2018-10-16 21:59:11 +02:00
|
|
|
private function getParserCacheKey($file_name)
|
2017-02-18 19:41:27 +01:00
|
|
|
{
|
2018-10-16 21:59:11 +02:00
|
|
|
return md5($file_name) . ($this->use_igbinary ? '-igbinary' : '') . '-r';
|
2017-02-18 19:41:27 +01:00
|
|
|
}
|
|
|
|
}
|