Skip to content
Thomas Weinert edited this page Aug 16, 2014 · 17 revisions

Creator

(FluentDOM 5.1)

The FluentDOM\Nodes\Creator is a functor, a class usable like a function. In PHP you implement the magic method __invoke to support this. It allows you to have a function with a state/configuration.

You can use the FluentDOM::create() method to get a new instance and assign it to a variable.

Basic Usage

The first argument of the function is the node name. The returned object can be cast to string.

$_ = FluentDOM::create();
echo $_('ul');

Output

<?xml version="1.0" encoding="UTF-8"?>
<ul/>

Attributes And Child Nodes

Other arguments can set attributes (arrays or attribute nodes) and add text nodes (string) or child elements.

$_ = FluentDOM::create();
echo $_(
  'ul',
  ['class' => 'navigation'],
  $_('li', 'FluentDOM')
);

Output

<?xml version="1.0" encoding="UTF-8"?>
<ul class="navigation"><li>FluentDOM</li></ul>
Clone this wiki locally