New in Symfony 3.2: DX improvements
November 4, 2016 • 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.
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
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
use Symfony\Component\Console\Helper\ProgressBar;
$progress = new ProgressBar($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
In PHP 7.x, methods can define the types of their return values. For example:
1 2 3 4
public function myFactory(): 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 PhpStorm links
The Symfony framework.ide configuration option allows you to turn any file path displayed in Symfony error pages into clickable links that open that exact file and line number in your favorite editor or IDE. We already supported lots of editors (SublimeText, Vim, etc.) and, starting from Symfony 3.2, we also support PhpStorm.
Added support for prioritizing form type extensions
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 special
form.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\ImageTypeExtension
tags:
- { name: form.type_extension, priority: -128,
extended_type: Symfony\Component\Form\Extension\Core\Type\FileType }
Added a named constructor to JsonResponse
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 of
JsonResponse
:
1 2
// $contents = '{"foo":"bar"}';
return new JsonResponse($contents, Response::HTTP_OK, [], true);
In Symfony 3.2, you can use the new fromJsonString()
named constructor:
1 2
// $contents = '{"foo":"bar"}';
return JsonResponse::fromJsonString($contents);
Added a short syntax for service configurators
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 syntax
configurator: [ '@app.configurator', 'configure' ]
# New short syntax supported by Symfony 3.2
configurator: 'app.configurator:configure'
Allowed to specify a domain when updating translations
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
The transChoice()
PHP function has been simplified to match Twig's
transchoice
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);
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.