|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* To change this license header, choose License Headers in Project Properties. |
|
5
|
|
|
* To change this template file, choose Tools | Templates |
|
6
|
|
|
* and open the template in the editor. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace OBRSDK\Entidades\Abstratos; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Description of ABancos |
|
13
|
|
|
* |
|
14
|
|
|
* @author Antonio |
|
15
|
|
|
*/ |
|
16
|
|
|
abstract class AEntidadePropriedades extends AEntidadePreenchimento { |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* |
|
20
|
|
|
* @param object $entidade |
|
21
|
|
|
* @return array |
|
22
|
|
|
*/ |
|
23
|
|
|
public function getAtributes($entidade = null) { |
|
24
|
|
|
$atributos = get_object_vars($entidade == null ? $this : $entidade); |
|
25
|
|
|
$atributosPreenchidos = []; |
|
26
|
|
|
foreach ($atributos as $atributoNome => $valor) { |
|
27
|
|
|
$atributoValor = $this->getAtributoValor($valor); |
|
28
|
|
|
if ($atributoValor != null) { |
|
29
|
|
|
$atributosPreenchidos[$atributoNome] = $atributoValor; |
|
30
|
|
|
} |
|
31
|
|
|
} |
|
32
|
|
|
return $atributosPreenchidos; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* |
|
37
|
|
|
* @param array $valor |
|
38
|
|
|
* @return array |
|
39
|
|
|
*/ |
|
40
|
|
|
private function percorrerArrayAtributo($valor) { |
|
41
|
|
|
$atributoValor = []; |
|
42
|
|
|
|
|
43
|
|
|
foreach ($valor as $v) { |
|
44
|
|
|
if (is_object($v)) { |
|
45
|
|
|
$atributoValor[] = $this->getAtributes($v); |
|
46
|
|
|
} else { |
|
47
|
|
|
$atributoValor[] = $v; |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
return $atributoValor; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
private function getAtributoValor($atributoValor) { |
|
55
|
|
|
$returnable = null; |
|
56
|
|
|
if (is_array($atributoValor)) { |
|
57
|
|
|
$returnable = $this->percorrerArrayAtributo($atributoValor); |
|
58
|
|
|
} else if (is_object($atributoValor)) { |
|
59
|
|
|
$returnable = $this->getAtributes($atributoValor); |
|
60
|
|
|
} else { |
|
61
|
|
|
$returnable = $atributoValor; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
return count($returnable) > 0 ? $returnable : null; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/// ==== |
|
68
|
|
|
/// MAGIC METHODS |
|
69
|
|
|
/// ==== |
|
70
|
|
|
|
|
71
|
|
|
public function __get($name) { |
|
72
|
|
|
if (property_exists($this, $name)) { |
|
73
|
|
|
return $this->$name; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function __call($metodo, $param) { |
|
78
|
|
|
if (strtolower(substr($metodo, 0, 3)) == "get") { |
|
79
|
|
|
$get = substr($metodo, 3); |
|
80
|
|
|
$property = $this->pascalCaseParaUnderscore($get); |
|
81
|
|
|
|
|
82
|
|
|
return $this->$property; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
} |
|
87
|
|
|
|