1<?php 2/** 3 * Copyright (c) 2020. ComboStrap, Inc. and its affiliates. All Rights Reserved. 4 * 5 * This source code is licensed under the GPL license found in the 6 * COPYING file in the root directory of this source tree. 7 * 8 * @license GPL 3 (https://www.gnu.org/licenses/gpl-3.0.en.html) 9 * @author ComboStrap <support@combostrap.com> 10 * 11 */ 12 13namespace ComboStrap; 14 15 16class DomUtility 17{ 18 /** 19 * @param DOMElement $domElements 20 * @return array with one element by dom element with its attributes 21 * 22 * This funcion was created because there is no way to get this information 23 * from the phpQuery element 24 */ 25 static public function domElements2Attributes($domElements) 26 { 27 $nodes = array(); 28 foreach ($domElements as $key => $domElement) { 29 $nodes[$key] = self::extractsAttributes($domElement); 30 } 31 return $nodes; 32 } 33 34 /** 35 * @param DOMElement $domElement 36 * @return array with one element with its attributes 37 * 38 * This function was created because there is no way to get this information 39 * from the phpQuery element 40 */ 41 static public function extractsAttributes($domElement) 42 { 43 $node = array(); 44 if ($domElement->hasAttributes()) { 45 foreach ($domElement->attributes as $attr) { 46 $name = $attr->name; 47 $value = $attr->value; 48 $node[$name] = $value; 49 } 50 } 51 return $node; 52 } 53 54} 55