DiDom\Element::attributes PHP Method

attributes() public method

Returns the node attributes or null, if it is not DOMElement.
public attributes ( ) : array | null
return array | null
    public function attributes()
    {
        if (!$this->node instanceof DOMElement) {
            return null;
        }
        $attributes = [];
        foreach ($this->node->attributes as $name => $attr) {
            $attributes[$name] = $attr->value;
        }
        return $attributes;
    }

Usage Example

示例#1
0
 public function testAttributes()
 {
     $attributes = ['type' => 'text', 'name' => 'username'];
     $element = new Element('input', null, $attributes);
     $this->assertEquals($attributes, $element->attributes());
 }