Getting the Custom Path of the .env File

Jérôme Tamarelle
Contributed by Jérôme Tamarelle in #52638

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

Javier Spagnoletti
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:

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

Nicolas Grekas
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

Maximilian Beckers
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

Hubert Lenoir
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:

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)');
Published in #Living on the edge