New in Symfony 7.1: Misc Improvements (part 2)
Custom .env Path
Contributed by
Jérôme Tamarelle
in #52638.
When using a file to configure environment variables Symfony looks by default
in the .env file at the root of the project (and its variants .env.local,
.env.<environment>, .env.<environment>.local, etc.)
In Synmfony 7.1, we’re making the .env file location configurable, so you can
store that file in any other custom location. To do so, define the full path to
the new location in the SYMFONY_DOTENV_PATH env var (you must define this env
var outside Symfony; e.g. in your web/app server, in Docker, etc.)
Getting all Enum Cases in YAML Config
Contributed by
Javier Spagnoletti
in #52230.
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:
AppEntityUser:
properties:
status:
– Choice:
choices:
– !php/enum ‚AppEntityEnumUserStatus::Enabled‘
– !php/enum ‚AppEntityEnumUserStatus::Disabled‘
– !php/enum ‚AppEntityEnumUserStatus::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:
AppEntityUser:
properties:
status:
– Choice:
choices: !php/enum ‚AppEntityEnumUserStatus‘
Add Microseconds Getter/Setter in Clock
Contributed by
Nicolas Grekas
in #53942.
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
Contributed by
Maximilian Beckers
in #53728.
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
Contributed by
Hubert Lenoir
in #48803.
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:
$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)‘);
Symfony Blog