Home / Symfony / New in Symfony 7.4: Misc. Features (Part 1)

New in Symfony 7.4: Misc. Features (Part 1)

Native HTML5 Parser


Nicolas Grekas
Contributed by
Nicolas Grekas
in
#61366
and #61475

PHP 8.4 includes a native and full-featured HTML5 parser. In Symfony applications,
HTML parsers are used in the DomCrawler component and HtmlSanitizer component.
In previous Symfony versions, we relied on third-party libraries that implemented
HTML parsers in PHP code.

Starting in Symfony 7.4, Symfony uses the much faster native HTML parser from
PHP if your application runs on PHP 8.4 or higher. This is automatic, so there
is no change to make on your side.

Allow Any Protocols in Url Constraint


Aleksandar Stan
Contributed by
Aleksandar Stan
in
#60561

The Url constraint uses the protocols option to specify which protocols
are allowed when validating URLs. In Symfony 7.4 we improved this option so you
can use * to accept any protocol that follows the RFC 3986 spec (e.g.
https://, git+ssh://, file://, custom://):

// src/Entity/Author.php
namespace AppEntity;

use SymfonyComponentValidatorConstraints as Assert;

class Author
{
    #[AssertUrl(protocols: ['*'])]
    protected string $bioUrl;
}


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

Some APIs expose a Link HTTP header for pagination, so you must parse that
header to consume the API contents. Symfony already provides a WebLink component,
so in Symfony 7.4 we are adding an HttpHeaderParser class to parse these headers:

use SymfonyComponentWebLinkHttpHeaderParser;

$parser = new HttpHeaderParser();
// get the value of the Link header from the Request
$linkHeader = '</foo.css>; rel="prerender",</bar.otf>; rel="dns-prefetch"; pr="0.7",</baz.js>; rel="preload"; as="script"';

$links = $parser->parse($linkHeader)->getLinks();
$links[0]->getRels();       // ['prerender']
$links[1]->getAttributes(); // ['pr' => '0.7']
$links[2]->getHref();       // '/baz.js'

HTTP QUERY Method


Alexandre Daubois
Contributed by
Alexandre Daubois
in
#61173

The HTTP QUERY Method is a proposed addition to the HTTP standard. A
QUERY request is similar to a POST request but can be automatically
repeated or restarted without concern for partial state changes.

Technically, a QUERY request asks the target to “process the enclosed
content in a safe and idempotent manner and then respond with the result of
that processing”
.

In Symfony 7.4, we added support for QUERY in the Request class, the
HTTP Cache feature, the web profiler, and the HttpClient component.

Resource Tags Configuration


Nicolas Grekas
Contributed by
Nicolas Grekas
in
#61536
and #61578

In Symfony 7.3, we introduced resource tags so you can apply tags to classes
that are not registered as services and later get or inject those tagged
classes. In Symfony 7.4 we are improving this feature so you can configure
resource tags more easily in YAML or PHP formats:

# config/packages/services.yaml
services:
    foo:
        class: stdClass
        resource_tags:
            - { name: 'my.tag', foo: 'bar' }
            - 'another.tag'

use SymfonyComponentDependencyInjectionAttributeAutoconfigureResourceTag;

#[AutoconfigureResourceTag('my.tag', ['foo' => 'bar'])]
#[AutoconfigureResourceTag('another.tag')]
class SomeClass
{
    // ...
}


Sponsor the Symfony project.
Tagged:

Leave a Reply

Your email address will not be published. Required fields are marked *