December 16, 2019 Javier Eguiluz

Improved PropertyAccess Error Messages¶ Contributed by

Pierre du Plessis

in #31194. Great error messages are essential to avoid frustration when using any piece of software. In Symfony 4.4 we improved the error messages generated by PropertyAccess when trying to find a writable property. For example, when you already defined the adder/remover methods but their signature was wrong (e.g. addFoo() / removeFoo() ), this was the error displayed: 1 2 Neither the property "foo" nor one of the methods "addFoo()/removeFoo()", "setFoo()", "foo()", "__set()" or "__call()" exist and have public access. The error message is now much more clear: 1 The method "removeFoo()" requires at least "1" parameter, "0" found. This is just one example, but we improved lots of other error messages in this component.

Support *:only-of-type CSS selectors¶ Contributed by

Jakub Zalas

in #33861. The CssSelector component, which is used indirectly in functional tests to select items based on CSS selectors, supported the :only-of-type pseudo-class when specifying an HTML element (e.g. p:only-of-type selects a child only if it's the only paragraph inside an element). In Symfony 4.4 we also added support for *:only-of-type (or just :only-of-type ) which selects single child elements. If an element has 2 <p> and 1 <a> as children, only the <a> is selected, but if it has 1 <p> and 1 <a> , both are selected because they are the only ones of their types.

Use properties as Range values¶ Contributed by

Jérôme Parmentier

in #31511. The Range constraint validates that a given number or DateTime object is between some minimum and maximum. In Symfony 4.4, thanks to the new maxPropertyPath and minPropertyPath options, you can use the values stored in some properties as the values of those minimum/maximum: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 // src/Entity/Event.php namespace App\Entity ; use Symfony\Component\Validator\Constraints as Assert ; class Event { /** * @Assert\Range( * minPropertyPath = "startsAt", * maxPropertyPath = "endsAt" * ) */ private $registrationDate ; private $startsAt ; private $endsAt ; // ... }

Allow to sort translation messages¶ Contributed by

Dāvis Zālītis

in #33117. The translation:update command helps you extract the translatable contents from Twig templates and PHP controllers. In Symfony 4.4, we added a new --sort option to sort the list of messages alphabetically ( asc or desc ): 1 $ php bin/console translation:update --force --sort = asc fr

Consider empty strings not valid¶ Contributed by

Maxime Steinhausser

in #31528. Should an empty string be considered valid or invalid in the Length constraint? The answer is not as obvious as it may seem at first sight. In Symfony 4.4, we tried to improve and simplify this behavior with a new allowEmptyString option. In Symfony 4.4, the new option is true by default, to keep compatibility with the existing behavior. However, it's deprecated to not define a value for this option explicitly, so you'll see several deprecation logs related to this. We had to deprecate not setting it so we could change its default value to false in Symfony 5.0.