Add new DOM Living Standard API to ext/dom#4709
Add new DOM Living Standard API to ext/dom#4709beberlei wants to merge 57 commits intophp:masterfrom
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.
Unlike the case above, this doesn't generate an error.
There was a problem hiding this comment.
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.
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.
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?
|
|
||
| if (newchild) { | ||
| parentNode->children = newchild; | ||
| newchild->prev = prevsib; |
There was a problem hiding this comment.
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.
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; | ||
|
|
||
|
|
|
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
DOMParentNodeinterfacefirstElementChild,lastElementChild,childElementCountproperty handlersDOMElement instanceof DOMParentNodeDOMDocument instanceof DOMParentNodeDOMFragment instanceof DOMParentNodeprepend()append()We leave out
DOMParentNode#querySelectorandquerySelectorAlland 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,nextElementSiblingproperty handlers directly on all classes that implementDOMChildNode.previousElementSibling,nextElementSiblingproperty handlersDOMElementDOMCharacterDataDOMChildNode
DOMChildNodeinterfaceDOMElement instanceof DOMChildNodeDOMCharacterData instanceof DOMChildNoderemove()before()after()replaceWith()Implementation Todos
append,prepend,before,aftermethods instead of code duplication used now. (better be done after RFC acceptance)Testing