1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Make igbinary the default serializer

Fix #484 and fix #527
This commit is contained in:
Matthew Brown 2018-02-19 11:14:07 -05:00
parent 81fd016120
commit 634375ae94
7 changed files with 50 additions and 15 deletions

View File

@ -37,6 +37,9 @@
"squizlabs/php_codesniffer": "^3.0",
"php-coveralls/php-coveralls": "^2.0"
},
"suggest": {
"ext-igbinary": "2"
},
"scripts": {
"psalm": "./psalm",
"standards": "php ./vendor/friendsofphp/php-cs-fixer/php-cs-fixer fix --verbose --allow-risky=yes",

View File

@ -428,6 +428,8 @@ class Config
if (isset($config_xml['serializer'])) {
$attribute_text = (string) $config_xml['serializer'];
$config->use_igbinary = $attribute_text === 'igbinary';
} elseif ($igbinary_version = phpversion('igbinary')) {
$config->use_igbinary = version_compare($igbinary_version, '2.0.5') >= 0;
}
if (isset($config_xml['allowPhpStormGenerics'])) {

View File

@ -51,7 +51,11 @@ class ClassLikeStorageCacheProvider
$cache_location = $this->getCacheLocationForClass($fq_classlike_name_lc, true);
$storage->hash = $this->getCacheHash($file_path, $file_contents);
file_put_contents($cache_location, serialize($storage));
if ($this->config->use_igbinary) {
file_put_contents($cache_location, igbinary_serialize($storage));
} else {
file_put_contents($cache_location, serialize($storage));
}
}
/**
@ -101,8 +105,13 @@ class ClassLikeStorageCacheProvider
$cache_location = $this->getCacheLocationForClass($fq_classlike_name_lc);
if (file_exists($cache_location)) {
/** @var ClassLikeStorage */
return unserialize((string)file_get_contents($cache_location)) ?: null;
if ($this->config->use_igbinary) {
/** @var ClassLikeStorage */
return igbinary_unserialize((string)file_get_contents($cache_location)) ?: null;
} else {
/** @var ClassLikeStorage */
return unserialize((string)file_get_contents($cache_location)) ?: null;
}
}
return null;
@ -128,6 +137,9 @@ class ClassLikeStorageCacheProvider
mkdir($parser_cache_directory, 0777, true);
}
return $parser_cache_directory . DIRECTORY_SEPARATOR . sha1($fq_classlike_name_lc);
return $parser_cache_directory
. DIRECTORY_SEPARATOR
. sha1($fq_classlike_name_lc)
. ($this->config->use_igbinary ? '-igbinary' : '');
}
}

View File

@ -50,7 +50,11 @@ class FileStorageCacheProvider
$cache_location = $this->getCacheLocationForPath($file_path, true);
$storage->hash = $this->getCacheHash($file_path, $file_contents);
file_put_contents($cache_location, serialize($storage));
if ($this->config->use_igbinary) {
file_put_contents($cache_location, igbinary_serialize($storage));
} else {
file_put_contents($cache_location, serialize($storage));
}
}
/**
@ -99,8 +103,13 @@ class FileStorageCacheProvider
$cache_location = $this->getCacheLocationForPath($file_path);
if (file_exists($cache_location)) {
/** @var FileStorage */
return unserialize((string)file_get_contents($cache_location)) ?: null;
if ($this->config->use_igbinary) {
/** @var FileStorage */
return igbinary_unserialize((string)file_get_contents($cache_location)) ?: null;
} else {
/** @var FileStorage */
return unserialize((string)file_get_contents($cache_location)) ?: null;
}
}
return null;
@ -126,6 +135,9 @@ class FileStorageCacheProvider
mkdir($parser_cache_directory, 0777, true);
}
return $parser_cache_directory . DIRECTORY_SEPARATOR . sha1($file_path);
return $parser_cache_directory
. DIRECTORY_SEPARATOR
. sha1($file_path)
. ($this->config->use_igbinary ? '-igbinary' : '');
}
}

View File

@ -244,7 +244,8 @@ class ParserCacheProvider
if (is_dir($cache_directory)) {
foreach ($file_names as $file_name) {
$hash_file_name = $cache_directory . DIRECTORY_SEPARATOR . $this->getParserCacheKey($file_name);
$hash_file_name =
$cache_directory . DIRECTORY_SEPARATOR . $this->getParserCacheKey($file_name, $this->use_igbinary);
if (file_exists($hash_file_name)) {
if (filemtime($hash_file_name) < $min_time) {
@ -256,12 +257,13 @@ class ParserCacheProvider
}
/**
* @param string $file_name
* @param string $file_name
* @param bool $use_igbinary
*
* @return string
*/
public static function getParserCacheKey($file_name)
public static function getParserCacheKey($file_name, $use_igbinary)
{
return md5($file_name);
return md5($file_name) . ($use_igbinary ? '-igbinary' : '');
}
}

View File

@ -42,7 +42,7 @@ class StatementsProvider
$modified_time = $this->file_provider->getModifiedTime($file_path);
$file_content_hash = md5($version . $file_contents);
$file_cache_key = $this->cache_provider->getParserCacheKey($file_path);
$file_cache_key = $this->cache_provider->getParserCacheKey($file_path, $this->cache_provider->use_igbinary);
$stmts = $this->cache_provider->loadStatementsFromCache(
$modified_time,

View File

@ -268,9 +268,13 @@ if ($path_to_config) {
$config = Config::getConfigForPath($current_dir, $current_dir, $output_format);
}
$file_storage_cache_provider = new Psalm\Provider\NoCache\NoFileStorageCacheProvider();
$file_storage_cache_provider = isset($options['no-cache'])
? new Psalm\Provider\NoCache\NoFileStorageCacheProvider()
: new Psalm\Provider\FileStorageCacheProvider($config);
$classlike_storage_cache_provider = new Psalm\Provider\NoCache\NoClassLikeStorageCacheProvider();
$classlike_storage_cache_provider = isset($options['no-cache'])
? new Psalm\Provider\NoCache\NoClassLikeStorageCacheProvider()
: new Psalm\Provider\ClassLikeStorageCacheProvider($config);
if (isset($options['clear-cache'])) {
$cache_directory = $config->getCacheDirectory();