-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add new DOM Living Standard API to ext/dom #4709
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
Conversation
First implementation of DOMElement#remove()
…y type to string and turn them to DOMTextNode
…ations to DOMDocument+DOMDocumentFragment for now.
Great! Although I would like the DOM and HTML to be handled as XHP in Hacklang. I would pay for xhp in PHP! 😍 |
@cscott Nothing you mention has anything to do with this RFC. Can you please specify what you mean incompatible with PHP DOM. As the RFC mentions, we are adopting the WHATWG DOM Living Standard changes to how PHP DOM works to keep the existing behaviors. We just add the new methods and their behavior in a way that is compatible with how PHP DOM works today. I don't believe it makes sense to break the API of ext/dom, because when people use ext/dom to mainipulate or traverse xml documents, this is usually wide-spread, requires a fair bit of code, and might therefore not really easy to migrate. Overall, the PHP DOM extension should continue to be inspired by the DOM Stanndard, but breaking BC to followß it at this point is out of the questino and doesn't serve a good purpose. My idea would rather be thta we add a page to the documentation explaining the differences. |
@cscott by the way, I have reviewed the wikimedia ticket a few times before already, but it contains a misconception about missing HTML XML functionality (innerHTML, uppercase tags, body property). ext/dom is about XML and doesn't aim to implement the HTML standards extensions to it at this time. |
xmlSetTreeDoc(newNode, documentNode); | ||
|
||
if (!xmlAddChild(fragment, newNode)) { | ||
return NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unlike the case above, this doesn't generate an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its not a type error, as it is a string, not sure what to do here. the return value from xmlAddChild
is not checked everywhere in the existing code base.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant the php_dom_throw_error(HIERARCHY_REQUEST_ERR, stricterror);
error above. Though I guess that can't happen if the added node is newly created?
… assertions, after/before are loosing elements.
xmlSetTreeDoc(newNode, documentNode); | ||
|
||
if (!xmlAddChild(fragment, newNode)) { | ||
return NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant the php_dom_throw_error(HIERARCHY_REQUEST_ERR, stricterror);
error above. Though I guess that can't happen if the added node is newly created?
ext/dom/parentnode.c
Outdated
|
||
if (newchild) { | ||
parentNode->children = newchild; | ||
newchild->prev = prevsib; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both the prevsib variable and this assignment look unnecessary to me. prevsib is always NULL, and newchild->prev should also be NULL already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this was left over so that each method looks as equal to the previous ones so I can more easily find common things to refactor out later. They are too different though, except the parent node assignment so i cleaned this up now.
|
||
newchild->prev = prevsib; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: double newline
Merged in 5acd86d |
RFC: https://wiki.php.net/rfc/dom_living_standard_api
Add new methods from https://dom.spec.whatwg.org/ (formerly https://www.w3.org/TR/dom) specification to ext/dom in a mostly backwards compatible way and "PHPify" the API
DOMParentNode
DOMParentNode
interfacefirstElementChild
,lastElementChild
,childElementCount
property handlersDOMElement instanceof DOMParentNode
DOMDocument instanceof DOMParentNode
DOMFragment instanceof DOMParentNode
prepend()
append()
We leave out
DOMParentNode#querySelector
andquerySelectorAll
and leave open to include them in a new interface later. In any case translating CSS Selectors to XPath should be a userland concern, Symfony CSS Selector and FluentDOM PhpCSS are good examples.DOMNonDocumentTypeChildNode
This interface is not actually added, instead added
previousElementSibling
,nextElementSibling
property handlers directly on all classes that implementDOMChildNode
.previousElementSibling
,nextElementSibling
property handlersDOMElement
DOMCharacterData
DOMChildNode
DOMChildNode
interfaceDOMElement instanceof DOMChildNode
DOMCharacterData instanceof DOMChildNode
remove()
before()
after()
replaceWith()
Implementation Todos
append
,prepend
,before
,after
methods instead of code duplication used now. (better be done after RFC acceptance)Testing