8000 Merge branch '4.4' into 5.0 · symfony/symfony@65d06cb · GitHub
[go: up one dir, main page]

Skip to content

Commit 65d06cb

Browse files
committed
Merge branch '4.4' into 5.0
* 4.4: [Dotenv] Documentation improvement [DI] Clarified deprecation for TypedReference in 4.4 [Validator] Add missing vietnamese translations add German translation add missing Messenger options to XML schema definition [Validator][ConstraintValidator] Update wrong PRETTY_DATE doc [DomCrawler][Form] Fix PHPDoc on get & offsetGet [ErrorHandler] fix parsing static return type on interface method annotation (fix #35836) prevent method calls on null values Return int if scale = 0
2 parents 15297b1 + 8f7b8aa commit 65d06cb

File tree

19 files changed

+115
-18
lines changed

19 files changed

+115
-18
lines changed

src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@
414414
</xsd:sequence>
415415
<xsd:attribute name="default-bus" type="xsd:string" />
416416
<xsd:attribute name="enabled" type="xsd:boolean" />
417+
<xsd:attribute name="failure-transport" type="xsd:string" />
417418
</xsd:complexType>
418419

419420
<xsd:complexType name="messenger_serializer">
@@ -444,12 +445,21 @@
444445
<xsd:complexType name="messenger_transport">
445446
<xsd:sequence>
446447
<xsd:element name="options" type="metadata" minOccurs="0" maxOccurs="unbounded" />
448+
<xsd:element name="retry-strategy" type="messenger_retry_strategy" minOccurs="0" maxOccurs="1" />
447449
</xsd:sequence>
448450
<xsd:attribute name="name" type="xsd:string" />
449451
<xsd:attribute name="serializer" type="xsd:string" />
450452
<xsd:attribute name="dsn" type="xsd:string" />
451453
</xsd:complexType>
452454

455+
<xsd:complexType name="messenger_retry_strategy">
456+
<xsd:attribute name="service" type="xsd:string" />
457+
<xsd:attribute name="max-retries" type="xsd:integer" />
458+
<xsd:attribute name="delay" type="xsd:integer" />
459+
<xsd:attribute name="multiplier" type="xsd:float" />
460+
<xsd:attribute name="max-delay" type="xsd:float" />
461+
</xsd:complexType>
462+
453463
<xsd:complexType name="messenger_bus">
454464
<xsd:sequence>
455465
<xsd:element name="middleware" type="messenger_middleware" minOccurs="0" maxOccurs="unbounded" />

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/messenger_transports.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
$container->loadFromExtension('framework', [
44
'serializer' => true,
55
'messenger' => [
6+
'failure_transport' => 'failed',
67
'serializer' => [
78
'default_serializer' => 'messenger.transport.symfony_serializer',
89
],
@@ -12,7 +13,14 @@
1213
'dsn' => 'amqp://localhost/%2f/messages?exchange_name=exchange_name',
1314
'options' => ['queue' => ['name' => 'Queue']],
1415
'serializer' => 'messenger.transport.native_php_serializer',
16+
'retry_strategy' => [
17+
'max_retries' => 10,
18+
'delay' => 7,
19+
'multiplier' => 3,
20+
'max_delay' => 100,
21+
],
1522
],
23+
'failed' => 'in-memory:///',
1624
'redis' => 'redis://127.0.0.1:6379/messages',
1725
],
1826
],

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/messenger_transports.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
<framework:config>
99
<framework:serializer enabled="true" />
10-
<framework:messenger>
10+
<framework:messenger failure-transport="failed">
1111
<framework:serializer default-serializer="messenger.transport.symfony_serializer" />
1212
<framework:transport name="default" dsn="amqp://localhost/%2f/messages" />
1313
<framework:transport name="customised" dsn="amqp://localhost/%2f/messages?exchange_name=exchange_name" serializer="messenger.transport.native_php_serializer">
@@ -16,7 +16,9 @@
1616
<framework:name>Queue</framework:name>
1717
</framework:queue>
1818
</framework:options>
19+
<framework:retry-strategy max-retries="10" delay="7" multiplier="3" max-delay="100"/>
1920
</framework:transport>
21+
<framework:transport name="failed" dsn="in-memory:///" />
2022
<framework:transport name="redis" dsn="redis://127.0.0.1:6379/messages" />
2123
</framework:messenger>
2224
</framework:config>

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/messenger_transports.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
framework:
22
serializer: true
33
messenger:
4+
failure_transport: failed
45
serializer:
56
default_serializer: messenger.transport.symfony_serializer
67
transports:
@@ -11,4 +12,10 @@ framework:
1112
queue:
1213
name: Queue
1314
serializer: 'messenger.transport.native_php_serializer'
15+
retry_strategy:
16+
max_retries: 10
17+
delay: 7
18+
multiplier: 3
19+
max_delay: 100
20+
failed: 'in-memory:///'
1421
redis: 'redis://127.0.0.1:6379/messages'

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,13 @@ public function testMessengerTransports()
627627
$this->assertSame('redis://127.0.0.1:6379/messages', $transportArguments[0]);
628628

629629
$this->assertTrue($container->hasDefinition('messenger.transport.redis.factory'));
630+
631+
$this->assertSame(10, $container->getDefinition('messenger.retry.multiplier_retry_strategy.customised')->getArgument(0));
632+
$this->assertSame(7, $container->getDefinition('messenger.retry.multiplier_retry_strategy.customised')->getArgument(1));
633+
$this->assertSame(3, $container->getDefinition('messenger.retry.multiplier_retry_strategy.customised')->getArgument(2));
634+
$this->assertSame(100, $container->getDefinition('messenger.retry.multiplier_retry_strategy.customised')->getArgument(3));
635+
636+
$this->assertEquals(new Reference('messenger.transport.failed'), $container->getDefinition('messenger.failure.send_failed_message_to_failure_transport_listener')->getArgument(0));
630637
}
631638

632639
public function testMessengerRouting()

src/Symfony/Component/DomCrawler/Form.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ public function remove(string $name)
273273
/**
274274
* Gets a named field.
275275
*
276-
* @return FormField The field instance
276+
* @return FormField|FormField[]|FormField[][] The value of the field
277277
*
278278
* @throws \InvalidArgumentException When field is not present in this form
279279
*/
@@ -317,7 +317,7 @@ public function offsetExists($name)
317317
*
318318
* @param string $name The field name
319319
*
320-
* @return FormField The associated Field instance
320+
* @return FormField|FormField[]|FormField[][] The value of the field
321321
*
322322
* @throws \InvalidArgumentException if the field does not exist
323323
*/

src/Symfony/Component/DomCrawler/FormFieldRegistry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function remove(string $name)
6666
/**
6767
* Returns the value of the field based on the fully qualifed name and its children.
6868
*
69-
* @return mixed The value of the field
69+
* @return FormField|FormField[]|FormField[][] The value of the field
7070
*
7171
* @throws \InvalidArgumentException if the field does not exist
7272
*/

src/Symfony/Component/DomCrawler/Tests/FormTest.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\DomCrawler\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\DomCrawler\Field\TextareaFormField;
1516
use Symfony\Component\DomCrawler\Form;
1617
use Symfony\Component\DomCrawler\FormFieldRegistry;
1718

@@ -965,7 +966,7 @@ protected function createTestMultipleForm()
965966
return $dom;
966967
}
967968

968-
public function testgetPhpValuesWithEmptyTextarea()
969+
public function testGetPhpValuesWithEmptyTextarea()
969970
{
970971
$dom = new \DOMDocument();
971972
$dom->loadHTML('
@@ -980,4 +981,34 @@ public function testgetPhpValuesWithEmptyTextarea()
980981
$form = new Form($nodes->item(0), 'http://example.com');
981982
$this->assertEquals($form->getPhpValues(), ['example' => '']);
982983
}
984+
985+
public function testGetReturnTypes()
986+
{
987+
$dom = new \DOMDocument();
988+
$dom->loadHTML('
989+
<html>
990+
<form>
991+
<textarea name="foo[collection][0][bar]">item 0</textarea>
992+
</form>
993+
</html>'
994+
);
995+
996+
$nodes = $dom->getElementsByTagName('form');
997+
$form = new Form($nodes->item(0), 'http://example.com');
998+
999+
// FormField
1000+
$this->assertInstanceOf(TextareaFormField::class, $textareaFormField = $form->get('foo[collection][0][bar]'));
1001+
1002+
// Array of FormField
1003+
$this->assertSame([
1004+
'bar' => $textareaFormField,
1005+
], $form->get('foo[collection][0]'));
1006+
1007+
// Array of array of FormField
1008+
$this->assertSame([
1009+
[
1010+
'bar' => $textareaFormField,
1011+
],
1012+
], $form->get('foo[collection]'));
1013+
}
9831014
}

src/Symfony/Component/Dotenv/README.md

325D
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Dotenv Component
22
================
33

44
Symfony Dotenv parses `.env` files to make environment variables stored in them
5-
accessible via `$_SERVER`, `$_ENV` and optionally `getenv()`.
5+
accessible via `$_SERVER` or `$_ENV`.
66

77
Resources
88
---------

src/Symfony/Component/ErrorHandler/DebugClassLoader.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -427,17 +427,17 @@ public function checkAnnotations(\ReflectionClass $refl, string $class): array
427427
}
428428
}
429429

430-
if ($refl->isInterface() && false !== strpos($doc, 'method') && preg_match_all('#\n \* @method\s+(static\s+)?+(?:[\w\|&\[\]\\\]+\s+)?(\w+(?:\s*\([^\)]*\))?)+(.+?([[:punct:]]\s*)?)?(?=\r?\n \*(?: @|/$|\r?\n))#', $doc, $notice, PREG_SET_ORDER)) {
430+
if ($refl->isInterface() && false !== strpos($doc, 'method') && preg_match_all('#\n \* @method\s+(static\s+)?+([\w\|&\[\]\\\]+\s+)?(\w+(?:\s*\([^\)]*\))?)+(.+?([[:punct:]]\s*)?)?(?=\r?\n \*(?: @|/$|\r?\n))#', $doc, $notice, PREG_SET_ORDER)) {
431431
foreach ($notice as $method) {
432-
$static = '' !== $method[1];
433-
$name = $method[2];
434-
$description = $method[3] ?? null;
432+
$static = '' !== $method[1] && !empty($method[2]);
433+
$name = $method[3];
434+
$description = $method[4] ?? null;
435435
if (false === strpos($name, '(')) {
436436
$name .= '()';
437437
}
438438
if (null !== $description) {
439439
$description = trim($description);
440-
if (!isset($method[4])) {
440+
if (!isset($method[5])) {
441441
$description .= '.';
442442
}
443443
}

src/Symfony/Component/ErrorHandler/Tests/DebugClassLoaderTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ class_exists('Test\\'.ExtendsVirtual::class, true);
325325
restore_error_handler();
326326

327327
$this->assertSame([
328+
'Class "Test\Symfony\Component\ErrorHandler\Tests\ExtendsVirtualParent" should implement method "Symfony\Component\ErrorHandler\Tests\Fixtures\VirtualInterface::staticReturningMethod()".',
328329
'Class "Test\Symfony\Component\ErrorHandler\Tests\ExtendsVirtualParent" should implement method "Symfony\Component\ErrorHandler\Tests\Fixtures\VirtualInterface::sameLineInterfaceMethodNoBraces()".',
329330
'Class "Test\Symfony\Component\ErrorHandler\Tests\ExtendsVirtualParent" should implement method "Symfony\Component\ErrorHandler\Tests\Fixtures\VirtualInterface::newLineInterfaceMethod()": Some description!',
330331
'Class "Test\Symfony\Component\ErrorHandler\Tests\ExtendsVirtualParent" should implement method "Symfony\Component\ErrorHandler\Tests\Fixtures\VirtualInterface::newLineInterfaceMethodNoBraces()": Description.',

src/Symfony/Component/ErrorHandler/Tests/Fixtures/VirtualInterface.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
/**
66
* @method string interfaceMethod()
7+
* @method static staticReturningMethod()
78
* @method sameLineInterfaceMethod($arg)
89
* @method sameLineInterfaceMethodNoBraces
910
*
@@ -25,7 +26,7 @@
2526
*
2627
* Static
2728
* @method static Foo&Bar staticMethod()
28-
* @method static staticMethodNoBraces
29+
* @method static mixed staticMethodNoBraces
2930
* @method static \stdClass staticMethodTyped(int $arg) Description
3031
* @method static \stdClass[] staticMethodTypedNoBraces
3132
*/

src/Symfony/Component/Form/Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ private function round($number)
279279
break;
280280
}
281281

282-
$number /= $roundingCoef;
282+
$number = 1 === $roundingCoef ? (int) $number : $number / $roundingCoef;
283283
}
284284

285285
return $number;

src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ public function testReverseTransformWithRounding($scale, $input, $output, $round
370370
{
371371
$transformer = new NumberToLocalizedStringTransformer($scale, null, $roundingMode);
372372

373-
$this->assertEquals($output, $transformer->reverseTransform($input));
373+
$this->assertSame($output, $transformer->reverseTransform($input));
374374
}
375375

376376
public function testReverseTransformDoesNotRoundIfNoScale()

src/Symfony/Component/Serializer/Encoder/XmlEncoder.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Serializer\Encoder;
1313

14+
use Symfony\Component\Serializer\Exception\BadMethodCallException;
1415
use Symfony\Component\Serializer\Exception\NotEncodableValueException;
1516
use Symfony\Component\Serializer\SerializerAwareInterface;
1617
use Symfony\Component\Serializer\SerializerAwareTrait;
@@ -368,7 +369,7 @@ private function buildXml(\DOMNode $parentNode, $data, string $xmlRootNodeName =
368369
$removeEmptyTags = $this->context[self::REMOVE_EMPTY_TAGS] ?? $this->defaultContext[self::REMOVE_EMPTY_TAGS] ?? false;
369370
$encoderIgnoredNodeTypes = $this->context[self::ENCODER_IGNORED_NODE_TYPES] ?? $this->defaultContext[self::ENCODER_IGNORED_NODE_TYPES];
370371

371-
if (\is_array($data) || ($data instanceof \Traversable && !$this->serializer->supportsNormalization($data, $this->format))) {
372+
if (\is_array($data) || ($data instanceof \Traversable && (null === $this->serializer || !$this->serializer->supportsNormalization($data, $this->format)))) {
372373
foreach ($data as $key => $data) {
373374
//Ah this is the magic @ attribute types.
374375
if (0 === strpos($key, '@') && $this->isElementNameValid($attributeName = substr($key, 1))) {
@@ -407,6 +408,10 @@ private function buildXml(\DOMNode $parentNode, $data, string $xmlRootNodeName =
407408
}
408409

409410
if (\is_object($data)) {
411+
if (null === $this->serializer) {
412+
throw new BadMethodCallException(sprintf('The serializer needs to be set to allow %s() to be used with object data.', __METHOD__));
413+
}
414+
410415
$data = $this->serializer->normalize($data, $this->format, $this->context);
411416
if (null !== $data && !is_scalar($data)) {
412417
return $this->buildXml($parentNode, $data, $xmlRootNodeName);
@@ -469,6 +474,10 @@ private function selectNodeType(\DOMNode $node, $val): bool
469474
} elseif ($val instanceof \Traversable) {
470475
$this->buildXml($node, $val);
471476
} elseif (\is_object($val)) {
477+
if (null === $this->serializer) {
478+
throw new BadMethodCallException(sprintf('The serializer needs to be set to allow %s() to be used with object data.', __METHOD__));
479+
}
480+
472481
return $this->selectNodeType($node, $this->serializer->normalize($val, $this->format, $this->context));
473482
} elseif (is_numeric($val)) {
474483
return $this->appendText($node, (string) $val);

src/Symfony/Component/Serializer/Normalizer/ArrayDenormalizer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ public function denormalize($data, string $type, string $format = null, array $c
6868
*/
6969
public function supportsDenormalization($data, string $type, string $format = null, array $context = []): bool
7070
{
71+
if (null === $this->serializer) {
72+
throw new BadMethodCallException(sprintf('The serializer needs to be set to allow %s() to be used.', __METHOD__));
73+
}
74+
7175
return '[]' === substr($type, -2)
7276
&& $this->serializer->supportsDenormalization($data, substr($type, 0, -2), $format, $context);
7377
}

src/Symfony/Component/Validator/ConstraintValidator.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
abstract class ConstraintValidator implements ConstraintValidatorInterface
2222
{
2323
/**
24-
* Whether to format {@link \DateTime} objects as RFC-3339 dates
25-
* ("Y-m-d H:i:s").
24+
* Whether to format {@link \DateTime} objects, either with the {@link \IntlDateFormatter}
25+
* (if it is available) or as RFC-3339 dates ("Y-m-d H:i:s").
2626
*/
2727
const PRETTY_DATE = 1;
2828

@@ -69,7 +69,8 @@ protected function formatTypeOf($value)
6969
* in double quotes ("). Objects, arrays and resources are formatted as
7070
* "object", "array" and "resource". If the $format bitmask contains
7171
* the PRETTY_DATE bit, then {@link \DateTime} objects will be formatted
72-
* as RFC-3339 dates ("Y-m-d H:i:s").
72+
* with the {@link \IntlDateFormatter}. If it is not available, they will be
73+
* formatted as RFC-3339 dates ("Y-m-d H:i:s").
7374
*
7475
* Be careful when passing message parameters to a constraint violation
7576
* that (may) contain objects, arrays or resources. These parameters

src/Symfony/Component/Validator/Resources/translations/validators.de.xlf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,10 @@
370370
<source>This value is not a valid hostname.</source>
371371
<target>Dieser Wert ist kein gültiger Hostname.</target>
372372
</trans-unit>
373+
<trans-unit id="96">
374+
<source>The number of elements in this collection should be a multiple of {{ compared_value }}.</source>
375+
<target>Die Anzahl an Elementen in dieser Sammlung sollte ein Vielfaches von {{ compared_value }} sein.</target>
376+
</trans-unit>
373377
</body>
374378
</file>
375379
</xliff>

src/Symfony/Component/Validator/Resources/translations/validators.vi.xlf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,18 @@
362362
<source>This password has been leaked in a data breach, it must not be used. Please use another password.</source>
363363
<target>Mật khẩu này đã bị rò rỉ dữ liệu, không được sử dụng nữa. Xin vui lòng sử dụng mật khẩu khác.</target>
364364
</trans-unit>
365+
<trans-unit id="94">
366+
<source>This value should be between {{ min }} and {{ max }}.</source>
367+
<target>Giá trị này nên thuộc giữa {{ min }} và {{ max }}.</target>
368+
</trans-unit>
369+
<trans-unit id="95">
370+
<source>This value is not a valid hostname.</source>
371+
<target>Giá trị này không phải là tên máy chủ hợp lệ.</target>
372+
</trans-unit>
373+
<trans-unit id="96">
374+
<source>The number of elements in this collection should be a multiple of {{ compared_value }}.</source>
375+
<target>Số lượng các phần tử trong bộ sưu tập này nên là bội số của {{compared_value}}.</target>
376+
</trans-unit>
365377
</body>
366378
</file>
367379
</xliff>

0 commit comments

Comments
 (0)
0