New in Symfony 4.1: Misc. improvements (part 3)
May 28, 2018 • Published by Javier Eguiluz
Warning: This post is about an unsupported Symfony version. Some of this information may be out of date. Read the most recent Symfony Docs.
Allow to set the rounding strategy for MoneyType
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
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
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
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()
.
Help the Symfony project!
As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.
"that would be a really bad rounding" --- any money rounding is bad rounding.
Good job
> 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.