-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DomCrawler] Support classes from the new DOM extension #54383
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
base: 7.3
Are you sure you want to change the base?
Conversation
a326cbc
to
414de14
Compare
src/Symfony/Component/DomCrawler/Test/Constraint/CrawlerSelectorExists.php
Outdated
Show resolved
Hide resolved
36b8982
to
cc6945b
Compare
(Commented on the GBK test case too, but I know that GH notifications can be weird so just pointing it out so the comment isn't lost). The intention with <root>
<child1 xmlns:a="urn:a">
<a:nestedchild1/>
</child1>
<child1 xmlns:a="urn:not_a">
<a:nestedchild2/>
</child1>
</root> That's why the default Anyway, to answer the question of "why doesn't it work?", I wrote about this in the following two threads: veewee/xml#74 (comment) and nielsdos/php-src#93 (comment) |
cc6945b
to
c7408a9
Compare
Thanks @nielsdos for this complete explanation! 🚀 I think waiting for nielsdos/php-src#93 would help a lot in what's missing now in this PR. In the meantime, I'll have a look at what's possible with the current API. |
c7408a9
to
54b3814
Compare
54b3814
to
8a5f8b7
Compare
https://wiki.php.net/rfc/dom_additions_84 is under discussion which contains the features you need to finish this, as well as some extras such as css selector support. I'd like to point out one thing that may bite later about this PR: you're using the NO_DEFAULT_NS compatibility flag. This flag exists to ease migration and won't put elements in their proper namespace, it will put them in no namespace to be exact. Presumably you do this because your CSS selector translation does not take into account namespaces? Note that not having the proper namespace set on elements has quite a few subtle consequences. Depending on if something is inside the html namespace the behaviour of some methods alter (as defined by spec). For example automatic lowercasing of attribute names will not happen with the compatibility flag on because the element holding the attribute is no longer in the html namespace. (See https://dom.spec.whatwg.org/#concept-element-attributes-get-by-name step 1 for example) |
Amazing, thank you for keeping me updated! I'll have a look at the |
f27f754
to
ae36c49
Compare
I extracted common parts in traits for every class as you advised @derrabus, as well as tests. It really simplifies the whole thing for sure. I think it is ready for review now, even if I'm not sure how a review should be done in a PR that big. All classes have now an equivalent in the |
fa487e7
to
17ccdbb
Compare
17ccdbb
to
7dd7a3f
Compare
Creating totally separate classes independent of the existing ones means that we cannot use the new crawler in the BrowserKit component (as that would be a BC break) and this also implies that we cannot deprecate the old one. |
I understand, thanks for pointing this out. Which approach would you advise to solve this problem? |
7dd7a3f
to
10667d5
Compare
d934f0b
to
6fde3a6
Compare
6fde3a6
to
19cbe2a
Compare
I'm going to assume that, since you created a new |
@alexandre-daubois please provide info about which parts make it impossible to add support in |
The problem is that the new classes are completely different from the old ones and totally unrelated. Because of this, most method signatures from the existing Crawler cannot be updated to support a union of both old and new classes without breaking BC (thus creating new classes) |
Why can't the new types just be added as a union with the old types? |
@alexandre-daubois Creating new classes also breaks BC for BrowserKit if we make it switch to the new class (and if we keep BrowserKit on the old class, the feature is almost useless and won't help us remove the usage of |
@Bilge expanding a parameter type for a non-final method is a BC break, and the Crawler is not final. |
Would |
There are a lot of them. Actually, all methods put in common traits are the untouched one, whereas all methods of classes under the "NativeCrawler" namespace (for example) are the methods that need to be updated to support |
@alexandre-daubois I don't think this is actually true. For instance, |
Yes, for example |
What's the status of this PR @alexandre-daubois? |
I need to rebase it, but if I remember correctly, the implementation works. We still don't have decided what's the best approach. Currently, traits are used for common parts between the current and the new native crawlers. However, @stof raised that in #54383 (comment) that it will cause problems with the migration of Browserkit. Actually, some methods requires BC breaks because the PHP 8.4 native parser introduces new classes, incompatible with the old classes. Maybe the best option is to introduce BC breaks, allowing us to widen types in protected and public methods that requires to (i.e. |
New classes using the native parser are located in
NativeCrawler\
subnamespace. Existing classes and new ones have mutualized code in each corresponding trait to avoid duplication where possible.All tests covering the current classes have been transposed and adapted to new classes.
Remaining failing tests will be solved in the next PHP 8.4 nightly.