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