diff --git a/docs/en/030_Document_Object_Model/010_Document/020_Document-C14N.md b/docs/en/030_Document_Object_Model/010_Document/020_Document-C14N.md new file mode 100644 index 0000000..c81916d --- /dev/null +++ b/docs/en/030_Document_Object_Model/010_Document/020_Document-C14N.md @@ -0,0 +1,13 @@ +--- +title: Document::C14N +--- + +Document::C14N — **DISABLED** + +## Description ## + +```php +public Document::C14N ( bool $exclusive = false , bool $withComments = false , array|null $xpath = null , array|null $nsPrefixes = null ) : false +``` + +This function has been disabled and will always return `false`. `\DOMDocument::C14N` is an extremely slow and inefficient method to serialize DOM and never should be used. Documented to show difference from [`\DOMDocument`](https://www.php.net/manual/en/class.domdocument.php). \ No newline at end of file diff --git a/docs/en/030_Document_Object_Model/010_Document/020_Document-C14NFile.md b/docs/en/030_Document_Object_Model/010_Document/020_Document-C14NFile.md new file mode 100644 index 0000000..d7c8dc2 --- /dev/null +++ b/docs/en/030_Document_Object_Model/010_Document/020_Document-C14NFile.md @@ -0,0 +1,13 @@ +--- +title: Document::C14NFile +--- + +Document::C14NFile — **DISABLED** + +## Description ## + +```php +public Document::C14NFile ( string $uri , bool $exclusive = false , bool $withComments = false , array|null $xpath = null , array|null $nsPrefixes = null ) : false +``` + +This function has been disabled and will always return `false`. `\DOMDocument::C14NFile` is an extremely slow and inefficient method to serialize DOM and never should be used. Documented to show difference from [`\DOMDocument`](https://www.php.net/manual/en/class.domdocument.php). \ No newline at end of file diff --git a/docs/en/030_Document_Object_Model/010_Document/index.md b/docs/en/030_Document_Object_Model/010_Document/index.md index a59541d..cd4023c 100644 --- a/docs/en/030_Document_Object_Model/010_Document/index.md +++ b/docs/en/030_Document_Object_Model/010_Document/index.md @@ -11,6 +11,7 @@ Represents an entire HTML document; serves as the root of the document tree. Unl

Info Only new methods and methods which make outward-facing changes from \DOMDocument will be documented here, otherwise they will be linked back to PHP's documentation.

MensBeam\HTML\Document extends \DOMDocument {
+    use Walk;
 
     /* Constants */
     public const NO_QUIRKS_MODE = 0 ;
@@ -18,26 +19,26 @@ Represents an entire HTML document; serves as the root of the document tree. Unl
     public const LIMITED_QUIRKS_MODE = 2 ;
 
     /* Properties */
-    public string|null $documentEncoding = null ;
-    public int $quirksMode = 0 ;
+    public string|null $documentEncoding = null ;
+    public int $quirksMode = 0 ;
 
     /* Inherited properties from \DOMDocument */
     public readonly DocumentType $doctype ;
     public readonly Element $documentElement ;
     public string|null $documentURI ;
-    public readonly \DOMImplementation $implementation ;
+    public readonly \DOMImplementation $implementation ;
 
     /* Inherited properties from \DOMNode */
     public readonly string $nodeName ;
     public string $nodeValue ;
     public readonly int $nodeType ;
-    public readonly \DOMNode|null $parentNode ;
-    public readonly \DOMNodeList $childNodes ;
-    public readonly \DOMNode|null $firstChild ;
-    public readonly \DOMNode|null $lastChild ;
-    public readonly \DOMNode|null $previousSibling ;
-    public readonly \DOMNode|null $nextSibling ;
-    public readonly \DOMNamedNodeMap|null $attributes ;
+    public readonly \DOMNode|null $parentNode ;
+    public readonly \DOMNodeList $childNodes ;
+    public readonly \DOMNode|null $firstChild ;
+    public readonly \DOMNode|null $lastChild ;
+    public readonly \DOMNode|null $previousSibling ;
+    public readonly \DOMNode|null $nextSibling ;
+    public readonly \DOMNamedNodeMap|null $attributes ;
     public readonly Document|null $ownerDocument ;
     public readonly string|null $namespaceURI ;
     public string $prefix ;
@@ -48,16 +49,60 @@ Represents an entire HTML document; serves as the root of the document tree. Unl
     /* Methods */
     public __construct ( )
     public createEntityReference ( string $name ) : false
+    public C14N ( bool $exclusive = false , bool $withComments = false , array|null $xpath = null , array|null $nsPrefixes = null ) : false
+    public C14NFile ( string $uri , bool $exclusive = false , bool $withComments = false , array|null $xpath = null , array|null $nsPrefixes = null ) : false
     public load ( string $filename , null $options = null , string|null $encodingOrContentType = null ) : bool
     public loadHTML ( string $source , null $options = null , string|null $encodingOrContentType = null ) : bool
     public loadHTMLFile ( string $filename , null $options = null , string|null $encodingOrContentType = null ) : bool
     public loadXML ( string $source , null $options = null ) : false
     public save ( string $filename , null $options = null ) : int|false
     public saveHTMLFile ( string $filename , null $options = null ) : int|false
-    public saveXML ( DOMNode|null $node = null , null $options = null ) : false
+    public saveXML ( \DOMNode|null $node = null , null $options = null ) : false
     public validate ( ) : true
     public xinclude ( null $options = null ) : false
 
+    /* Methods from Walk */
+    public walk ( \Closure $filter ) : \Generator
+
+    /* Methods inherited from \DOMDocument */
+    public createAttribute ( string $localName ) : \DOMAttr|false
+    public createAttributeNS ( string|null $namespace , string $qualifiedName ) : \DOMAttr|false
+    public createCDATASection ( string $data ) : \DOMCdataSection|false
+    public createComment ( string $data ) : Comment|false
+    public createDocumentFragment ( ) : DocumentFragment|false
+    public createElement ( string $localName , string $value = "" ) : Element|false
+    public createElementNS ( string|null $namespace , string $qualifiedName , string $value = "" ) : Element|false
+    public createProcessingInstruction ( string $target , string $data = "" ) : ProcessingInstruction|false
+    public createTextNode ( string $data ) : Text|false
+    public getElementById ( string $elementId ) : Element|null
+    public getElementsByTagName ( string $qualifiedName ) : \DOMNodeList
+    public getElementsByTagNameNS ( string $namespace , string $localName ) : \DOMNodeList
+    public importNode ( \DOMNode $node , bool $deep = false ) : \DOMNode|false
+    public normalizeDocument ( ) : void
+    public registerNodeClass ( string $baseClass , string|null $extendedClass ) : bool
+    public relaxNGValidate ( string $filename ) : bool
+    public relaxNGValidateSource ( string $source ) : bool
+    public saveHTML ( \DOMNode|null $node = null ) : string|false
+    public schemaValidate ( string $filename , int $flags = 0 ) : bool
+    public schemaValidateSource ( string $source , int $flags = 0 ) : bool
+
+    /* Methods inherited from \DOMNode */
+    public \DOMNode::appendChild ( \DOMNode $node ) : \DOMNode|false
+    public \DOMNode::cloneNode ( bool $deep = false ) : \DOMNode|false
+    public \DOMNode::getLineNo ( ) : int
+    public \DOMNode::getNodePath ( ) : string|null
+    public \DOMNode::hasAttributes ( ) : bool
+    public \DOMNode::hasChildNodes ( ) : bool
+    public \DOMNode::insertBefore ( \DOMNode $node , \DOMNode|null $child = null ) : \DOMNode|false
+    public \DOMNode::isDefaultNamespace ( string $namespace ) : bool
+    public \DOMNode::isSameNode ( \DOMNode $otherNode ) : bool
+    public \DOMNode::isSupported ( string $feature , string $version ) : bool
+    public \DOMNode::lookupNamespaceUri ( string $prefix ) : string
+    public \DOMNode::lookupPrefix ( string $namespace ) : string|null
+    public \DOMNode::normalize ( ) : void
+    public \DOMNode::removeChild ( \DOMNode $child ) : \DOMNode|false
+    public \DOMNode::replaceChild ( \DOMNode $node , \DOMNode $child ) : \DOMNode|false
+
 }
## Constants ## @@ -78,7 +123,7 @@ Represents an entire HTML document; serves as the root of the document tree. Unl
Used when parsing. Specifies which mode the document was parsed in. One of the predefined quirks mode constants.
-The following properties inherited from `\DOMDocument` have no effect in `Mensbeam\HTML\Document`, so therefore are not listed in the schema above: +The following properties inherited from [`\DOMDocument`](https://www.php.net/manual/en/class.domdocument.php) have no effect in `Mensbeam\HTML\Document`, so therefore are not listed in the schema above: * actualEncoding * config diff --git a/docs/en/030_Document_Object_Model/Walk/010_Walk-walk.md b/docs/en/030_Document_Object_Model/Walk/010_Walk-walk.md new file mode 100644 index 0000000..2e4cae0 --- /dev/null +++ b/docs/en/030_Document_Object_Model/Walk/010_Walk-walk.md @@ -0,0 +1,46 @@ +--- +title: Walk::walk +--- + +Walk::walk — Output generator for walking down the DOM tree + +## Description ## + +```php +public Walk::walk ( \Closure $filter ) : \Generator +``` + +Creates a `\Generator` object for walking down the DOM tree. + +## Examples ## + +**Example \#1 Print name of every Element** + +```php +loadHTML('Ook!

Eek

'); +$tree = $dom->walk(function($node) { + return ($node instanceof Element); +}); + +foreach ($tree as $t) { + echo "{$t->nodeName}\n"; +} + +?> +``` + +The above example will output something similar to: + +```php +html +head +title +body +h1 + +``` \ No newline at end of file diff --git a/docs/en/030_Document_Object_Model/Walk/index.md b/docs/en/030_Document_Object_Model/Walk/index.md new file mode 100644 index 0000000..efd6a66 --- /dev/null +++ b/docs/en/030_Document_Object_Model/Walk/index.md @@ -0,0 +1,11 @@ +# The Walk trait # + +## Introduction ## + +Allows nodes to walk down the DOM via a [`\Generator`](https://www.php.net/manual/en/class.generator.php). + +
trait MensBeam\HTML\Walk {
+
+    public walk ( \Closure $filter ) : \Generator
+
+}
\ No newline at end of file diff --git a/lib/DOM/Comment.php b/lib/DOM/Comment.php index 667decc..5d8e66a 100644 --- a/lib/DOM/Comment.php +++ b/lib/DOM/Comment.php @@ -7,7 +7,7 @@ declare(strict_types=1); namespace MensBeam\HTML; class Comment extends \DOMComment { - use Moonwalk; + use C14N, Moonwalk; public function __toString(): string { # Append the literal string "