createElement() public method

Allow to add a text content and attributes directly. If $content is an array, the $content argument will be merged with the $attributes argument.
public createElement ( string $name, string | array $content = NULL, array $attributes = NULL ) : Element
$name string
$content string | array
$attributes array
return Element
Beispiel #1
0
 /**
  * Create an Element node and configure it.
  *
  * The first argument is the node name. All other arguments are flexible.
  *
  * - Arrays are set as attributes
  * - Attribute and Namespace nodes are set as attributes
  * - Nodes are appended as child nodes
  * - FluentDOM\Appendable instances are appended
  * - Strings or objects castable to string are appended as text nodes
  *
  * @param string $name
  * @param mixed ...$parameters
  * @return \FluentDOM\Element
  */
 public function element($name, ...$parameters)
 {
     $node = $this->_document->createElement($name);
     foreach ($parameters as $parameter) {
         $node->append($parameter);
     }
     return $node;
 }