1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Genkgo\Camt\Camt052\Decoder; |
4
|
|
|
|
5
|
|
|
use Genkgo\Camt\Decoder\Message as BaseMessageDecoder; |
6
|
|
|
use Genkgo\Camt\Camt052\DTO as Camt052DTO; |
7
|
|
|
use Genkgo\Camt\DTO; |
8
|
|
|
use \SimpleXMLElement; |
9
|
|
|
use \DateTimeImmutable; |
10
|
|
|
use Genkgo\Camt\Iban; |
11
|
|
|
|
12
|
|
|
abstract class Message extends BaseMessageDecoder |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @param DTO\Message $message |
16
|
|
|
* @param SimpleXMLElement $document |
17
|
|
|
*/ |
18
|
4 |
|
public function addGroupHeader(DTO\Message $message, SimpleXMLElement $document) |
19
|
|
|
{ |
20
|
4 |
|
$xmlGroupHeader = $this->getRootElement($document)->GrpHdr; |
|
|
|
|
21
|
4 |
|
$groupHeader = new DTO\GroupHeader( |
22
|
4 |
|
(string)$xmlGroupHeader->MsgId, |
23
|
4 |
|
new DateTimeImmutable((string)$xmlGroupHeader->CreDtTm) |
24
|
4 |
|
); |
25
|
|
|
|
26
|
4 |
|
$message->setGroupHeader($groupHeader); |
27
|
4 |
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param DTO\Message $message |
31
|
|
|
* @param SimpleXMLElement $document |
32
|
|
|
*/ |
33
|
4 |
|
public function addRecords(DTO\Message $message, SimpleXMLElement $document) |
34
|
3 |
|
{ |
35
|
4 |
|
$reports = []; |
36
|
|
|
|
37
|
4 |
|
$xmlReports = $this->getRootElement($document)->Rpt; |
|
|
|
|
38
|
4 |
|
foreach ($xmlReports as $xmlReport) { |
39
|
4 |
|
$report = new Camt052DTO\Report( |
40
|
4 |
|
(string) $xmlReport->Id, |
41
|
4 |
|
new DateTimeImmutable((string)$xmlReport->CreDtTm), |
42
|
4 |
|
$this->getAccount($xmlReport) |
|
|
|
|
43
|
4 |
|
); |
44
|
|
|
|
45
|
4 |
|
$this->recordDecoder->addBalances($report, $xmlReport); |
46
|
4 |
|
$this->recordDecoder->addEntries($report, $xmlReport); |
47
|
|
|
|
48
|
4 |
|
$reports[] = $report; |
49
|
4 |
|
} |
50
|
|
|
|
51
|
4 |
|
$message->setRecords($reports); |
52
|
4 |
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param SimpleXMLElement $document |
56
|
|
|
* |
57
|
|
|
* @return SimpleXMLElement |
58
|
|
|
*/ |
59
|
|
|
abstract public function getRootElement(SimpleXMLElement $document); |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param SimpleXMLElement $xmlRecord |
63
|
|
|
* |
64
|
|
|
* @return DTO\Account |
65
|
|
|
*/ |
66
|
4 |
|
protected function getAccount(SimpleXMLElement $xmlRecord) |
67
|
|
|
{ |
68
|
4 |
|
if (isset($xmlRecord->Acct->Id->IBAN)) { |
69
|
3 |
|
return new DTO\IbanAccount(new Iban((string) $xmlRecord->Acct->Id->IBAN)); |
70
|
|
|
} |
71
|
|
|
|
72
|
4 |
|
if (isset($xmlRecord->Acct->Id->BBAN)) { |
73
|
|
|
return new Camt052DTO\BBANAccount((string) $xmlRecord->Acct->Id->BBAN); |
74
|
3 |
|
} |
75
|
|
|
|
76
|
4 |
|
if (isset($xmlRecord->Acct->Id->UPIC)) { |
77
|
3 |
|
return new Camt052DTO\UPICAccount((string) $xmlRecord->Acct->Id->UPIC); |
78
|
|
|
} |
79
|
|
|
|
80
|
4 |
|
if (isset($xmlRecord->Acct->Id->PrtryAcct)) { |
81
|
4 |
|
return new Camt052DTO\ProprietaryAccount((string) $xmlRecord->Acct->Id->PrtryAcct->Id); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
if (isset($xmlRecord->Acct->Id->Othr)) { |
85
|
|
|
$xmlOtherIdentification = $xmlRecord->Acct->Id->Othr; |
86
|
|
|
$otherAccount = new DTO\OtherAccount((string) $xmlOtherIdentification->Id); |
87
|
|
|
|
88
|
|
|
if (isset($xmlOtherIdentification->SchmeNm)) { |
89
|
|
|
if (isset($xmlOtherIdentification->SchmeNm->Cd)) { |
90
|
|
|
$otherAccount->setSchemeName((string) $xmlOtherIdentification->SchmeNm->Cd); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
if (isset($otherIdentification->SchmeNm->Prtry)) { |
|
|
|
|
94
|
|
|
$otherAccount->setSchemeName((string) $xmlOtherIdentification->SchmeNm->Prtry); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
if (isset($xmlOtherIdentification->Issr)) { |
99
|
|
|
$otherAccount->setIssuer($xmlOtherIdentification->Issr); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
return $otherAccount; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.