1
|
|
|
<?php |
2
|
|
|
namespace PHPTools\PHPHtmlDom\Core; |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Esta clae contiene los metodos abstractos para todo PHPHtmlDomElement |
6
|
|
|
*/ |
7
|
|
|
abstract class PHPHtmlDomElementAbstract |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* Permite saber si el elemento posee una clase. |
11
|
|
|
* @param string $classname Cadena de texto con el nombre d ela clase a buscar. |
12
|
|
|
* @return boolean |
13
|
|
|
*/ |
14
|
|
|
final public function hasclass($classname) |
15
|
|
|
{ |
16
|
|
|
return !!$this->hasattr('class')?in_array($classname, explode(' ', $this->attrs->class)):FALSE; |
|
|
|
|
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Permite saber si el elemento tiene definido un atributo. |
21
|
|
|
* @param string $attr cadena de texto con el nombre del atributo a buscar. |
22
|
|
|
* @return boolean |
23
|
|
|
*/ |
24
|
|
|
final public function hasattr($attr) |
25
|
|
|
{ |
26
|
|
|
return !!isset($this->attrs->{$attr}); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Permite obtener el valor de un attributo del elemento. |
31
|
|
|
* @param string $inx Cadena de texto con el nombre del aatributo a obtener |
32
|
|
|
* @return string|NULL Devuelve el valor del atributo si el mismo se encuentra definido o NULL en caso contrario. |
33
|
|
|
*/ |
34
|
|
|
final public function attr($inx) |
35
|
|
|
{ |
36
|
|
|
return !!$this->hasattr($inx)?$this->attrs->{$inx}:NULL; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Permite obtener el valor de un atributo tipo data. |
41
|
|
|
* @param string $inx Cadena de texto con el nombre del atributo a obtener sin la palabra data |
42
|
|
|
* @return string|NULL Devuelve el valor del atributo si el mismo se encuentra definido o NULL en caso contrario. |
43
|
|
|
*/ |
44
|
|
|
final public function data($inx) |
45
|
|
|
{ |
46
|
|
|
return $this->attr(sprintf('data-%s',$inx)); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Permite obtener el elemeno padre si lo posee |
51
|
|
|
* @return PHPHtmlDomElement|DOMDocument |
52
|
|
|
*/ |
53
|
|
|
final public function parent() |
54
|
|
|
{ |
55
|
|
|
$parent = NULL; |
56
|
|
|
|
57
|
|
|
if(!!isset($this->dom_element->parentNode)) |
58
|
|
|
{ |
59
|
|
|
if($this->dom_element->parentNode->nodeType == 1) |
60
|
|
|
{ |
61
|
|
|
$parent = new PHPHtmlDomElement($this->dom_element->parentNode); |
|
|
|
|
62
|
|
|
} |
63
|
|
|
else |
64
|
|
|
{ |
65
|
|
|
$parent = $this->dom_element->parentNode; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
return $parent; |
69
|
|
|
} |
70
|
|
|
} |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: