1
|
|
|
<?php |
2
|
|
|
namespace NFePHP\EFD\Common; |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Classe abstrata basica de onde cada bloco é cunstruido |
6
|
|
|
*/ |
7
|
|
|
abstract class Block |
8
|
|
|
{ |
9
|
|
|
public $elements = []; |
10
|
|
|
protected $bloco = ''; |
11
|
|
|
protected $elementTotal; |
12
|
|
|
|
13
|
|
|
public function __construct($total) |
14
|
|
|
{ |
15
|
|
|
$this->elementTotal = $total; |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Call classes to build each EFD element |
20
|
|
|
* @param string $name |
21
|
|
|
* @param array $arguments [std] |
22
|
|
|
* @return void |
23
|
|
|
* @throws \Exception |
24
|
|
|
*/ |
25
|
|
|
public function __call($name, $arguments) |
26
|
|
|
{ |
27
|
|
|
$name = str_replace('-', '', strtolower($name)); |
28
|
|
|
$realname = $name; |
29
|
|
|
if (!array_key_exists($realname, $this->elements)) { |
30
|
|
|
throw new \Exception("Não encontrada referencia ao método $name."); |
31
|
|
|
} |
32
|
|
|
$className = $this->elements[$realname]['class']; |
33
|
|
|
if (empty($arguments[0])) { |
34
|
|
|
throw new \Exception("Sem dados passados para o método [$name]."); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
$elclass = new $className($arguments[0]); |
38
|
|
|
|
39
|
|
|
//aqui deve ser feita a construção do bloco |
40
|
|
|
//para fazer a montagem verificar o elemento pai |
41
|
|
|
//se não existir elemento pai no bloco disparar um exception |
42
|
|
|
//$parent = $elclass::PARENT; |
43
|
|
|
|
44
|
|
|
//o parent pode ser um ou multipos separados por | |
45
|
|
|
//se não existir o parent então apenas acrescentar sem necessidade |
46
|
|
|
//de verificação |
47
|
|
|
//TODO |
48
|
|
|
|
49
|
|
|
$this->bloco .= "{$elclass}\n"; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Totalizes the elements of the block and returns the complete block |
54
|
|
|
* in a string adding element 0990 |
55
|
|
|
* @return string |
56
|
|
|
*/ |
57
|
|
|
public function get() |
58
|
|
|
{ |
59
|
|
|
//fazer a montagem do elemento 0990 Totalizador |
60
|
|
|
$n = count(explode("\n", $this->bloco)); |
61
|
|
|
$this->bloco .= "|" . $this->elementTotal . "|$n|\n"; |
62
|
|
|
return $this->bloco; |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|