This is the 41st and last post in the series of New features of Symfony 4.1, which will be released at the end of this month and will have support for bug fixes until January 2019 (see Symfony 4.1 roadmap).

Added getParameter() to ControllerTrait

Robin Chalas
Contributed by Robin Chalas in #25439

Symfony comes with two optional base classes for controllers: Controller and AbstractController. They are similar but AbstractController is recommended because it's more restrictive: it does not allow you to access services directly via $this->get() or $this->container->get().

In Symfony 4.1, we improved AbstractController to add the commonly used helper getParameter() to get the value of any container config parameter. This change will allow to transition from Controller to AbstractController more easily.

Anonymous services in PHP DSL

Nikita Konstantinov
Contributed by Nikita Konstantinov in #24632

In Symfony 3.4 we introduced a PHP DSL to configure routes and services. In Symfony 4.1 we improved it adding support for anonymous services, which is useful when you don't care about the service name (e.g. when decorating services).

1
2
3
4
5
6
// app/config/services.php
return function (ContainerConfigurator $container) {
    $services = $container->services();
    // to create an anonymous service, pass null as its ID argument
    $services->set(null, stdClass::class)->tag('listener');
};

Added support for extracting type from constructor

Grégoire Pineau
Contributed by Grégoire Pineau in #25605

In Symfony 4.1, the ReflectionExtractor class of the PropertyInfo component added a new $enableConstructorExtraction argument to allow introspecting property information using the constructor arguments.

Consider the following example:

1
2
3
4
5
6
7
8
9
10
class SomeClass
{
    public $property1;
    public $property2;

    public function __construct(string $property1, ?int $property2)
    {
        // ...
    }
}

In Symfony 4.1, when this option is enabled, PropertyInfo will tell you that property1 is a non-nullable string type and that property2 is a nullable integer.

Configurable PHP error log level

Hamza Amrouche
Contributed by Hamza Amrouche in #26504

The framework.php_errors.log option allows to use the application logger instead of the PHP logger for logging PHP errors.

In Symfony 4.1, this option is no longer a boolean to enable/disable it. If you pass an integer value, you enable the feature and set the PHP logger to that logging level.

Published in #Living on the edge