May 29, 2018 Javier Eguiluz

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 ¶ 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¶ 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¶ 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.