From 5892837641956cdb746174146feb1cc67a7621c6 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Wed, 7 Aug 2019 17:07:08 +0200 Subject: [PATCH 1/4] Resilience against file_get_contents() race conditions. --- src/Symfony/Component/HttpKernel/HttpCache/Store.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpKernel/HttpCache/Store.php b/src/Symfony/Component/HttpKernel/HttpCache/Store.php index 9533cf637c..c831ba2ac3 100644 --- a/src/Symfony/Component/HttpKernel/HttpCache/Store.php +++ b/src/Symfony/Component/HttpKernel/HttpCache/Store.php @@ -356,7 +356,7 @@ class Store implements StoreInterface { $path = $this->getPath($key); - return file_exists($path) ? file_get_contents($path) : null; + return file_exists($path) && false !== ($contents = file_get_contents($path)) ? $contents : null; } /** From 63b71b5ade977f2b2f34b6db5af0b6a0cb296260 Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Wed, 7 Aug 2019 18:29:13 +0200 Subject: [PATCH 2/4] [Intl] fix nullable phpdocs and useless method visibility of internal class --- .../Component/Intl/Collator/Collator.php | 4 +-- .../DateFormat/FullTransformer.php | 29 ++++++------------- .../Intl/DateFormatter/IntlDateFormatter.php | 4 +-- .../Intl/NumberFormatter/NumberFormatter.php | 14 ++++----- 4 files changed, 20 insertions(+), 31 deletions(-) diff --git a/src/Symfony/Component/Intl/Collator/Collator.php b/src/Symfony/Component/Intl/Collator/Collator.php index 62b1ddc995..a87e0eb228 100644 --- a/src/Symfony/Component/Intl/Collator/Collator.php +++ b/src/Symfony/Component/Intl/Collator/Collator.php @@ -70,7 +70,7 @@ class Collator const SORT_STRING = 1; /** - * @param string $locale The locale code. The only currently supported locale is "en" (or null using the default locale, i.e. "en") + * @param string|null $locale The locale code. The only currently supported locale is "en" (or null using the default locale, i.e. "en") * * @throws MethodArgumentValueNotImplementedException When $locale different than "en" or null is passed */ @@ -84,7 +84,7 @@ class Collator /** * Static constructor. * - * @param string $locale The locale code. The only currently supported locale is "en" (or null using the default locale, i.e. "en") + * @param string|null $locale The locale code. The only currently supported locale is "en" (or null using the default locale, i.e. "en") * * @return self * diff --git a/src/Symfony/Component/Intl/DateFormatter/DateFormat/FullTransformer.php b/src/Symfony/Component/Intl/DateFormatter/DateFormat/FullTransformer.php index 13854ff719..6edae72fc3 100644 --- a/src/Symfony/Component/Intl/DateFormatter/DateFormat/FullTransformer.php +++ b/src/Symfony/Component/Intl/DateFormatter/DateFormat/FullTransformer.php @@ -69,16 +69,6 @@ class FullTransformer ]; } - /** - * Return the array of Transformer objects. - * - * @return Transformer[] Associative array of Transformer objects (format char => Transformer) - */ - public function getTransformers() - { - return $this->transformers; - } - /** * Format a DateTime using ICU dateformat pattern. * @@ -105,7 +95,7 @@ class FullTransformer * * @throws NotImplementedException When it encounters a not implemented date character */ - public function formatReplace($dateChars, $dateTime) + private function formatReplace($dateChars, \DateTime $dateTime) { $length = \strlen($dateChars); @@ -172,7 +162,7 @@ class FullTransformer * @return string The reverse matching regular expression with named captures being formed by the * transformer index in the $transformer array */ - public function getReverseMatchingRegExp($pattern) + private function getReverseMatchingRegExp($pattern) { $escapedPattern = preg_quote($pattern, '/'); @@ -189,9 +179,8 @@ class FullTransformer return $this->replaceQuoteMatch($dateChars); } - $transformers = $this->getTransformers(); - if (isset($transformers[$transformerIndex])) { - $transformer = $transformers[$transformerIndex]; + if (isset($this->transformers[$transformerIndex])) { + $transformer = $this->transformers[$transformerIndex]; $captureName = str_repeat($transformerIndex, $length); return "(?P<$captureName>".$transformer->getReverseMatchingRegExp($length).')'; @@ -208,7 +197,7 @@ class FullTransformer * * @return bool true if matches, false otherwise */ - public function isQuoteMatch($quoteMatch) + private function isQuoteMatch($quoteMatch) { return "'" === $quoteMatch[0]; } @@ -220,7 +209,7 @@ class FullTransformer * * @return string A string with the single quotes replaced */ - public function replaceQuoteMatch($quoteMatch) + private function replaceQuoteMatch($quoteMatch) { if (preg_match("/^'+$/", $quoteMatch)) { return str_replace("''", "'", $quoteMatch); @@ -236,7 +225,7 @@ class FullTransformer * * @return string The chars match regular expression */ - protected function buildCharsMatch($specialChars) + private function buildCharsMatch($specialChars) { $specialCharsArray = str_split($specialChars); @@ -253,7 +242,7 @@ class FullTransformer * * @return array */ - protected function normalizeArray(array $data) + private function normalizeArray(array $data) { $ret = []; @@ -280,7 +269,7 @@ class FullTransformer * * @return bool|int The calculated timestamp or false if matched date is invalid */ - protected function calculateUnixTimestamp(\DateTime $dateTime, array $options) + private function calculateUnixTimestamp(\DateTime $dateTime, array $options) { $options = $this->getDefaultValueForOptions($options); diff --git a/src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php b/src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php index 197a2e3db0..c5e60aee63 100644 --- a/src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php +++ b/src/Symfony/Component/Intl/DateFormatter/IntlDateFormatter.php @@ -118,7 +118,7 @@ class IntlDateFormatter private $timeZoneId; /** - * @param string $locale The locale code. The only currently supported locale is "en" (or null using the default locale, i.e. "en") + * @param string|null $locale The locale code. The only currently supported locale is "en" (or null using the default locale, i.e. "en") * @param int|null $datetype Type of date formatting, one of the format type constants * @param int|null $timetype Type of time formatting, one of the format type constants * @param \IntlTimeZone|\DateTimeZone|string|null $timezone Timezone identifier @@ -152,7 +152,7 @@ class IntlDateFormatter /** * Static constructor. * - * @param string $locale The locale code. The only currently supported locale is "en" (or null using the default locale, i.e. "en") + * @param string|null $locale The locale code. The only currently supported locale is "en" (or null using the default locale, i.e. "en") * @param int|null $datetype Type of date formatting, one of the format type constants * @param int|null $timetype Type of time formatting, one of the format type constants * @param \IntlTimeZone|\DateTimeZone|string|null $timezone Timezone identifier diff --git a/src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php b/src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php index 9ba821eac8..5c31bdf554 100644 --- a/src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php +++ b/src/Symfony/Component/Intl/NumberFormatter/NumberFormatter.php @@ -241,13 +241,13 @@ class NumberFormatter ]; /** - * @param string $locale The locale code. The only currently supported locale is "en" (or null using the default locale, i.e. "en") - * @param int $style Style of the formatting, one of the format style constants. - * The only supported styles are NumberFormatter::DECIMAL - * and NumberFormatter::CURRENCY. - * @param string $pattern Not supported. A pattern string in case $style is NumberFormat::PATTERN_DECIMAL or - * NumberFormat::PATTERN_RULEBASED. It must conform to the syntax - * described in the ICU DecimalFormat or ICU RuleBasedNumberFormat documentation + * @param string|null $locale The locale code. The only currently supported locale is "en" (or null using the default locale, i.e. "en") + * @param int $style Style of the formatting, one of the format style constants. + * The only supported styles are NumberFormatter::DECIMAL + * and NumberFormatter::CURRENCY. + * @param string $pattern Not supported. A pattern string in case $style is NumberFormat::PATTERN_DECIMAL or + * NumberFormat::PATTERN_RULEBASED. It must conform to the syntax + * described in the ICU DecimalFormat or ICU RuleBasedNumberFormat documentation * * @see http://www.php.net/manual/en/numberformatter.create.php * @see http://www.icu-project.org/apiref/icu4c/classDecimalFormat.html#_details From 4ee54f0e84cb1a7ecc52264c4a7665d50c492601 Mon Sep 17 00:00:00 2001 From: Thomas Calvet Date: Thu, 8 Aug 2019 08:39:07 +0200 Subject: [PATCH 3/4] [HttpKernel] Clarify error handler restoring process again --- src/Symfony/Component/HttpKernel/Kernel.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 9e283b4771..6d71214f1b 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -597,10 +597,9 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl return; } - if ($this->debug) { + if ($collectDeprecations = $this->debug && !\defined('PHPUNIT_COMPOSER_INSTALL')) { $collectedLogs = []; - $previousHandler = \defined('PHPUNIT_COMPOSER_INSTALL'); - $previousHandler = $previousHandler ?: set_error_handler(function ($type, $message, $file, $line) use (&$collectedLogs, &$previousHandler) { + $previousHandler = set_error_handler(function ($type, $message, $file, $line) use (&$collectedLogs, &$previousHandler) { if (E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type) { return $previousHandler ? $previousHandler($type, $message, $file, $line) : false; } @@ -636,7 +635,7 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl $container = $this->buildContainer(); $container->compile(); } finally { - if ($this->debug && true !== $previousHandler) { + if ($collectDeprecations) { restore_error_handler(); file_put_contents($cacheDir.'/'.$class.'Deprecations.log', serialize(array_values($collectedLogs))); From 12b8c942eb0eedab0a960bd473102f145e7bef44 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Thu, 8 Aug 2019 08:47:22 +0200 Subject: [PATCH 4/4] consistently throw NotSupportException --- src/Symfony/Component/Lock/Store/CombinedStore.php | 2 +- src/Symfony/Component/Lock/Store/MemcachedStore.php | 3 ++- src/Symfony/Component/Lock/Store/RedisStore.php | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Lock/Store/CombinedStore.php b/src/Symfony/Component/Lock/Store/CombinedStore.php index 6038b3be93..01c8785d01 100644 --- a/src/Symfony/Component/Lock/Store/CombinedStore.php +++ b/src/Symfony/Component/Lock/Store/CombinedStore.php @@ -94,7 +94,7 @@ class CombinedStore implements StoreInterface, LoggerAwareInterface public function waitAndSave(Key $key) { - throw new NotSupportedException(sprintf('The store "%s" does not supports blocking locks.', \get_class($this))); + throw new NotSupportedException(sprintf('The store "%s" does not support blocking locks.', \get_class($this))); } /** diff --git a/src/Symfony/Component/Lock/Store/MemcachedStore.php b/src/Symfony/Component/Lock/Store/MemcachedStore.php index 7a51d6149b..2ad920313d 100644 --- a/src/Symfony/Component/Lock/Store/MemcachedStore.php +++ b/src/Symfony/Component/Lock/Store/MemcachedStore.php @@ -13,6 +13,7 @@ namespace Symfony\Component\Lock\Store; use Symfony\Component\Lock\Exception\InvalidArgumentException; use Symfony\Component\Lock\Exception\LockConflictedException; +use Symfony\Component\Lock\Exception\NotSupportedException; use Symfony\Component\Lock\Key; use Symfony\Component\Lock\StoreInterface; @@ -70,7 +71,7 @@ class MemcachedStore implements StoreInterface public function waitAndSave(Key $key) { - throw new InvalidArgumentException(sprintf('The store "%s" does not supports blocking locks.', \get_class($this))); + throw new NotSupportedException(sprintf('The store "%s" does not support blocking locks.', \get_class($this))); } /** diff --git a/src/Symfony/Component/Lock/Store/RedisStore.php b/src/Symfony/Component/Lock/Store/RedisStore.php index 6070c2e74e..6ad47a3337 100644 --- a/src/Symfony/Component/Lock/Store/RedisStore.php +++ b/src/Symfony/Component/Lock/Store/RedisStore.php @@ -14,6 +14,7 @@ namespace Symfony\Component\Lock\Store; use Symfony\Component\Cache\Traits\RedisProxy; use Symfony\Component\Lock\Exception\InvalidArgumentException; use Symfony\Component\Lock\Exception\LockConflictedException; +use Symfony\Component\Lock\Exception\NotSupportedException; use Symfony\Component\Lock\Key; use Symfony\Component\Lock\StoreInterface; @@ -72,7 +73,7 @@ class RedisStore implements StoreInterface public function waitAndSave(Key $key) { - throw new InvalidArgumentException(sprintf('The store "%s" does not supports blocking locks.', \get_class($this))); + throw new NotSupportedException(sprintf('The store "%s" does not support blocking locks.', \get_class($this))); } /**