Implement a DOM Facade for true compatibility
g105b opened this issue · 1 comments
In the current version of PHP.Gt/Dom, the objects that are interacted with are extensions of the native DOMDocument objects, but this imposes limitations such as lack of specific element implementation (#260).
If the repository had an overhaul to work as a Facade to the native DOMDocument, full compatibility could be reached, without having to implement an HTML parser and xpath traversal, etc.
Example:
$collection = $document->querySelectorAll("table>tr, input");
($collection[0] instanceof HTMLTableRowElement); // true
($collection[1] instanceof HTMLInputElement); //true
The querySelectorAll function of the HTMLDocument can map directly to the XPath function of the native DOMDocument element, as it does now, but without being an extension of the Document object - rather, a facade to it.
This will allow the construction of the HTMLCollection above to create the correct object hierarchy, so as each matching item is added to the collection it can check the tagname and create the correct element type.
I'm thinking out loud regarding how certain objects should be created. A lot of DOM objects have a private constructor. For example, it's impossible to construct a DOMImplementation
object. So how can we do it?
I want to keep enforcing the rule of "all or no static functions" on a class, but this decision has two impacts:
- A class can't have it's own static functions for factory methods.
- An external factory class can only call public constructors, and set public methods.
The solution I'm toying with is to extend the classes with private contructors into their own factories. For example, class DOMImplementationFactory extends DOMImplementation
. Then this factory can have static functions to create new instances, and because it's an extension, will be able to access protected members, including the protected constructors.