The DOMImplementation class
(PHP 5)
Introduction
The DOMImplementation interface provides a number of methods for performing operations that are independent of any particular instance of the document object model.
Class synopsis
DOMImplementation
{
/* Properties */
/* Methods */
__construct
( void
)
public DOMDocument createDocument
([ string
$namespaceURI
= NULL
[, string $qualifiedName
= NULL
[, DOMDocumentType $doctype
= NULL
]]] )
public DOMDocumentType createDocumentType
([ string
}$qualifiedName
= NULL
[, string $publicId
= NULL
[, string $systemId
= NULL
]]] )Table of Contents
- DOMImplementation::__construct — Creates a new DOMImplementation object
- DOMImplementation::createDocument — Creates a DOMDocument object of the specified type with its document element
- DOMImplementation::createDocumentType — Creates an empty DOMDocumentType object
- DOMImplementation::hasFeature — Test if the DOM implementation implements a specific feature
- Введение
- Установка и настройка
- Предопределенные константы
- Examples
- Класс DOMAttr
- Класс DOMCdataSection
- Класс DOMCharacterData
- Класс DOMComment
- Класс DOMDocument
- Класс DOMDocumentFragment
- Класс DOMDocumentType
- Класс DOMElement
- Класс DOMEntity
- Класс DOMEntityReference
- Класс DOMException
- Класс DOMImplementation
- Класс DOMNamedNodeMap
- Класс DOMNode
- Класс DOMNodeList
- Класс DOMNotation
- Класс DOMProcessingInstruction
- The DOMText class
- Класс DOMXPath
- DOM Функции
Коментарии
Ok got it working like a charm using "proxy pattern" with traits. The idea being declaring the common methods inside a "trait" in order for extended and registered Node Classes to have access even if not derived / child of the extended DOMNode…
Here a small snippet :
<?php
namespace my;
trait tNode
{ // We need the magic method __get in order to add properties such as DOMNode->parentElement
public function __get($name)
{ if(property_exists($this, $name)){return $this->$name;}
if(method_exists($this, $name)){return $this->$name();}
throw new \ErrorException('my\\Node property \''.(string) $name.'\' not found…', 42, E_USER_WARNING);
}
// parentElement property definition
private function parentElement()
{ if($this->parentNode === null){return null;}
if($this->parentNode->nodeType === XML_ELEMENT_NODE){return $this->parentNode;}
return $this->parentNode->parentElement();
}
// JavaScript equivalent
public function isEqualNode(\DOMNode $node){return $this->isSameNode($node);}
public function compareDocumentPosition(\DOMNode $otherNode)
{ if($this->ownerDocument !== $otherNode->ownerDocument){return DOCUMENT_POSITION_DISCONNECTED;}
$c = strcmp($this->getNodePath(), $otherNode->getNodePath());
if($c === 0){return 0;}
else if($c < 0){return DOCUMENT_POSITION_FOLLOWING | ($c < -1 ? DOCUMENT_POSITION_CONTAINED_BY : 0);}
return DOCUMENT_POSITION_PRECEDING | ($c > 1 ? DOCUMENT_POSITION_CONTAINS : 0);
}
public function contains(\DOMNode $otherNode){return ($this->compareDocumentPosition($otherNode) >= DOCUMENT_POSITION_CONTAINED_BY);}
}
class Document extends \DomDocument
{ public function __construct($version=null, $encoding=null)
{ parent::__construct($version, $encoding);
$this->registerNodeClass('DOMNode', 'my\Node');
$this->registerNodeClass('DOMElement', 'my\Element');
$this->registerNodeClass('DOMDocument', 'my\Document');
/* [...] */
}
}
class Element extends \DOMElement
{ use tNode;
/* [...] */
}
class Node extends \DOMNode
{ use tNode;
/* [...] */
}
?>