New in Symfony 4.1: Misc. improvements (part 3)
Allow to set the rounding strategy for MoneyType
¶
Contributed by
syastrebov
in #26767.
In Symfony 4.1, the MoneyType form field defines a new option called
rounding_mode
to control how the values are rounded. Before, all values were
rounded towards "the nearest neighbor" (ROUND_HALF_UP
) so 15.999
was
rounded as 16.00
. Now you can set it for example to ROUND_DOWN
to display
it as 15.99
:
1 2 3 4 5 6 7 | use Symfony\Component\Form\Extension\Core\DataTransformer\NumberToLocalizedStringTransformer;
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
// ...
$builder->add('price', MoneyType::class, array(
'rounding_mode' => NumberToLocalizedStringTransformer::ROUND_DOWN,
));
|
Adding and removing LDAP attributes more efficiently¶
Contributed by
Jean-Guilhem Rouel
in #21856.
Updating LDAP entries with the update()
is slow in some scenarios. That's
why in Symfony 4.1 there are two new methods called addAttributeValues()
and
removeAttributeValues()
that add/remove values to a multi-valued attribute:
1 2 3 4 5 6 7 8 9 | use Symfony\Component\Ldap\Ldap;
use Symfony\Component\Ldap\Entry;
// ...
$entry = $ldap->query('...', '...')->execute()[0];
$entityManager = $ldap->getEntryManager();
$entityManager->addAttributeValues($entry, 'telephoneNumber', ['+1.111.222.3333', '+1.222.333.4444']);
$entityManager->removeAttributeValues($entry, 'telephoneNumber', ['+1.111.222.3333', '+1.222.333.4444']);
|
Keep query string after redirecting¶
Contributed by
Hamza Amrouche
in #26281.
In Symfony 4.1, routes can define (in YAML, XML or PHP) a new option called
keepQueryParams
. By default it's false
, but if you set it to true
,
the query parameters (if any) are added to the redirected URL:
1 2 3 4 5 6 7 | legacy_search:
path: /search-engine
controller: Symfony\Bundle\FrameworkBundle\Controller\RedirectController::redirectAction
defaults:
route: search
permanent: true
keepQueryParams: true
|
In this example, if the original URL is /search-engine?q=symfony
, the app
redirects to /search?q=symfony
Added support for hasser accessors in PropertyInfo¶
Contributed by
Sébastien Decrême
in #23617.
The PropertyInfo component introspects information about class properties by
using different sources of metadata. In Symfony 4.1, one of those sources (the
ReflectionExtractor
class) added support for hasser methods.
This will allow for example to make a property readable by defining methods like
hasChildren()
instead of just getChildren()
.
Comments
> Confused why the price is an integer? Don't worry: this is just an example.
> But, storing prices as integers (e.g. 100 = $1 USD) can avoid rounding issues.
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.
Bart van den Burg said on May 28, 2018 at 14:04 #1