DiDom\Element::__construct PHP Метод

__construct() публичный Метод

Constructor.
public __construct ( DOMNode | string $name, string $value = null, array $attributes = [] )
$name DOMNode | string The tag name of the element
$value string The value of the element
$attributes array The attributes of the element
    public function __construct($name, $value = null, $attributes = [])
    {
        if (is_string($name)) {
            $document = new DOMDocument('1.0', 'UTF-8');
            $node = $document->createElement($name);
            $this->setNode($node);
        } else {
            $this->setNode($name);
        }
        if ($value !== null) {
            $this->setValue($value);
        }
        if (!is_array($attributes)) {
            throw new InvalidArgumentException(sprintf('%s expects parameter 3 to be array, %s given', __METHOD__, is_object($attributes) ? get_class($attributes) : gettype($attributes)));
        }
        foreach ($attributes as $name => $value) {
            $this->setAttribute($name, $value);
        }
    }

Usage Example

Пример #1
0
 /**
  * Constructor.
  *
  * @param \DOMElement $node The node associated with this field
  */
 public function __construct(\DOMElement $node)
 {
     parent::__construct($node);
     $this->name = $node->getAttribute('name');
     $this->initialize();
 }