Merge branch '4.2'

* 4.2:
  Fix Cache error while using anonymous class
  [Cache] fix LockRegistry
  Update validators.cs.xlf
  Make translations consistent with other translations.
  Correct language code for ukrainian language in security translations.
  Fix return type of Request::getRequestFormat
  [Cache] Fix perf when using RedisCluster by reducing roundtrips to the servers
This commit is contained in:
Nicolas Grekas 2019-03-15 14:38:03 +01:00
commit b7e798ef74
8 changed files with 76 additions and 32 deletions

View File

@ -23,7 +23,7 @@ use Symfony\Contracts\Cache\ItemInterface;
*
* @author Nicolas Grekas <p@tchwork.com>
*/
class LockRegistry
final class LockRegistry
{
private static $openedFiles = [];
private static $lockedFiles = [];
@ -75,7 +75,7 @@ class LockRegistry
return $previousFiles;
}
public static function compute(callable $callback, ItemInterface $item, bool &$save, CacheInterface $pool)
public static function compute(callable $callback, ItemInterface $item, bool &$save, CacheInterface $pool, \Closure $setMetadata = null)
{
$key = self::$files ? crc32($item->getKey()) % \count(self::$files) : -1;
@ -89,7 +89,18 @@ class LockRegistry
if (flock($lock, LOCK_EX | LOCK_NB)) {
self::$lockedFiles[$key] = true;
return $callback($item, $save);
$value = $callback($item, $save);
if ($save) {
if ($setMetadata) {
$setMetadata($item);
}
$pool->save($item->set($value));
$save = false;
}
return $value;
}
// if we failed the race, retry locking in blocking mode to wait for the winner
flock($lock, LOCK_SH);
@ -126,6 +137,6 @@ class LockRegistry
restore_error_handler();
}
self::$openedFiles[$key] = $h ?: @fopen(self::$files[$key], 'r');
return self::$openedFiles[$key] = $h ?: @fopen(self::$files[$key], 'r');
}
}

View File

@ -40,7 +40,7 @@ trait ContractsTrait
public function setCallbackWrapper(?callable $callbackWrapper): callable
{
$previousWrapper = $this->callbackWrapper;
$this->callbackWrapper = $callbackWrapper ?? function (callable $callback, ItemInterface $item, bool &$save, CacheInterface $pool) {
$this->callbackWrapper = $callbackWrapper ?? function (callable $callback, ItemInterface $item, bool &$save, CacheInterface $pool, \Closure $setMetadata) {
return $callback($item, $save);
};
@ -56,17 +56,19 @@ trait ContractsTrait
static $setMetadata;
$setMetadata = $setMetadata ?? \Closure::bind(
function (AdapterInterface $pool, ItemInterface $item, float $startTime) {
function (CacheItem $item, float $startTime, ?array &$metadata) {
if ($item->expiry > $endTime = microtime(true)) {
$item->newMetadata[ItemInterface::METADATA_EXPIRY] = $item->expiry;
$item->newMetadata[ItemInterface::METADATA_CTIME] = 1000 * (int) ($endTime - $startTime);
$item->newMetadata[CacheItem::METADATA_EXPIRY] = $metadata[CacheItem::METADATA_EXPIRY] = $item->expiry;
$item->newMetadata[CacheItem::METADATA_CTIME] = $metadata[CacheItem::METADATA_CTIME] = 1000 * (int) ($endTime - $startTime);
} else {
unset($metadata[CacheItem::METADATA_EXPIRY], $metadata[CacheItem::METADATA_CTIME]);
}
},
null,
CacheItem::class
);
return $this->contractsGet($pool, $key, function (CacheItem $item, bool &$save) use ($pool, $callback, $setMetadata) {
return $this->contractsGet($pool, $key, function (CacheItem $item, bool &$save) use ($pool, $callback, $setMetadata, &$metadata) {
// don't wrap nor save recursive calls
if (null === $callbackWrapper = $this->callbackWrapper) {
$value = $callback($item, $save);
@ -78,8 +80,10 @@ trait ContractsTrait
$startTime = microtime(true);
try {
$value = $callbackWrapper($callback, $item, $save, $pool);
$setMetadata($pool, $item, $startTime);
$value = $callbackWrapper($callback, $item, $save, $pool, function (CacheItem $item) use ($setMetadata, $startTime, &$metadata) {
$setMetadata($item, $startTime, $metadata);
});
$setMetadata($item, $startTime, $metadata);
return $value;
} finally {

View File

@ -1330,7 +1330,7 @@ class Request
*
* @param string|null $default The default format
*
* @return string The request format
* @return string|null The request format
*/
public function getRequestFormat($default = 'html')
{

View File

@ -66,6 +66,11 @@ class Psr6Cache implements CacheInterface
*/
private function escapeClassName(string $class): string
{
if (false !== strpos($class, '@')) {
// anonymous class: replace all PSR6-reserved characters
return str_replace(["\0", '\\', '/', '@', ':', '{', '}', '(', ')'], '.', $class);
}
return str_replace('\\', '.', $class);
}
}

View File

@ -36,23 +36,23 @@
</trans-unit>
<trans-unit id="9">
<source>This field was not expected.</source>
<target>Това поле не се е очаквало.</target>
<target>Полето не се е очаквало.</target>
</trans-unit>
<trans-unit id="10">
<source>This field is missing.</source>
<target>Това поле липсва.</target>
<target>Полето липсва.</target>
</trans-unit>
<trans-unit id="11">
<source>This value is not a valid date.</source>
<target>Стойността не е валидна дата (date).</target>
<target>Стойността не е валидна дата.</target>
</trans-unit>
<trans-unit id="12">
<source>This value is not a valid datetime.</source>
<target>Стойността не е валидна дата (datetime).</target>
<target>Стойността не е валидна дата и час.</target>
</trans-unit>
<trans-unit id="13">
<source>This value is not a valid email address.</source>
<target>Стойността не е валиден email адрес.</target>
<target>Стойността не е валиден имейл адрес.</target>
</trans-unit>
<trans-unit id="14">
<source>The file could not be found.</source>
@ -68,7 +68,7 @@
</trans-unit>
<trans-unit id="17">
<source>The mime type of the file is invalid ({{ type }}). Allowed mime types are {{ types }}.</source>
<target>Майм типа на файла е невалиден ({{ type }}). Разрешени майм типове са {{ types }}.</target>
<target>Mime типа на файла е невалиден ({{ type }}). Разрешени mime типове са {{ types }}.</target>
</trans-unit>
<trans-unit id="18">
<source>This value should be {{ limit }} or less.</source>
@ -104,7 +104,7 @@
</trans-unit>
<trans-unit id="26">
<source>This value is not a valid time.</source>
<target>Стойността не е валидно време (time).</target>
<target>Стойността не е валидно време.</target>
</trans-unit>
<trans-unit id="27">
<source>This value is not a valid URL.</source>
@ -216,35 +216,35 @@
</trans-unit>
<trans-unit id="57">
<source>Invalid card number.</source>
<target>Невалиден номер на картата.</target>
<target>Невалиден номер на карта.</target>
</trans-unit>
<trans-unit id="58">
<source>Unsupported card type or invalid card number.</source>
<target>Неподдържан тип карта или невалиден номер на картата.</target>
<target>Неподдържан тип карта или невалиден номер на карта.</target>
</trans-unit>
<trans-unit id="59">
<source>This is not a valid International Bank Account Number (IBAN).</source>
<target>Невалиден Международен номер на банкова сметка (IBAN).</target>
<target>Това не е валиден Международен номер на банкова сметка (IBAN).</target>
</trans-unit>
<trans-unit id="60">
<source>This value is not a valid ISBN-10.</source>
<target>Невалиден ISBN-10.</target>
<target>Стойността не е валиден ISBN-10.</target>
</trans-unit>
<trans-unit id="61">
<source>This value is not a valid ISBN-13.</source>
<target>Невалиден ISBN-13.</target>
<target>Стойността не е валиден ISBN-13.</target>
</trans-unit>
<trans-unit id="62">
<source>This value is neither a valid ISBN-10 nor a valid ISBN-13.</source>
<target>Невалидна стойност както за ISBN-10, така и за ISBN-13 .</target>
<target>Стойността не е нито валиден ISBN-10, нито валиден ISBN-13.</target>
</trans-unit>
<trans-unit id="63">
<source>This value is not a valid ISSN.</source>
<target>Невалиден Международен стандартен сериен номер (ISSN).</target>
<target>Стойността не е валиден ISSN.</target>
</trans-unit>
<trans-unit id="64">
<source>This value is not a valid currency.</source>
<target>Невалидна валута.</target>
<target>Стойността не е валидна валута.</target>
</trans-unit>
<trans-unit id="65">
<source>This value should be equal to {{ compared_value }}.</source>
@ -308,11 +308,11 @@
</trans-unit>
<trans-unit id="80">
<source>This value does not match the expected {{ charset }} charset.</source>
<target>Стойността не съвпада с {{ charset }}.</target>
<target>Стойността не съвпада с очакваната {{ charset }} кодировка.</target>
</trans-unit>
<trans-unit id="81">
<source>This is not a valid Business Identifier Code (BIC).</source>
<target>Невалиден бизнес идентификационен код (BIC).</target>
<target>Това не е валиден Бизнес идентификационен код (BIC).</target>
</trans-unit>
<trans-unit id="82">
<source>Error</source>
@ -324,15 +324,15 @@
</trans-unit>
<trans-unit id="84">
<source>This value should be a multiple of {{ compared_value }}.</source>
<target>Тази стойност трябва да бъде кратно число на {{ compared_value }}.</target>
<target>Стойността трябва да бъде кратно число на {{ compared_value }}.</target>
</trans-unit>
<trans-unit id="85">
<source>This Business Identifier Code (BIC) is not associated with IBAN {{ iban }}.</source>
<target>Този бизнес идентификационен код (BIC) не е свързана с IBAN {{ iban }}.</target>
<target>Бизнес идентификационния код (BIC) не е свързан с IBAN {{ iban }}.</target>
</trans-unit>
<trans-unit id="86">
<source>This value should be valid JSON.</source>
<target>Тази стойност трябва да е валидна JSON.</target>
<target>Стойността трябва да е валиден JSON.</target>
</trans-unit>
</body>
</file>

View File

@ -318,6 +318,22 @@
<source>Error</source>
<target>Chyba</target>
</trans-unit>
<trans-unit id="83">
<source>This is not a valid UUID.</source>
<target>Tato hodnota není platné UUID.</target>
</trans-unit>
<trans-unit id="84">
<source>This value should be a multiple of {{ compared_value }}.</source>
<target>Tato hodnota musí být násobek hodnoty {{ compared_value }}.</target>
</trans-unit>
<trans-unit id="85">
<source>This Business Identifier Code (BIC) is not associated with IBAN {{ iban }}.</source>
<target>Bankovní identifikační kód (BIC) neodpovídá mezinárodnímu číslu účtu (IBAN) {{ iban }}.</target>
</trans-unit>
<trans-unit id="86">
<source>This value should be valid JSON.</source>
<target>Tato hodnota musí být validní JSON.</target>
</trans-unit>
</body>
</file>
</xliff>

View File

@ -23,4 +23,12 @@ class Psr6CacheTest extends AbstractCacheTest
$this->cache->write($metadata);
$this->assertFalse($this->cache->has('Foo_Bar'));
}
public function testNameWithInvalidChars()
{
$metadata = new ClassMetadata('class@anonymous/path/file');
$this->cache->write($metadata);
$this->assertTrue($this->cache->has('class@anonymous/path/file'));
}
}