mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 10:38:45 +02:00
migration symfony 5 4 (#300)
* symfony 5.4 (diff dev) * symfony 5.4 (working) * symfony 5.4 (update autoload) * symfony 5.4 (remove swiftmailer mailer implementation) * symfony 5.4 (php doc and split Global accessor class) ### Impacted packages: composer require php:">=7.2.5 <8.0.0" symfony/console:5.4.* symfony/dotenv:5.4.* symfony/framework-bundle:5.4.* symfony/twig-bundle:5.4.* symfony/yaml:5.4.* --update-with-dependencies composer require symfony/stopwatch:5.4.* symfony/web-profiler-bundle:5.4.* --dev --update-with-dependencies
This commit is contained in:
@@ -29,15 +29,15 @@ class ResourceCheckerConfigCache implements ConfigCacheInterface
|
||||
private $file;
|
||||
|
||||
/**
|
||||
* @var iterable|ResourceCheckerInterface[]
|
||||
* @var iterable<mixed, ResourceCheckerInterface>
|
||||
*/
|
||||
private $resourceCheckers;
|
||||
|
||||
/**
|
||||
* @param string $file The absolute cache path
|
||||
* @param iterable|ResourceCheckerInterface[] $resourceCheckers The ResourceCheckers to use for the freshness check
|
||||
* @param string $file The absolute cache path
|
||||
* @param iterable<mixed, ResourceCheckerInterface> $resourceCheckers The ResourceCheckers to use for the freshness check
|
||||
*/
|
||||
public function __construct($file, $resourceCheckers = [])
|
||||
public function __construct(string $file, iterable $resourceCheckers = [])
|
||||
{
|
||||
$this->file = $file;
|
||||
$this->resourceCheckers = $resourceCheckers;
|
||||
@@ -60,7 +60,7 @@ class ResourceCheckerConfigCache implements ConfigCacheInterface
|
||||
* The first ResourceChecker that supports a given resource is considered authoritative.
|
||||
* Resources with no matching ResourceChecker will silently be ignored and considered fresh.
|
||||
*
|
||||
* @return bool true if the cache is fresh, false otherwise
|
||||
* @return bool
|
||||
*/
|
||||
public function isFresh()
|
||||
{
|
||||
@@ -91,7 +91,6 @@ class ResourceCheckerConfigCache implements ConfigCacheInterface
|
||||
$time = filemtime($this->file);
|
||||
|
||||
foreach ($meta as $resource) {
|
||||
/* @var ResourceInterface $resource */
|
||||
foreach ($this->resourceCheckers as $checker) {
|
||||
if (!$checker->supports($resource)) {
|
||||
continue; // next checker
|
||||
@@ -116,7 +115,7 @@ class ResourceCheckerConfigCache implements ConfigCacheInterface
|
||||
*
|
||||
* @throws \RuntimeException When cache file can't be written
|
||||
*/
|
||||
public function write($content, array $metadata = null)
|
||||
public function write(string $content, array $metadata = null)
|
||||
{
|
||||
$mode = 0666;
|
||||
$umask = umask();
|
||||
@@ -144,21 +143,18 @@ class ResourceCheckerConfigCache implements ConfigCacheInterface
|
||||
|
||||
/**
|
||||
* Gets the meta file path.
|
||||
*
|
||||
* @return string The meta file path
|
||||
*/
|
||||
private function getMetaFile()
|
||||
private function getMetaFile(): string
|
||||
{
|
||||
return $this->file.'.meta';
|
||||
}
|
||||
|
||||
private function safelyUnserialize($file)
|
||||
private function safelyUnserialize(string $file)
|
||||
{
|
||||
$e = null;
|
||||
$meta = false;
|
||||
$content = file_get_contents($file);
|
||||
$signalingException = new \UnexpectedValueException();
|
||||
$prevUnserializeHandler = ini_set('unserialize_callback_func', '');
|
||||
$prevUnserializeHandler = ini_set('unserialize_callback_func', self::class.'::handleUnserializeCallback');
|
||||
$prevErrorHandler = set_error_handler(function ($type, $msg, $file, $line, $context = []) use (&$prevErrorHandler, $signalingException) {
|
||||
if (__FILE__ === $file) {
|
||||
throw $signalingException;
|
||||
@@ -169,15 +165,23 @@ class ResourceCheckerConfigCache implements ConfigCacheInterface
|
||||
|
||||
try {
|
||||
$meta = unserialize($content);
|
||||
} catch (\Error $e) {
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
restore_error_handler();
|
||||
ini_set('unserialize_callback_func', $prevUnserializeHandler);
|
||||
if (null !== $e && $e !== $signalingException) {
|
||||
throw $e;
|
||||
} catch (\Throwable $e) {
|
||||
if ($e !== $signalingException) {
|
||||
throw $e;
|
||||
}
|
||||
} finally {
|
||||
restore_error_handler();
|
||||
ini_set('unserialize_callback_func', $prevUnserializeHandler);
|
||||
}
|
||||
|
||||
return $meta;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public static function handleUnserializeCallback(string $class)
|
||||
{
|
||||
trigger_error('Class not found: '.$class);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user