|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: Giansalex |
|
5
|
|
|
* Date: 12/08/2017 |
|
6
|
|
|
* Time: 18:06 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Greenter\Factory; |
|
10
|
|
|
|
|
11
|
|
|
use Greenter\Model\Response\BillResult; |
|
12
|
|
|
use Greenter\Model\Response\SummaryResult; |
|
13
|
|
|
use Greenter\Security\SignedXml; |
|
14
|
|
|
use Greenter\Ws\Services\FeSunat; |
|
15
|
|
|
use Greenter\Ws\Services\WsSunatInterface; |
|
16
|
|
|
use Greenter\Zip\ZipFactory; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Class BaseFactory |
|
20
|
|
|
* @package Greenter\Factory |
|
21
|
|
|
*/ |
|
22
|
|
|
class BaseFactory |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @var SignedXml |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $signer; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var ZipFactory |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $zipper; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @var WsSunatInterface |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $sender; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Ultimo xml generado. |
|
41
|
|
|
* |
|
42
|
|
|
* @var string |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $lastXml; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* BaseFactory constructor. |
|
48
|
|
|
*/ |
|
49
|
60 |
|
public function __construct() |
|
50
|
|
|
{ |
|
51
|
60 |
|
$this->signer = new SignedXml(); |
|
52
|
60 |
|
$this->sender = new FeSunat(); |
|
53
|
60 |
|
$this->zipper = new ZipFactory(); |
|
54
|
60 |
|
$this->sender->setUrlWsdl(__DIR__.'/../Resources/wsdl/billService.wsdl'); |
|
55
|
60 |
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @param array $ws |
|
59
|
|
|
*/ |
|
60
|
60 |
|
protected function setWsParams($ws) |
|
61
|
|
|
{ |
|
62
|
60 |
|
$this->sender->setCredentials($ws['user'], $ws['pass']); |
|
63
|
60 |
|
if (isset($ws['service'])) { |
|
64
|
60 |
|
$this->sender->setService($ws['service']); |
|
65
|
60 |
|
} |
|
66
|
60 |
|
if (isset($ws['wsdl'])) { |
|
67
|
|
|
$this->sender->setUrlWsdl($ws['wsdl']); |
|
68
|
|
|
} |
|
69
|
60 |
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param string $xml |
|
73
|
|
|
* @param string $filename |
|
74
|
|
|
* @return BillResult |
|
75
|
|
|
*/ |
|
76
|
26 |
View Code Duplication |
protected function getBillResult($xml, $filename) |
|
|
|
|
|
|
77
|
|
|
{ |
|
78
|
26 |
|
$this->lastXml = $this->getXmmlSigned($xml); |
|
79
|
|
|
|
|
80
|
26 |
|
$zip = $this->zipper->compress("$filename.xml", $this->lastXml); |
|
81
|
26 |
|
return $this->sender->send("$filename.zip", $zip); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @param string $xml |
|
86
|
|
|
* @param string $filename |
|
87
|
|
|
* @return SummaryResult |
|
88
|
|
|
*/ |
|
89
|
10 |
View Code Duplication |
protected function getSummaryResult($xml, $filename) |
|
|
|
|
|
|
90
|
|
|
{ |
|
91
|
10 |
|
$this->lastXml = $this->getXmmlSigned($xml); |
|
92
|
|
|
|
|
93
|
10 |
|
$zip = $this->zipper->compress("$filename.xml", $this->lastXml); |
|
94
|
10 |
|
return $this->sender->sendSummary("$filename.zip", $zip); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @param string $xml |
|
99
|
|
|
* @return string |
|
100
|
|
|
*/ |
|
101
|
36 |
|
private function getXmmlSigned($xml) |
|
102
|
|
|
{ |
|
103
|
36 |
|
return $this->signer->sign($xml); |
|
104
|
|
|
} |
|
105
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.