Skip to content

Commit

Permalink
Merge branch '5.0'
Browse files Browse the repository at this point in the history
* 5.0:
  [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
  [5.0] Remove some unused variables
  [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
  • Loading branch information
fabpot committed Feb 29, 2020
2 parents 0888ff6 + 65d06cb commit 6429999
Show file tree
Hide file tree
Showing 22 changed files with 117 additions and 21 deletions.
Expand Up @@ -415,6 +415,7 @@
</xsd:sequence>
<xsd:attribute name="default-bus" type="xsd:string" />
<xsd:attribute name="enabled" type="xsd:boolean" />
<xsd:attribute name="failure-transport" type="xsd:string" />
</xsd:complexType>

<xsd:complexType name="messenger_serializer">
Expand Down Expand Up @@ -445,12 +446,21 @@
<xsd:complexType name="messenger_transport">
<xsd:sequence>
<xsd:element name="options" type="metadata" minOccurs="0" maxOccurs="unbounded" />
<xsd:element name="retry-strategy" type="messenger_retry_strategy" minOccurs="0" maxOccurs="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="serializer" type="xsd:string" />
<xsd:attribute name="dsn" type="xsd:string" />
</xsd:complexType>

<xsd:complexType name="messenger_retry_strategy">
<xsd:attribute name="service" type="xsd:string" />
<xsd:attribute name="max-retries" type="xsd:integer" />
<xsd:attribute name="delay" type="xsd:integer" />
<xsd:attribute name="multiplier" type="xsd:float" />
<xsd:attribute name="max-delay" type="xsd:float" />
</xsd:complexType>

<xsd:complexType name="messenger_bus">
<xsd:sequence>
<xsd:element name="middleware" type="messenger_middleware" minOccurs="0" maxOccurs="unbounded" />
Expand Down
Expand Up @@ -3,6 +3,7 @@
$container->loadFromExtension('framework', [
'serializer' => true,
'messenger' => [
'failure_transport' => 'failed',
'serializer' => [
'default_serializer' => 'messenger.transport.symfony_serializer',
],
Expand All @@ -12,7 +13,14 @@
'dsn' => 'amqp://localhost/%2f/messages?exchange_name=exchange_name',
'options' => ['queue' => ['name' => 'Queue']],
'serializer' => 'messenger.transport.native_php_serializer',
'retry_strategy' => [
'max_retries' => 10,
'delay' => 7,
'multiplier' => 3,
'max_delay' => 100,
],
],
'failed' => 'in-memory:///',
'redis' => 'redis://127.0.0.1:6379/messages',
],
],
Expand Down
Expand Up @@ -7,7 +7,7 @@

<framework:config>
<framework:serializer enabled="true" />
<framework:messenger>
<framework:messenger failure-transport="failed">
<framework:serializer default-serializer="messenger.transport.symfony_serializer" />
<framework:transport name="default" dsn="amqp://localhost/%2f/messages" />
<framework:transport name="customised" dsn="amqp://localhost/%2f/messages?exchange_name=exchange_name" serializer="messenger.transport.native_php_serializer">
Expand All @@ -16,7 +16,9 @@
<framework:name>Queue</framework:name>
</framework:queue>
</framework:options>
<framework:retry-strategy max-retries="10" delay="7" multiplier="3" max-delay="100"/>
</framework:transport>
<framework:transport name="failed" dsn="in-memory:///" />
<framework:transport name="redis" dsn="redis://127.0.0.1:6379/messages" />
</framework:messenger>
</framework:config>
Expand Down
@@ -1,6 +1,7 @@
framework:
serializer: true
messenger:
failure_transport: failed
serializer:
default_serializer: messenger.transport.symfony_serializer
transports:
Expand All @@ -11,4 +12,10 @@ framework:
queue:
name: Queue
serializer: 'messenger.transport.native_php_serializer'
retry_strategy:
max_retries: 10
delay: 7
multiplier: 3
max_delay: 100
failed: 'in-memory:///'
redis: 'redis://127.0.0.1:6379/messages'
Expand Up @@ -629,6 +629,13 @@ public function testMessengerTransports()
$this->assertSame('redis://127.0.0.1:6379/messages', $transportArguments[0]);

$this->assertTrue($container->hasDefinition('messenger.transport.redis.factory'));

$this->assertSame(10, $container->getDefinition('messenger.retry.multiplier_retry_strategy.customised')->getArgument(0));
$this->assertSame(7, $container->getDefinition('messenger.retry.multiplier_retry_strategy.customised')->getArgument(1));
$this->assertSame(3, $container->getDefinition('messenger.retry.multiplier_retry_strategy.customised')->getArgument(2));
$this->assertSame(100, $container->getDefinition('messenger.retry.multiplier_retry_strategy.customised')->getArgument(3));

$this->assertEquals(new Reference('messenger.transport.failed'), $container->getDefinition('messenger.failure.send_failed_message_to_failure_transport_listener')->getArgument(0));
}

public function testMessengerRouting()
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/DomCrawler/Form.php
Expand Up @@ -273,7 +273,7 @@ public function remove(string $name)
/**
* Gets a named field.
*
* @return FormField The field instance
* @return FormField|FormField[]|FormField[][] The value of the field
*
* @throws \InvalidArgumentException When field is not present in this form
*/
Expand Down Expand Up @@ -317,7 +317,7 @@ public function offsetExists($name)
*
* @param string $name The field name
*
* @return FormField The associated Field instance
* @return FormField|FormField[]|FormField[][] The value of the field
*
* @throws \InvalidArgumentException if the field does not exist
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/DomCrawler/FormFieldRegistry.php
Expand Up @@ -66,7 +66,7 @@ public function remove(string $name)
/**
* Returns the value of the field based on the fully qualifed name and its children.
*
* @return mixed The value of the field
* @return FormField|FormField[]|FormField[][] The value of the field
*
* @throws \InvalidArgumentException if the field does not exist
*/
Expand Down
33 changes: 32 additions & 1 deletion src/Symfony/Component/DomCrawler/Tests/FormTest.php
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\DomCrawler\Tests;

use PHPUnit\Framework\TestCase;
use Symfony\Component\DomCrawler\Field\TextareaFormField;
use Symfony\Component\DomCrawler\Form;
use Symfony\Component\DomCrawler\FormFieldRegistry;

Expand Down Expand Up @@ -965,7 +966,7 @@ protected function createTestMultipleForm()
return $dom;
}

public function testgetPhpValuesWithEmptyTextarea()
public function testGetPhpValuesWithEmptyTextarea()
{
$dom = new \DOMDocument();
$dom->loadHTML('
Expand All @@ -980,4 +981,34 @@ public function testgetPhpValuesWithEmptyTextarea()
$form = new Form($nodes->item(0), 'http://example.com');
$this->assertEquals($form->getPhpValues(), ['example' => '']);
}

public function testGetReturnTypes()
{
$dom = new \DOMDocument();
$dom->loadHTML('
<html>
<form>
<textarea name="foo[collection][0][bar]">item 0</textarea>
</form>
</html>'
);

$nodes = $dom->getElementsByTagName('form');
$form = new Form($nodes->item(0), 'http://example.com');

// FormField
$this->assertInstanceOf(TextareaFormField::class, $textareaFormField = $form->get('foo[collection][0][bar]'));

// Array of FormField
$this->assertSame([
'bar' => $textareaFormField,
], $form->get('foo[collection][0]'));

// Array of array of FormField
$this->assertSame([
[
'bar' => $textareaFormField,
],
], $form->get('foo[collection]'));
}
}
2 changes: 1 addition & 1 deletion src/Symfony/Component/Dotenv/README.md
Expand Up @@ -2,7 +2,7 @@ Dotenv Component
================

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

Resources
---------
Expand Down
10 changes: 5 additions & 5 deletions src/Symfony/Component/ErrorHandler/DebugClassLoader.php
Expand Up @@ -427,17 +427,17 @@ public function checkAnnotations(\ReflectionClass $refl, string $class): array
}
}

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)) {
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)) {
foreach ($notice as $method) {
$static = '' !== $method[1];
$name = $method[2];
$description = $method[3] ?? null;
$static = '' !== $method[1] && !empty($method[2]);
$name = $method[3];
$description = $method[4] ?? null;
if (false === strpos($name, '(')) {
$name .= '()';
}
if (null !== $description) {
$description = trim($description);
if (!isset($method[4])) {
if (!isset($method[5])) {
$description .= '.';
}
}
Expand Down
Expand Up @@ -325,6 +325,7 @@ class_exists('Test\\'.ExtendsVirtual::class, true);
restore_error_handler();

$this->assertSame([
'Class "Test\Symfony\Component\ErrorHandler\Tests\ExtendsVirtualParent" should implement method "Symfony\Component\ErrorHandler\Tests\Fixtures\VirtualInterface::staticReturningMethod()".',
'Class "Test\Symfony\Component\ErrorHandler\Tests\ExtendsVirtualParent" should implement method "Symfony\Component\ErrorHandler\Tests\Fixtures\VirtualInterface::sameLineInterfaceMethodNoBraces()".',
'Class "Test\Symfony\Component\ErrorHandler\Tests\ExtendsVirtualParent" should implement method "Symfony\Component\ErrorHandler\Tests\Fixtures\VirtualInterface::newLineInterfaceMethod()": Some description!',
'Class "Test\Symfony\Component\ErrorHandler\Tests\ExtendsVirtualParent" should implement method "Symfony\Component\ErrorHandler\Tests\Fixtures\VirtualInterface::newLineInterfaceMethodNoBraces()": Description.',
Expand Down
Expand Up @@ -4,6 +4,7 @@

/**
* @method string interfaceMethod()
* @method static staticReturningMethod()
* @method sameLineInterfaceMethod($arg)
* @method sameLineInterfaceMethodNoBraces
*
Expand All @@ -25,7 +26,7 @@
*
* Static
* @method static Foo&Bar staticMethod()
* @method static staticMethodNoBraces
* @method static mixed staticMethodNoBraces
* @method static \stdClass staticMethodTyped(int $arg) Description
* @method static \stdClass[] staticMethodTypedNoBraces
*/
Expand Down
Expand Up @@ -279,7 +279,7 @@ private function round($number)
break;
}

$number /= $roundingCoef;
$number = 1 === $roundingCoef ? (int) $number : $number / $roundingCoef;
}

return $number;
Expand Down
Expand Up @@ -370,7 +370,7 @@ public function testReverseTransformWithRounding($scale, $input, $output, $round
{
$transformer = new NumberToLocalizedStringTransformer($scale, null, $roundingMode);

$this->assertEquals($output, $transformer->reverseTransform($input));
$this->assertSame($output, $transformer->reverseTransform($input));
}

public function testReverseTransformDoesNotRoundIfNoScale()
Expand Down
Expand Up @@ -72,7 +72,7 @@ public function wait(?ResponseInterface $pendingResponse, float $maxDuration = n
goto check_duration;
}

if ([$request, $promise] = $this->promisePool[$response] ?? null) {
if ([, $promise] = $this->promisePool[$response] ?? null) {
unset($this->promisePool[$response]);
$promise->resolve($this->createPsr7Response($response, true));
}
Expand Down
11 changes: 10 additions & 1 deletion src/Symfony/Component/Serializer/Encoder/XmlEncoder.php
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Component\Serializer\Encoder;

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

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

if (\is_object($data)) {
if (null === $this->serializer) {
throw new BadMethodCallException(sprintf('The serializer needs to be set to allow %s() to be used with object data.', __METHOD__));
}

$data = $this->serializer->normalize($data, $this->format, $this->context);
if (null !== $data && !is_scalar($data)) {
return $this->buildXml($parentNode, $data, $xmlRootNodeName);
Expand Down Expand Up @@ -469,6 +474,10 @@ private function selectNodeType(\DOMNode $node, $val): bool
} elseif ($val instanceof \Traversable) {
$this->buildXml($node, $val);
} elseif (\is_object($val)) {
if (null === $this->serializer) {
throw new BadMethodCallException(sprintf('The serializer needs to be set to allow %s() to be used with object data.', __METHOD__));
}

return $this->selectNodeType($node, $this->serializer->normalize($val, $this->format, $this->context));
} elseif (is_numeric($val)) {
return $this->appendText($node, (string) $val);
Expand Down
Expand Up @@ -68,6 +68,10 @@ public function denormalize($data, string $type, string $format = null, array $c
*/
public function supportsDenormalization($data, string $type, string $format = null, array $context = []): bool
{
if (null === $this->serializer) {
throw new BadMethodCallException(sprintf('The serializer needs to be set to allow %s() to be used.', __METHOD__));
}

return '[]' === substr($type, -2)
&& $this->serializer->supportsDenormalization($data, substr($type, 0, -2), $format, $context);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/String/UnicodeString.php
Expand Up @@ -241,7 +241,7 @@ public function replace(string $from, string $to): AbstractString
$tail = substr($tail, \strlen($slice) + \strlen($from));
}

$str->string = $result .= $tail;
$str->string = $result.$tail;
normalizer_is_normalized($str->string) ?: $str->string = normalizer_normalize($str->string);

if (false === $str->string) {
Expand Down
7 changes: 4 additions & 3 deletions src/Symfony/Component/Validator/ConstraintValidator.php
Expand Up @@ -21,8 +21,8 @@
abstract class ConstraintValidator implements ConstraintValidatorInterface
{
/**
* Whether to format {@link \DateTime} objects as RFC-3339 dates
* ("Y-m-d H:i:s").
* Whether to format {@link \DateTime} objects, either with the {@link \IntlDateFormatter}
* (if it is available) or as RFC-3339 dates ("Y-m-d H:i:s").
*/
const PRETTY_DATE = 1;

Expand Down Expand Up @@ -69,7 +69,8 @@ protected function formatTypeOf($value)
* in double quotes ("). Objects, arrays and resources are formatted as
* "object", "array" and "resource". If the $format bitmask contains
* the PRETTY_DATE bit, then {@link \DateTime} objects will be formatted
* as RFC-3339 dates ("Y-m-d H:i:s").
* with the {@link \IntlDateFormatter}. If it is not available, they will be
* formatted as RFC-3339 dates ("Y-m-d H:i:s").
*
* Be careful when passing message parameters to a constraint violation
* that (may) contain objects, arrays or resources. These parameters
Expand Down
Expand Up @@ -370,6 +370,10 @@
<source>This value is not a valid hostname.</source>
<target>Dieser Wert ist kein gültiger Hostname.</target>
</trans-unit>
<trans-unit id="96">
<source>The number of elements in this collection should be a multiple of {{ compared_value }}.</source>
<target>Die Anzahl an Elementen in dieser Sammlung sollte ein Vielfaches von {{ compared_value }} sein.</target>
</trans-unit>
</body>
</file>
</xliff>
Expand Up @@ -362,6 +362,18 @@
<source>This password has been leaked in a data breach, it must not be used. Please use another password.</source>
<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>
</trans-unit>
<trans-unit id="94">
<source>This value should be between {{ min }} and {{ max }}.</source>
<target>Giá trị này nên thuộc giữa {{ min }} và {{ max }}.</target>
</trans-unit>
<trans-unit id="95">
<source>This value is not a valid hostname.</source>
<target>Giá trị này không phải là tên máy chủ hợp lệ.</target>
</trans-unit>
<trans-unit id="96">
<source>The number of elements in this collection should be a multiple of {{ compared_value }}.</source>
<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>
</trans-unit>
</body>
</file>
</xliff>
1 change: 0 additions & 1 deletion src/Symfony/Component/VarDumper/Cloner/VarCloner.php
Expand Up @@ -28,7 +28,6 @@ protected function doClone($var)
$pos = 0; // Number of cloned items past the minimum depth
$refsCounter = 0; // Hard references counter
$queue = [[$var]]; // This breadth-first queue is the return value
$indexedArrays = []; // Map of queue indexes that hold numerically indexed arrays
$hardRefs = []; // Map of original zval ids to stub objects
$objRefs = []; // Map of original object handles to their stub object counterpart
$objects = []; // Keep a ref to objects to ensure their handle cannot be reused while cloning
Expand Down

0 comments on commit 6429999

Please sign in to comment.