Dodo
DOm DOcument implementation
Loading...
Searching...
No Matches
Wikimedia\Dodo\NamedNodeMap Class Reference
+ Inheritance diagram for Wikimedia\Dodo\NamedNodeMap:

Public Member Functions

 __construct (?Element $element=null)
 
 _append (Attr $a)
 
 _replace (Attr $oldAttr, Attr $a)
 
 _remove (Attr $a)
 
int getLength ()
 
 item (int $index)
 
bool _hasNamedItem (string $qname)
 Nonstandard.
 
bool _hasNamedItemNS (?string $ns, string $lname)
 Nonstandard.
 
bool _hasNamedItemNode (Attr $a)
 Nonstandard.
 
Attr getNamedItem (string $qname)
 
Attr getNamedItemNS (?string $ns, string $lname)
 The getNamedItemNS(namespace, localName) method steps are to return the result of getting an attribute given namespace, localName, and element.
 
 setNamedItem ( $attr)
 The setNamedItem(attr) and setNamedItemNS(attr) method steps are to return the result of "setting an attribute" given attr and element.
 
 setNamedItemNS ( $attr)
 
Attr removeNamedItem (string $qname)
 Note: qname may be lowercase or normalized in various ways.
 
 removeNamedItemNS (?string $ns, string $lname)
 Note: lname may be lowercase or normalized in various ways.
 
- Public Member Functions inherited from Wikimedia::IDLeDOM::NamedNodeMap
Iterator< AttrgetIterator ()
 

Detailed Description

NamedNodeMap.php

Implements a NamedNodeMap. Used to represent Element::attributes.

NOTE: Why is it called NamedNodeMap?

 NamedNodeMap has nothing to do with Nodes, it's a collection
 of Attrs. But once upon a time, an Attr was a type of Node called a
 NamedNode. But then DOM-4 came along and said that an Attr is no
 longer a subclass of Node. But then DOM-LS came and change it again,
 and said it was a subclass of Node. NamedNode was forgotten, but it
 lives on in this interface's name! How confusing!

NOTE: "Qualified name" is the "prefix:localName" string, which is what the "methods not ending in NS" use, aka Element::getAttribute() looks up by "qualified name". Our code uses "qname" to refer to this. The "methods ending in NS" look up by a combination of namespace and local name (ignoring prefix) which this code calls a "nskey" (or $key for short).

There can be multiple attributes matching a given qname – ie, they can have different namespaces for the same prefix so they collide in the qname index but not the nskey index. The nskey index however should be unique: in all the paths that might seem to allow different prefixes for the same namespace the prefix is instead stored in the local name portion so that uniqueness of nskey is preserved. We maintain a one-to-many map given the qname key. For the nskey maps we could use the index->attribute map to recompute the 'first' attribute for an nskey on every removal, although the uniqueness of the nskey means this isn't necessary in practice.

NOTE: This looks different from Domino.js!

 In Domino.js, NamedNodeMap was only implemented to satisfy
 'instanceof' type-checking. Almost all of the methods were
 stubbed, except for 'length' and 'item'. The tables that
 stored an Element's attributes were located directly on the
 Element itself.

 Because there are so many attribute handling methods on an
 Element, each with little differences, this meant replicating
 a bunch of the book-keeping inside those methods. The negative
 impact on code maintainability was pronounced, so the book-keeping
 was transferred to the NamedNodeMap itself, and its methods were
 properly implemented, which made it much easier to read and write
 the attribute methods on the Element class.

-forbid-undeclared-magic-properties

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\Dodo\NamedNodeMap::__construct ( ?Element $element = null)
Parameters
?Element$element

Member Function Documentation

◆ getLength()

int Wikimedia\Dodo\NamedNodeMap::getLength ( )

◆ getNamedItem()

Attr Wikimedia\Dodo\NamedNodeMap::getNamedItem ( string $qname)

◆ getNamedItemNS()

Attr Wikimedia\Dodo\NamedNodeMap::getNamedItemNS ( ?string $ns,
string $lname )

The getNamedItemNS(namespace, localName) method steps are to return the result of getting an attribute given namespace, localName, and element.

See also
https://dom.spec.whatwg.org/#dom-namednodemap-getnameditemns
https://dom.spec.whatwg.org/#concept-element-attributes-get-by-namespace

Implements Wikimedia::IDLeDOM::NamedNodeMap.

◆ item()

Wikimedia\Dodo\NamedNodeMap::item ( int $index)

◆ removeNamedItem()

Attr Wikimedia\Dodo\NamedNodeMap::removeNamedItem ( string $qname)

Note: qname may be lowercase or normalized in various ways.

See also
https://dom.spec.whatwg.org/#dom-namednodemap-removenameditem

Implements Wikimedia::IDLeDOM::NamedNodeMap.

◆ removeNamedItemNS()

Wikimedia\Dodo\NamedNodeMap::removeNamedItemNS ( ?string $ns,
string $lname )

Note: lname may be lowercase or normalized in various ways.

See also
https://dom.spec.whatwg.org/#dom-namednodemap-removenameditemns

Implements Wikimedia::IDLeDOM::NamedNodeMap.

◆ setNamedItem()

Wikimedia\Dodo\NamedNodeMap::setNamedItem ( $attr)

The setNamedItem(attr) and setNamedItemNS(attr) method steps are to return the result of "setting an attribute" given attr and element.

See also
https://dom.spec.whatwg.org/#dom-namednodemap-setnameditem
https://dom.spec.whatwg.org/#concept-element-attributes-set

Implements Wikimedia::IDLeDOM::NamedNodeMap.

◆ setNamedItemNS()

Wikimedia\Dodo\NamedNodeMap::setNamedItemNS ( $attr)

The documentation for this class was generated from the following file: