New in Symfony 4.1: Misc. improvements (part 4)
May 29, 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.
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
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
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
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
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.
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.