Quantcast
Channel: Symfony Blog
Viewing all articles
Browse latest Browse all 3057

New in Symfony 3.2: DX improvements

$
0
0

Symfony 3.2 includes tens of minor tweaks and improvements to make your work easier and to improve your productivity. This article summarizes some of those DX improvements.

Added ability to regress the progress bar

James Halsall

Contributed by
James Halsall
in #19824.

This is useful for example when the workload of some task cannot be determined beforehand In those cases, you can regress the progress bar by passing a negative step to the advance() method:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
useSymfony\Component\Console\Helper\ProgressBar;$progress=newProgressBar($output,100);$progress->start();// ... do some work$progress->advance(30);// new tasks are created, regress the bar by 10 steps$progress->advance(-10);

Automatically detect the service definition class

Guilhem N

Contributed by
Guilhem N
in #19191.

In PHP 7.x, methods can define the types of their return values. For example:

1
2
3
4
publicfunctionmyFactory():MyServiceClass{// ...}

In Symfony 3.2, we've added a new FactoryReturnTypePass compiler pass that automatically updates the service definitions of the factories that define their return types.

Added support for prioritizing form type extensions

David Maicher

Contributed by
David Maicher
in #19790.

Form extensions are the best way to add custom features on top of existing Symfony Form types. These extensions are enabled as services with the specialform.type_extension tag. In Symfony 3.2, this tag defines a new optional attribute called priority to better control the order in which the form type extensions are loaded:

1
2
3
4
5
6
services:app.form.image_type_extension:class:AppBundle\Form\Extension\ImageTypeExtensiontags:-{name:form.type_extension,priority:-128,extended_type:Symfony\Component\Form\Extension\Core\Type\FileType}

Added a named constructor to JsonResponse

Timothée Barray

Contributed by
Timothée Barray
in #19552.

If you create a JsonResponse with a content that is already encoded as a JSON string, you must pass true as the fourth optional argument ofJsonResponse:

1
2
// $contents = '{"foo":"bar"}';returnnewJsonResponse($contents,Response::HTTP_OK,[],true);

In Symfony 3.2, you can use the new fromJsonString() named constructor:

1
2
// $contents = '{"foo":"bar"}';returnJsonResponse::fromJsonString($contents);

Added a short syntax for service configurators

Oleg Voronkovich

Contributed by
Oleg Voronkovich in #19190.

Service configurators allow you to use a callable to configure a service after its instantiation. In Symfony 3.2, you can use a short syntax to define them in YAML config files:

1
2
3
4
5
6
7
services:app.some_service:class:...# Traditional syntaxconfigurator:['@app.configurator','configure']# New short syntax supported by Symfony 3.2configurator:'app.configurator:configure'

Allowed to specify a domain when updating translations

Anthony Grassiot

Contributed by
Anthony Grassiot in #19325.

The translation:update command now supports a --domain option to only update the messages related to that domain. This is very useful for complex applications that define lots of different translation domains:

1
$ ./bin/console translation:update en --force --domain=admin

Simplified the transChoice() function

Victor Bocharsky

Contributed by
Victor Bocharsky
in #19795.

The transChoice() PHP function has been simplified to match Twig'stranschoice filter. This means that you no longer have to provide the third optional argument with the value of the number parameter used to select the appropriate translation:

1
2
3
4
5
6
7
// Before$this->get('translator')->transChoice('1 apple|%count% apples',7,['%count%'=>7]);// After$this->get('translator')->transChoice('1 apple|%count% apples',7);

Be trained by Symfony experts - 2016-11-07 Paris - 2016-11-07 Paris - 2016-11-09 Paris

Viewing all articles
Browse latest Browse all 3057

Trending Articles