1212
1313namespace Derafu \Xml \Contract ;
1414
15+ use DOMDocument ;
1516use DOMElement ;
16- use DOMNodeList ;
17- use DOMParentNode ;
1817
1918/**
20- * Interface for the class that represents an XML document.
19+ * Interface for the underlying DOM document access .
2120 *
22- * This interface exists so that other interfaces that extend DOMDocument, such
23- * as XmlDocument, can resolve the methods that use the official PHP
24- * DOMDocument. These methods should not be implemented if you extend
25- * DOMDocument. It is only for the IDE and syntactic analyzers to not generate
26- * warnings in the interface.
27- *
28- * @see DOMDocument
21+ * Exposes the minimal DOM surface needed by XmlDocumentInterface: access to
22+ * the raw DOMDocument, the document element, and canonicalization. All other
23+ * DOM operations (mutation, validation) are handled by the services that need
24+ * them via getDomDocument().
2925 */
30- interface DOMDocumentInterface extends DOMParentNode
26+ interface DOMDocumentInterface
3127{
3228 /**
33- * Returns the root element instance of the document .
29+ * Returns the underlying DOMDocument instance.
3430 *
35- * This is a safe way to access $documentElement when using this interface
36- * as a variable type .
31+ * Provides an escape hatch for services (encoder, validator) that need
32+ * direct DOM access without polluting the XmlDocument public API .
3733 *
38- * If you do not use this, tools like phpstan will complain.
34+ * @return DOMDocument
35+ */
36+ public function getDomDocument (): DOMDocument ;
37+
38+ /**
39+ * Returns the root element instance of the document.
3940 *
4041 * @return DOMElement|null
4142 */
@@ -44,86 +45,16 @@ public function getDocumentElement(): ?DOMElement;
4445 /**
4546 * Canonicalizes the XML according to the C14N specification.
4647 *
47- * The official implementation of this interface inherits from DOMDocument
48- * so this method is available. However, it is defined in the interface so
49- * that tools like phpstan do not complain when using this interface as a
50- * variable type.
51- *
5248 * @param bool $exclusive Indicates if exclusive canonicalization is used.
5349 * @param bool $withComments Includes comments in the output if `true`.
54- * @param array|null $xpath Optional list of nodes to include in the
55- * canonicalization.
56- * @param array|null $nsPrefixes Prefixes of namespaces to consider in the
57- * canonicalization.
58- * @return string|false A string with the canonicalized XML or `false` in
59- * case of error.
50+ * @param array|null $xpath Optional list of nodes to include.
51+ * @param array|null $nsPrefixes Namespace prefixes to consider.
52+ * @return string|false Canonicalized XML or `false` on error.
6053 */
6154 public function C14N (
6255 bool $ exclusive = false ,
6356 bool $ withComments = false ,
6457 ?array $ xpath = null ,
6558 ?array $ nsPrefixes = null
6659 ): string |false ;
67-
68- /**
69- * Creates a new element in the XML document.
70- *
71- * The official implementation of this interface inherits from DOMDocument
72- * so this method is available. However, it is defined in the interface so
73- * that tools like phpstan do not complain when using this interface as a
74- * variable type.
75- *
76- * @param string $localName The local name of the element.
77- * @param string $value The optional value of the element.
78- * @return DOMElement|false The created element or `false` in case of error.
79- */
80- public function createElement (
81- string $ localName ,
82- string $ value = ''
83- ); // Adding a return type is incompatible with the official DOMDocument of PHP.
84-
85- /**
86- * Creates a new element in a specific namespace.
87- *
88- * The official implementation of this interface inherits from DOMDocument
89- * so this method is available. However, it is defined in the interface so
90- * that tools like phpstan do not complain when using this interface as a
91- * variable type.
92- *
93- * @param string|null $namespace The URI of the namespace (can be `null` for
94- * none).
95- * @param string $qualifiedName The qualified name of the element.
96- * @param string $value The optional value of the element.
97- * @return DOMElement|false The created element or `false` in case of error.
98- */
99- public function createElementNS (
100- ?string $ namespace ,
101- string $ qualifiedName ,
102- string $ value = ''
103- ); // Adding a return type is incompatible with the official DOMDocument of PHP.
104-
105- /**
106- * Validates the current XML document against an XML schema.
107- *
108- * The official implementation of this interface inherits from DOMDocument
109- * so this method is available. However, it is defined in the interface so
110- * that tools like phpstan do not complain when using this interface as a
111- * variable type.
112- *
113- * @param string $filename The path to the schema file (.xsd).
114- * @param int $flags Validation options (default `0`).
115- * @return bool `true` if validation is successful, `false` in case of error.
116- */
117- public function schemaValidate (string $ filename , int $ flags = 0 ): bool ;
118-
119- /**
120- * Gets a list of nodes (DOMNodeList) using a tag name.
121- *
122- * Searches for all elements of the current document that match the
123- * provided tag name (regardless of which part of the tree they are in).
124- *
125- * @param string $qualifiedName The qualified name of the tag to search for.
126- * @return DOMNodeList A list of nodes that match the tag.
127- */
128- public function getElementsByTagName (string $ qualifiedName ): DOMNodeList ;
12960}
0 commit comments