API Documentation for: 1.1.1
Show:

Document Class

Extends NodeContainer
Namespace: Canteen\HTML5

Create an HTML document. Basic barebones structure. Located in the namespace Canteen\HTML5.

$doc = new HTML5\Document('Untitled');
$doc->head->addChild(html('script src=main.js'));
$doc->body->addChild(html('div#frame'));
echo $doc;

Constructor

Document

(
  • [title='']
  • [charset='utf-8']
  • [beautify=false]
)

Parameters:

  • [title=''] String optional

    The title of the document

  • [charset='utf-8'] String optional

    The character encoding set of this HTML document

  • [beautify=false] Boolean optional

    If we should add whitespace to the output to make it look nice markup.

Methods

__get

(
  • name
)

Inherited from Node:

General purpose getter to get attribute values

Parameters:

  • name String

    The name of the property to set

__isset

(
  • name
)

Inherited from Node:

See if a property exists

Parameters:

  • name String

    The name of the attribute

__set

(
  • name
  • value
)

Inherited from Node:

General purpose setter to set attribute values

Parameters:

  • name String

    The name of the attribute

  • value String

    The value of the attribute

__toString

() String

Inherited from Node

Write to HTML

Returns:

String:

The string representation of this HTML node

addChild

(
  • childNode
)
NodeContainer

Inherited from NodeContainer:

Add's a child to this NodeContainer. The child to add cannot be null.

Parameters:

Returns:

NodeContainer:

The instance of this container

addChildAt

(
  • childNode
  • index
)
NodeContainer

Inherited from NodeContainer:

Add a child at a specific index

Parameters:

Returns:

NodeContainer:

The instance of this container

appendTo

(
  • container
)
Node

Inherited from Node:

Add this child to a node container at the end

Parameters:

Returns:

Node:

The instance of this Node

beautify

(
  • html
)
String static

Beautifies an HTML string into a human-readable and indented work of art.

Parameters:

  • html String

    The XML-compatible HTML as a string

Returns:

String:

The formatted string

getAttribute

(
  • [name=null]
)
String

Inherited from Node:

Fetch and attribute by name from this Node. The attribute name cannot be null; if so, this function will throw an Exception.

Parameters:

  • [name=null] String optional

    The name of the attribute to fetch

Returns:

String:

The attribute's value, if any or null

getChildAt

(
  • [index=0]
)
Node

Inherited from NodeContainer:

Gets a child of this Node container at given index. If no index is passed in, getChild() will return the child at index zero (0).

Parameters:

  • [index=0] Int optional

    The index to fetch child Node at

Returns:

Node:

The child Node

getChildren

() Array

Inherited from NodeContainer:

Returns an array of all children attached to this Node container.

Returns:

Array:

The collection of Node objects

getData

(
  • name
)
String

Inherited from Node:

Get the data-* HTML5 attribute value, if set

Parameters:

  • name String

    The name of the data attribute

Returns:

String:

The value of the data

getParent

() NodeContainer private

Inherited from Node:

Returns the parent node of this node, if a parent exists. If no parent exists, this function returns null.

Returns:

NodeContainer:

The parent node object

isEmpty

(
  • var
)
protected

Inherited from Node:

Checks if a variable is really "empty". Code borrowed from PHP.net at http://us3.php.net/manual/en/function.empty.php#90767 because we were previously using empty() to see if a variable is empty or not. But empty() dosen't work for attributes that have a value of "0", so we need something more robust here.

  • an unset variable -> empty
  • null -> empty
  • 0 -> NOT empty
  • "0" -> NOT empty
  • false -> empty
  • true -> NOT empty
  • 'string value' -> NOT empty
  • " "(white space) -> empty
  • array()(empty array) -> empty

Parameters:

  • var Mixed

    The variable to check for empty on

prepareChild

(
  • childNode
)
Node protected

Inherited from NodeContainer:

Before adding a child, we should do some checking for basic types and convert it into a more useable Node object.

Parameters:

Returns:

Node:

The child node

prependTo

(
  • container
)
Node

Inherited from Node:

Add this child to the beginning of a node container

Parameters:

Returns:

Node:

The instance of this Node

removeChild

(
  • [childNode=null]
)
Boolean

Inherited from NodeContainer:

Removes the first instance of child from this.
Once the first instance of the child is removed, this function will return. It returns true if a child was removed and false if no child was removed.

Parameters:

  • [childNode=null] Node optional

    The node to remove

Returns:

Boolean:

If successfully removed

removeChildAt

(
  • index
)
NodeContainer

Inherited from NodeContainer:

Remove a child as a specific index

Parameters:

  • index Int

    The index to remove child at

Returns:

NodeContainer:

The instance of the node container

removeChildren

() NodeContainer

Inherited from NodeContainer:

Removes all children attached to this Node container

Returns:

NodeContainer:

The instance of the node container

setAttribute

(
  • [name=null]
  • [value=null]
  • The
)

Inherited from Node:

Given a name and value pair, sets an attribute on this Node. The name and value cannot be empty; if so, this function will throw an Exception. Note if the attribute already exists and the caller wants to set an attribute of the same name, this function will not create a new Attribute, but rather update the value of the existing named attribute.

Parameters:

  • [name=null] String optional

    The name of the attribute to add

  • [value=null] String optional

    The value of the attribute

  • The Node

    instance of this node

setAttributes

(
  • values
)
Node

Inherited from Node:

Set the list of all attributes.

Parameters:

  • values Dictionary

    An attributes array(name=>value, name=>value)

Returns:

Node:

The instance of this Node

setParent

(
  • [parent=null]
)
protected

Inherited from Node:

Sets the parent of this Node. Note that this function is protected and can only be called by classes that extend Node. The parent cannot be null; this function will throw an Exception if the parent node is empty.

Parameters:

writeClose

() String protected

Inherited from NodeContainer:

Close the writing of this container as HTML

Returns:

String:

The closing HTML tag element

writeOpen

(
  • [selfClose=true]
)
String protected

Inherited from Node:

Start the writing the tag

Parameters:

  • [selfClose=true] Boolean optional

    If the tag is a self closing tag (e.g., br, img, hr)

Returns:

String:

The buffer of HTML

Properties

_attributes

Array protected

Inherited from Node:

The collection of Attributes objects

_children

Array private

Inherited from NodeContainer:

The collection of children nodes

_parent

NodeContainer protected

Inherited from Node:

The parent node, if any

_tag

String protected

Inherited from Node:

The string name of the tag

_validAttrs

Array protected

Inherited from Node:

The collection of valid attributes names for given tag

beautify

Boolean

Beautify the output

body

NodeContainer

The body node

docType

NodeContainer

The document type

head

NodeContainer

The head node

title

NodeContainer

The title node