Merge branch '4.3' into 4.4

* 4.3:
  Fixed #35084
  Add missing use statement
  [HttpClient] fix scheduling pending NativeResponse
  do not overwrite variable value
  [Profiler] wording
  Use spaces correctly to display options in DebugCommand
  X-Accel Nginx URL updated
  ticket-30197 [Validator] Add the missing translations for the Chinese (Taiwan) ("zh_TW") locale
  Fixed test added in #35022
  Use locale_parse for computing fallback locales
  [Console] Fix filtering out identical alternatives when there is a command loader
This commit is contained in:
Nicolas Grekas 2019-12-28 16:00:14 +01:00
commit 47f7cdc848
15 changed files with 181 additions and 58 deletions

View File

@ -4,7 +4,7 @@
'no_token' : { 'no_token' : {
status: 'error', status: 'error',
title: (token|default('') == 'latest') ? 'There are no profiles' : 'Token not found', title: (token|default('') == 'latest') ? 'There are no profiles' : 'Token not found',
message: (token|default('') == 'latest') ? 'No profiles found in the database.' : 'Token "' ~ token|default('') ~ '" was not found in the database.' message: (token|default('') == 'latest') ? 'No profiles found.' : 'Token "' ~ token|default('') ~ '" not found.'
} }
} %} } %}

View File

@ -55,7 +55,7 @@ class CachePoolPass implements CompilerPassInterface
} }
$seed .= '.'.$container->getParameter('kernel.container_class'); $seed .= '.'.$container->getParameter('kernel.container_class');
$pools = []; $allPools = [];
$clearers = []; $clearers = [];
$attributes = [ $attributes = [
'provider', 'provider',
@ -163,7 +163,7 @@ class CachePoolPass implements CompilerPassInterface
$clearers[$clearer][$name] = new Reference($id, $container::IGNORE_ON_UNINITIALIZED_REFERENCE); $clearers[$clearer][$name] = new Reference($id, $container::IGNORE_ON_UNINITIALIZED_REFERENCE);
} }
$pools[$name] = new Reference($id, $container::IGNORE_ON_UNINITIALIZED_REFERENCE); $allPools[$name] = new Reference($id, $container::IGNORE_ON_UNINITIALIZED_REFERENCE);
} }
$notAliasedCacheClearerId = $this->cacheClearerId; $notAliasedCacheClearerId = $this->cacheClearerId;
@ -171,7 +171,7 @@ class CachePoolPass implements CompilerPassInterface
$this->cacheClearerId = (string) $container->getAlias($this->cacheClearerId); $this->cacheClearerId = (string) $container->getAlias($this->cacheClearerId);
} }
if ($container->hasDefinition($this->cacheClearerId)) { if ($container->hasDefinition($this->cacheClearerId)) {
$clearers[$notAliasedCacheClearerId] = $pools; $clearers[$notAliasedCacheClearerId] = $allPools;
} }
foreach ($clearers as $id => $pools) { foreach ($clearers as $id => $pools) {
@ -189,7 +189,7 @@ class CachePoolPass implements CompilerPassInterface
} }
if ($container->hasDefinition('console.command.cache_pool_list')) { if ($container->hasDefinition('console.command.cache_pool_list')) {
$container->getDefinition('console.command.cache_pool_list')->replaceArgument(0, array_keys($pools)); $container->getDefinition('console.command.cache_pool_list')->replaceArgument(0, array_keys($allPools));
} }
} }

View File

@ -673,8 +673,13 @@ class Application implements ResetInterface
// filter out aliases for commands which are already on the list // filter out aliases for commands which are already on the list
if (\count($commands) > 1) { if (\count($commands) > 1) {
$commandList = $this->commandLoader ? array_merge(array_flip($this->commandLoader->getNames()), $this->commands) : $this->commands; $commandList = $this->commandLoader ? array_merge(array_flip($this->commandLoader->getNames()), $this->commands) : $this->commands;
$commands = array_unique(array_filter($commands, function ($nameOrAlias) use ($commandList, $commands, &$aliases) { $commands = array_unique(array_filter($commands, function ($nameOrAlias) use (&$commandList, $commands, &$aliases) {
$commandName = $commandList[$nameOrAlias] instanceof Command ? $commandList[$nameOrAlias]->getName() : $nameOrAlias; if (!$commandList[$nameOrAlias] instanceof Command) {
$commandList[$nameOrAlias] = $this->commandLoader->get($nameOrAlias);
}
$commandName = $commandList[$nameOrAlias]->getName();
$aliases[$nameOrAlias] = $commandName; $aliases[$nameOrAlias] = $commandName;
return $commandName === $nameOrAlias || !\in_array($commandName, $commands); return $commandName === $nameOrAlias || !\in_array($commandName, $commands);
@ -689,10 +694,6 @@ class Application implements ResetInterface
$maxLen = max(Helper::strlen($abbrev), $maxLen); $maxLen = max(Helper::strlen($abbrev), $maxLen);
} }
$abbrevs = array_map(function ($cmd) use ($commandList, $usableWidth, $maxLen, &$commands) { $abbrevs = array_map(function ($cmd) use ($commandList, $usableWidth, $maxLen, &$commands) {
if (!$commandList[$cmd] instanceof Command) {
$commandList[$cmd] = $this->commandLoader->get($cmd);
}
if ($commandList[$cmd]->isHidden()) { if ($commandList[$cmd]->isHidden()) {
unset($commands[array_search($cmd, $commands)]); unset($commands[array_search($cmd, $commands)]);

View File

@ -626,6 +626,9 @@ class ApplicationTest extends TestCase
$fooCommand->setAliases(['foo2']); $fooCommand->setAliases(['foo2']);
$application = new Application(); $application = new Application();
$application->setCommandLoader(new FactoryCommandLoader([
'foo3' => static function () use ($fooCommand) { return $fooCommand; },
]));
$application->add($fooCommand); $application->add($fooCommand);
$result = $application->find('foo'); $result = $application->find('foo');

View File

@ -448,11 +448,14 @@ class DotenvTest extends TestCase
putenv('Foo=Bar'); putenv('Foo=Bar');
$dotenv = new Dotenv(true); $dotenv = new Dotenv(true);
try {
$values = $dotenv->parse('Foo=${Foo}'); $values = $dotenv->parse('Foo=${Foo}');
$this->assertSame('Bar', $values['Foo']); $this->assertSame('Bar', $values['Foo']);
} finally {
putenv('Foo'); putenv('Foo');
} }
}
/** /**
* @group legacy * @group legacy

View File

@ -11,8 +11,6 @@
namespace Symfony\Component\HttpClient\Internal; namespace Symfony\Component\HttpClient\Internal;
use Symfony\Component\HttpClient\Response\NativeResponse;
/** /**
* Internal representation of the native client's state. * Internal representation of the native client's state.
* *
@ -24,8 +22,6 @@ final class NativeClientState extends ClientState
{ {
/** @var int */ /** @var int */
public $id; public $id;
/** @var NativeResponse[] */
public $pendingResponses = [];
/** @var int */ /** @var int */
public $maxHostConnections = PHP_INT_MAX; public $maxHostConnections = PHP_INT_MAX;
/** @var int */ /** @var int */

View File

@ -230,11 +230,7 @@ final class NativeResponse implements ResponseInterface
$runningResponses[$i] = [$response->multi, []]; $runningResponses[$i] = [$response->multi, []];
} }
if (null === $response->remaining) {
$response->multi->pendingResponses[] = $response;
} else {
$runningResponses[$i][1][$response->id] = $response; $runningResponses[$i][1][$response->id] = $response;
}
if (null === $response->buffer) { if (null === $response->buffer) {
// Response already completed // Response already completed
@ -336,25 +332,30 @@ final class NativeResponse implements ResponseInterface
return; return;
} }
if ($multi->pendingResponses && \count($multi->handles) < $multi->maxHostConnections) { // Create empty activity lists to tell ResponseTrait::stream() we still have pending requests
foreach ($responses as $i => $response) {
if (null === $response->remaining && null !== $response->buffer) {
$multi->handlesActivity[$i] = [];
}
}
if (\count($multi->handles) >= $multi->maxHostConnections) {
return;
}
// Open the next pending request - this is a blocking operation so we do only one of them // Open the next pending request - this is a blocking operation so we do only one of them
/** @var self $response */ foreach ($responses as $i => $response) {
$response = array_shift($multi->pendingResponses); if (null === $response->remaining && null !== $response->buffer) {
$response->open(); $response->open();
$responses[$response->id] = $response;
$multi->sleep = false; $multi->sleep = false;
self::perform($response->multi); self::perform($multi);
if (null !== $response->handle) { if (null !== $response->handle) {
$multi->handles[] = $response->handle; $multi->handles[] = $response->handle;
} }
}
if ($multi->pendingResponses) { break;
// Create empty activity list to tell ResponseTrait::stream() we still have pending requests }
$response = $multi->pendingResponses[0];
$responses[$response->id] = $response;
$multi->handlesActivity[$response->id] = [];
} }
} }

View File

@ -217,7 +217,7 @@ class BinaryFileResponse extends Response
} }
if ('x-accel-redirect' === strtolower($type)) { if ('x-accel-redirect' === strtolower($type)) {
// Do X-Accel-Mapping substitutions. // Do X-Accel-Mapping substitutions.
// @link http://wiki.nginx.org/X-accel#X-Accel-Redirect // @link https://www.nginx.com/resources/wiki/start/topics/examples/x-accel/#x-accel-redirect
$parts = HeaderUtils::split($request->headers->get('X-Accel-Mapping', ''), ',='); $parts = HeaderUtils::split($request->headers->get('X-Accel-Mapping', ''), ',=');
foreach ($parts as $part) { foreach ($parts as $part) {
list($pathPrefix, $location) = $part; list($pathPrefix, $location) = $part;

View File

@ -108,9 +108,9 @@ EOF
$optionsMapping = []; $optionsMapping = [];
foreach ($options as $key => $value) { foreach ($options as $key => $value) {
$optionsMapping[] = ' '.$key.'='.$value; $optionsMapping[] = $key.'='.$value;
} }
return ' (when'.implode(', ', $optionsMapping).')'; return ' (when '.implode(', ', $optionsMapping).')';
} }
} }

View File

@ -40,7 +40,7 @@ class DebugCommandTest extends TestCase
{ {
$command = new DebugCommand([ $command = new DebugCommand([
'command_bus' => [ 'command_bus' => [
DummyCommand::class => [[DummyCommandHandler::class, []]], DummyCommand::class => [[DummyCommandHandler::class, ['option1' => '1', 'option2' => '2']]],
MultipleBusesMessage::class => [[MultipleBusesMessageHandler::class, []]], MultipleBusesMessage::class => [[MultipleBusesMessageHandler::class, []]],
], ],
'query_bus' => [ 'query_bus' => [
@ -62,12 +62,12 @@ command_bus
The following messages can be dispatched: The following messages can be dispatched:
--------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------------------
Symfony\Component\Messenger\Tests\Fixtures\DummyCommand Symfony\Component\Messenger\Tests\Fixtures\DummyCommand
handled by Symfony\Component\Messenger\Tests\Fixtures\DummyCommandHandler handled by Symfony\Component\Messenger\Tests\Fixtures\DummyCommandHandler (when option1=1, option2=2)
Symfony\Component\Messenger\Tests\Fixtures\MultipleBusesMessage Symfony\Component\Messenger\Tests\Fixtures\MultipleBusesMessage
handled by Symfony\Component\Messenger\Tests\Fixtures\MultipleBusesMessageHandler handled by Symfony\Component\Messenger\Tests\Fixtures\MultipleBusesMessageHandler
--------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------------------
query_bus query_bus
--------- ---------

View File

@ -16,6 +16,7 @@ use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\DataCollector; use Symfony\Component\HttpKernel\DataCollector\DataCollector;
use Symfony\Component\HttpKernel\DataCollector\LateDataCollectorInterface; use Symfony\Component\HttpKernel\DataCollector\LateDataCollectorInterface;
use Symfony\Component\Translation\DataCollectorTranslator; use Symfony\Component\Translation\DataCollectorTranslator;
use Symfony\Component\VarDumper\Cloner\Data;
/** /**
* @author Abdellatif Ait boudad <a.aitboudad@gmail.com> * @author Abdellatif Ait boudad <a.aitboudad@gmail.com>

View File

@ -305,15 +305,38 @@ class TranslatorTest extends TestCase
$this->assertSame('bar', $translator->trans('bar')); $this->assertSame('bar', $translator->trans('bar'));
} }
public function testTransWithFallbackLocaleBis() /**
* @dataProvider getFallbackLocales
*/
public function testTransWithFallbackLocaleBis($expectedLocale, $locale)
{ {
$translator = new Translator('en_US'); $translator = new Translator($locale);
$translator->addLoader('array', new ArrayLoader()); $translator->addLoader('array', new ArrayLoader());
$translator->addResource('array', ['foo' => 'foofoo'], 'en_US'); $translator->addResource('array', ['foo' => 'foofoo'], $locale);
$translator->addResource('array', ['bar' => 'foobar'], 'en'); $translator->addResource('array', ['bar' => 'foobar'], $expectedLocale);
$this->assertEquals('foobar', $translator->trans('bar')); $this->assertEquals('foobar', $translator->trans('bar'));
} }
public function getFallbackLocales()
{
$locales = [
['en', 'en_US'],
['en', 'en-US'],
['sl_Latn_IT', 'sl_Latn_IT_nedis'],
['sl_Latn', 'sl_Latn_IT'],
];
if (\function_exists('locale_parse')) {
$locales[] = ['sl_Latn_IT', 'sl-Latn-IT-nedis'];
$locales[] = ['sl_Latn', 'sl-Latn-IT'];
} else {
$locales[] = ['sl-Latn-IT', 'sl-Latn-IT-nedis'];
$locales[] = ['sl-Latn', 'sl-Latn-IT'];
}
return $locales;
}
public function testTransWithFallbackLocaleTer() public function testTransWithFallbackLocaleTer()
{ {
$translator = new Translator('fr_FR'); $translator = new Translator('fr_FR');

View File

@ -471,10 +471,17 @@ EOF
while ($locale) { while ($locale) {
$parent = $parentLocales[$locale] ?? null; $parent = $parentLocales[$locale] ?? null;
if (!$parent && false !== strrchr($locale, '_')) { if ($parent) {
$locale = substr($locale, 0, -\strlen(strrchr($locale, '_'))); $locale = 'root' !== $parent ? $parent : null;
} elseif ('root' !== $parent) { } elseif (\function_exists('locale_parse')) {
$locale = $parent; $localeSubTags = locale_parse($locale);
$locale = null;
if (1 < \count($localeSubTags)) {
array_pop($localeSubTags);
$locale = locale_compose($localeSubTags) ?: null;
}
} elseif ($i = strrpos($locale, '_') ?: strrpos($locale, '-')) {
$locale = substr($locale, 0, $i);
} else { } else {
$locale = null; $locale = null;
} }

View File

@ -278,6 +278,94 @@
<source>This value should not be identical to {{ compared_value_type }} {{ compared_value }}.</source> <source>This value should not be identical to {{ compared_value_type }} {{ compared_value }}.</source>
<target>該值不應與 {{ compared_value_type }} {{ compared_value }} 相同。</target> <target>該值不應與 {{ compared_value_type }} {{ compared_value }} 相同。</target>
</trans-unit> </trans-unit>
<trans-unit id="73">
<source>The image ratio is too big ({{ ratio }}). Allowed maximum ratio is {{ max_ratio }}.</source>
<target>圖像格式過大 ({{ ratio }})。 最大允許尺寸 {{ max_ratio }}。</target>
</trans-unit>
<trans-unit id="74">
<source>The image ratio is too small ({{ ratio }}). Minimum ratio expected is {{ min_ratio }}.</source>
<target>圖像格式過小 ({{ ratio }})。最小尺寸 {{ min_ratio }}。</target>
</trans-unit>
<trans-unit id="75">
<source>The image is square ({{ width }}x{{ height }}px). Square images are not allowed.</source>
<target>方形圖像 ({{ width }}x{{ height }}px)。不接受方形圖像。</target>
</trans-unit>
<trans-unit id="76">
<source>The image is landscape oriented ({{ width }}x{{ height }}px). Landscape oriented images are not allowed.</source>
<target>紀念冊布局圖像 ({{ width }}x{{ height }}px)。 不接受紀念冊布局圖像。</target>
</trans-unit>
<trans-unit id="77">
<source>The image is portrait oriented ({{ width }}x{{ height }}px). Portrait oriented images are not allowed.</source>
<target>書籍布局圖像 ({{ width }}x{{ height }}px)。不接受圖像書籍布局。</target>
</trans-unit>
<trans-unit id="78">
<source>An empty file is not allowed.</source>
<target>不接受空白文件。</target>
</trans-unit>
<trans-unit id="79">
<source>The host could not be resolved.</source>
<target>未找到服務器。</target>
</trans-unit>
<trans-unit id="80">
<source>This value does not match the expected {{ charset }} charset.</source>
<target>該數值不符合預期 {{ charset }} 符號編碼。</target>
</trans-unit>
<trans-unit id="81">
<source>This is not a valid Business Identifier Code (BIC).</source>
<target>無效企業識別碼 (BIC)。</target>
</trans-unit>
<trans-unit id="82">
<source>Error.</source>
<target>錯誤。</target>
</trans-unit>
<trans-unit id="83">
<source>This is not a valid UUID.</source>
<target>無效的通用唯壹標識符 (UUID)。</target>
</trans-unit>
<trans-unit id="84">
<source>This value should be a multiple of {{ compared_value }}.</source>
<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>
</trans-unit>
<trans-unit id="86">
<source>This value should be valid JSON.</source>
<target>該數值必須序列化為JSON格式。</target>
</trans-unit>
<trans-unit id="87">
<source>This collection should contain only unique elements.</source>
<target>該集合應僅包含唯壹元素。</target>
</trans-unit>
<trans-unit id="88">
<source>This value should be positive.</source>
<target>數值應為正數。</target>
</trans-unit>
<trans-unit id="89">
<source>This value should be either positive or zero.</source>
<target>數值應或未正數,或為零。</target>
</trans-unit>
<trans-unit id="90">
<source>This value should be negative.</source>
<target>數值應為負數。</target>
</trans-unit>
<trans-unit id="91">
<source>This value should be either negative or zero.</source>
<target>數值應或未負數,或為零。</target>
</trans-unit>
<trans-unit id="92">
<source>This value is not a valid timezone.</source>
<target>無效時區。</target>
</trans-unit>
<trans-unit id="93">
<source>This password has been leaked in a data breach, it must not be used. Please use another password.</source>
<target>依據您的密碼,發生數據泄露,請勿使用改密碼。請更換密碼。</target>
</trans-unit>
<trans-unit id="94">
<source>This value should be between {{ min }} and {{ max }}.</source>
<target>該數值應在 {{ min }} 和 {{ max }} 之間。</target>
</trans-unit>
</body> </body>
</file> </file>
</xliff> </xliff>

View File

@ -25,7 +25,7 @@ final class CliContextProvider implements ContextProviderInterface
} }
return [ return [
'command_line' => $commandLine = implode(' ', $_SERVER['argv']), 'command_line' => $commandLine = implode(' ', $_SERVER['argv'] ?? []),
'identifier' => hash('crc32b', $commandLine.$_SERVER['REQUEST_TIME_FLOAT']), 'identifier' => hash('crc32b', $commandLine.$_SERVER['REQUEST_TIME_FLOAT']),
]; ];
} }