Skip to content

[DomCrawler] Leverage PHP 8.4 DOM addition of native query selectors #57605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
alexandre-daubois opened this issue Jun 30, 2024 · 6 comments
Open

Comments

@alexandre-daubois
Copy link
Member

alexandre-daubois commented Jun 30, 2024

Description

Support for native HTML5 parser is being added to DomCrawler.

Lately, a lot of great additions are being added to the new DOM extension, especially query selectors : https://wiki.php.net/rfc/dom_additions_84 (it's the first section of the RFC).

DomCrawler could definitely benefit from this. At this time, the component is using CssSelector (the dependency is in the require-dev section currently). It would be nice to leverage this new native feature also when available !

I think it is not a good idea to bring support right now in the WIP PR, it is already kind of huge and complex, and we should do this step by step. For the record, the patch was merged in the engine upstream already: php/php-src#13819.

I'm creating this issue so we don't forget about it 😄 Indeed related to #53666

Example

The Crawler API wouldn't change, but internals of Crawler::matches, Crawler::closest() and alike would leverage the new native API.

@alexandre-daubois alexandre-daubois changed the title Leverage PHP 8.4 DOM addition of native query selectors [DomCrawler] Leverage PHP 8.4 DOM addition of native query selectors Jun 30, 2024
@derrabus
Copy link
Member

derrabus commented Jul 1, 2024

Does that mean, we could deprecate the whole CssSelector component?

@alexandre-daubois
Copy link
Member Author

alexandre-daubois commented Jul 1, 2024

That's what I thought at first, but CssSelector is actually a translator from XPath to CSS syntax, which could be useful for many devs. I think it still has its place in the components ecosystem, but it definitely can be removed from DomCrawler dependencies at some point.

@derrabus
Copy link
Member

derrabus commented Jul 1, 2024

CssSelector is actually a translator from XPath to CSS syntax, which could be useful for many devs.

Okay, but if the DOM extension can select by CSS selectors directly, why would I still need such a translator? I mean, if we deprecated the component, it would still be around for as long as we maintain Symfony 7.4 (November 2028).

@stof
Copy link
Member

stof commented Jul 1, 2024

I suggest we first work on leveraging the new native feature in DomCrawler before making a decision on the future of the CssSelector component (we have until the release cycle of Symfony 7.4 to decide whether we should deprecate the CssSelector component to remove it in 8.0).

and btw, this will also depend on what PHP requirement we decide to use in Symfony 8.0, which is not decided yet.

@carsonbot
Copy link

Thank you for this suggestion.
There has not been a lot of activity here for a while. Would you still like to see this feature?
Every feature is developed by the community.
Perhaps someone would like to try?
You can read how to contribute to get started.

@alexandre-daubois
Copy link
Member Author

Still relevant once #54383 progresses

@carsonbot carsonbot removed the Stalled label Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants