1 | <?php |
||
24 | class FeFactory implements FactoryInterface |
||
25 | { |
||
26 | /** |
||
27 | * @var SignedXml |
||
28 | */ |
||
29 | private $signer; |
||
30 | |||
31 | /** |
||
32 | * @var ZipFactory |
||
33 | */ |
||
34 | private $zipper; |
||
35 | |||
36 | /** |
||
37 | * @var SenderInterface |
||
38 | */ |
||
39 | private $sender; |
||
40 | |||
41 | /** |
||
42 | * Ultimo xml generado. |
||
43 | * |
||
44 | * @var string |
||
45 | */ |
||
46 | private $lastXml; |
||
47 | |||
48 | /** |
||
49 | * @var BuilderInterface |
||
50 | */ |
||
51 | private $builder; |
||
52 | |||
53 | /** |
||
54 | * @var DocumentValidatorInterface |
||
55 | */ |
||
56 | private $validator; |
||
57 | |||
58 | /** |
||
59 | * @param $validator |
||
60 | * @return FeFactory |
||
61 | */ |
||
62 | 68 | public function setValidator($validator) |
|
67 | |||
68 | /** |
||
69 | * BaseFactory constructor. |
||
70 | */ |
||
71 | 74 | public function __construct() |
|
76 | |||
77 | /** |
||
78 | * @return BuilderInterface |
||
79 | */ |
||
80 | 4 | public function getBuilder() |
|
81 | { |
||
82 | 4 | return $this->builder; |
|
83 | } |
||
84 | |||
85 | /** |
||
86 | * @return SenderInterface |
||
87 | */ |
||
88 | 4 | public function getSender() |
|
89 | { |
||
90 | 4 | return $this->sender; |
|
91 | } |
||
92 | |||
93 | /** |
||
94 | * @param SenderInterface $sender |
||
95 | * @return FeFactory |
||
96 | */ |
||
97 | 68 | public function setSender($sender) |
|
102 | |||
103 | /** |
||
104 | * @param BuilderInterface $builder |
||
105 | * @return FeFactory |
||
106 | */ |
||
107 | 68 | public function setBuilder($builder) |
|
112 | |||
113 | /** |
||
114 | * @param DocumentInterface $document |
||
115 | * @return BaseResult |
||
116 | * @throws ValidationException |
||
117 | */ |
||
118 | 68 | public function send(DocumentInterface $document) |
|
119 | { |
||
120 | 68 | $errs = $this->validator->validate($document); |
|
121 | 68 | if (count($errs) > 0) { |
|
122 | 30 | throw new ValidationException($errs); |
|
123 | } |
||
124 | 38 | $xml = $this->builder->build($document); |
|
125 | 38 | $this->lastXml = $this->getXmmlSigned($xml); |
|
126 | 38 | $filename = $document->getName(); |
|
127 | |||
128 | 38 | $zip = $this->zipper->compress("$filename.xml", $this->lastXml); |
|
129 | 38 | return $this->sender->send("$filename.zip", $zip); |
|
130 | } |
||
131 | |||
132 | /** |
||
133 | * Set Certicated content |
||
134 | * @param string $cert |
||
135 | */ |
||
136 | 70 | public function setCertificate($cert) |
|
140 | |||
141 | /** |
||
142 | * Get Last XML Signed. |
||
143 | * |
||
144 | * @return string |
||
145 | */ |
||
146 | 10 | public function getLastXml() |
|
147 | { |
||
148 | 10 | return $this->lastXml; |
|
149 | } |
||
150 | |||
151 | /** |
||
152 | * @param string $xml |
||
153 | * @return string |
||
154 | */ |
||
155 | 38 | private function getXmmlSigned($xml) |
|
159 | } |