Overview

Namespaces

  • Tokamak
    • Dom

Classes

  • Component
  • Document
  • Element
  • HTMLDocument
  • Node
  • Overview
  • Namespace
  • Class

Class Node

Class Node

Direct known subclasses

Tokamak\Dom\Component, Tokamak\Dom\Document, Tokamak\Dom\Element

Indirect known subclasses

Tokamak\Dom\HTMLDocument
Abstract
Namespace: Tokamak\Dom
Package: Tokamak\Dom
Throws: RuntimeException
Located at Dom/Node.php
Methods summary
abstract public Tokamak\Dom\Node
# append( Tokamak\Dom\Node $node )

Append one Node instance as a child of another. Must be implemented differently for Element and Component, because the former is a single element that can have children, whereas the latter can represent a list of multiple top-level elements and components. Meanwhile, Document appends children to the top-level DOMDocument instance.

Append one Node instance as a child of another. Must be implemented differently for Element and Component, because the former is a single element that can have children, whereas the latter can represent a list of multiple top-level elements and components. Meanwhile, Document appends children to the top-level DOMDocument instance.

Parameters

$node
An Element or Component to be appended.

Returns

Tokamak\Dom\Node
Returns the child node for method chaining.
public Tokamak\Dom\Element
# appendElement( string $name, array $attributes = null, string $content = '', Closure $callback = null )

Syntactic sugar for constructing and then appending a new Element. Abstracts away the need to pass the ancestor DOMDocument to the child.

Syntactic sugar for constructing and then appending a new Element. Abstracts away the need to pass the ancestor DOMDocument to the child.

Parameters

$name
The element name ('div', 'a', 'body', etc.)
$attributes

Associative array of the element's attributes and their values. For "class", the value can also be an array of class names.

$content
The text content of the element.
$callback

A callback closure to be executed within the context of the child node. Allows a callback-chaining style for building the DOM tree.

Returns

Tokamak\Dom\Element
Returns the child Element for method chaining.
public Tokamak\Dom\Component
# appendComponent( string $name, array $data = null, Closure $callback = null )

Syntactic sugar for constructing and then appending a new Component. Abstracts away the need to pass the ancestor DOMDocument to the child. If a user-defined Component class of the requested name is not found, will look in the Tokamak\Dom\Components namespace for a built-in component class.

Syntactic sugar for constructing and then appending a new Component. Abstracts away the need to pass the ancestor DOMDocument to the child. If a user-defined Component class of the requested name is not found, will look in the Tokamak\Dom\Components namespace for a built-in component class.

Parameters

$name

The fully-qualified class name of a user-defined Component, or the name of a Component class in the Tokamak\Dom\Components namespace.

$data
Array of arbitrary data/state to be passed to the component
$callback

A callback closure to be executed within the context of the child node. Allows a callback-chaining style for building the DOM tree.

Returns

Tokamak\Dom\Component
Returns the child Element for method chaining.

Throws

RuntimeException
Thrown if $name does not refer to a defined Component class.
public
# setDom( DOMDocument $dom )

Inject an DOMDocument element as the ancestor of this node.

Inject an DOMDocument element as the ancestor of this node.

Parameters

$dom
public DOMDocument
# getDom( )

Get the underlying DOMDocument ancestor instance.

Get the underlying DOMDocument ancestor instance.

Returns

DOMDocument
protected
# addDomNode( DOMNode $node )

Add a DOMNode to the queue of nodes that will be appended to this node's parent.

Add a DOMNode to the queue of nodes that will be appended to this node's parent.

Parameters

$node
public DOMNode
# getDomNode( )

Remove a DOMNode from the queue of nodes to be appended to the parent and return it.

Remove a DOMNode from the queue of nodes to be appended to the parent and return it.

Returns

DOMNode
public boolean
# hasDomNodes( )

Does this instance have remaining DOMNode instances to be appended to the parent?

Does this instance have remaining DOMNode instances to be appended to the parent?

Returns

boolean
abstract protected
# render( )

Called by constructor. Must be implemented to define the DOM structure of an element or component. Works by adding nodes to the domNodes queue, either explicitly or via calls to Node::append.

Called by constructor. Must be implemented to define the DOM structure of an element or component. Works by adding nodes to the domNodes queue, either explicitly or via calls to Node::append.

Properties summary
protected static string $COMPONENT_NAMESPACE

Tokamak will look for components in this namespace if they are not defined elsewhere.

Tokamak will look for components in this namespace if they are not defined elsewhere.

# '\Tokamak\Dom\Components\\'
protected DOMDocument $dom

The underlying DOMDocument instance. Normally created by Tokamak\Dom\Document instance.

The underlying DOMDocument instance. Normally created by Tokamak\Dom\Document instance.

#
protected SplQueue<DOMNode> $domNodes

Queue of dom nodes to be appended to the parent node.

Queue of dom nodes to be appended to the parent node.

#
API documentation generated by ApiGen