New in Symfony 7.1: Misc Improvements (part 2)
May 30, 2024 • Published by Javier Eguiluz
Symfony 7.1 is backed by:
Getting the Custom Path of the .env
File
The .env
file used to configure environment variables is stored by default
at the root of the project (as they are all the related files: .env.local
,
.env.<environment>
, .env.<environment>.local
, etc.)
You can change the location of this file in several ways. For example, when using
the Runtime component, you can configure the new location in the composer.json
file:
1 2 3 4 5 6 7 8 9
{
// ...
"extra": {
// ...
"runtime": {
"dotenv_path": "my/custom/path/to/.env"
}
}
}
In Symfony 7.1, we're adding a SYMFONY_DOTENV_PATH
env var that stores the
location of the .env
file. Applications can use that env var to get the
right .env
file location instead of wrongly assuming that it's always stored
in the project root.
Getting all Enum Cases in YAML Config
If you use YAML to configure your Symfony applications (this is optional, and you can also use XML or PHP if you prefer those), referring to all the cases of a PHP enum is too verbose:
1 2 3 4 5 6 7 8
App\Entity\User:
properties:
status:
- Choice:
choices:
- !php/enum 'App\Entity\Enum\UserStatus::Enabled'
- !php/enum 'App\Entity\Enum\UserStatus::Disabled'
- !php/enum 'App\Entity\Enum\UserStatus::Blocked'
In Symfony 7.1, we've improved this so you can get all cases at once. To do so, add the FQCN of the enum, instead of listing each case:
1 2 3 4 5
App\Entity\User:
properties:
status:
- Choice:
choices: !php/enum 'App\Entity\Enum\UserStatus'
Add Microseconds Getter/Setter in Clock
PHP 8.4, to be released on November 21, 2024, will add the getMicroseconds()
and setMicroseconds()
methods to the DateTime
and DateTimeImmutable
classes. In Symfony 7.1, we've added those methods as a polyfill in the Clock component
so you can start using them today while keeping your apps future-proof.
min()
and max()
Functions in Expressions
The ExpressionLanguage component provides a rich syntax to define expressions.
In Symfony 7.1, we're improving it by adding support for the min()
and max()
functions of PHP.
Support for :is()
and :where()
Pseudo-Classes
The CssSelector component is mostly used in functional tests as an easier alternative to defining XPath expressions. We keep adding support for the selectors defined in the CSS spec and that's why in Symfony 7.1, we've introduced support for the :is() pseudo-class and the :where() pseudo-class:
1 2 3
$crawler = $client->request('GET', '/some/url/path');
$items = $crawler->filter(':is(ol, ul) :is(ol, ul) ol');
$items = $crawler->filter(':where(ol, ul, menu:unsupported) :where(ol, ul)');
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.