1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Genkgo\Camt\Camt053\Decoder; |
4
|
|
|
|
5
|
|
|
use Genkgo\Camt\Decoder\Message as BaseMessageDecoder; |
6
|
|
|
use Genkgo\Camt\Camt053\DTO as Camt053DTO; |
7
|
|
|
use Genkgo\Camt\DTO; |
8
|
|
|
use SimpleXMLElement; |
9
|
|
|
use DateTimeImmutable; |
10
|
|
|
use Genkgo\Camt\Iban; |
11
|
|
|
|
12
|
|
|
class Message extends BaseMessageDecoder |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @param DTO\Message $message |
16
|
|
|
* @param SimpleXMLElement $document |
17
|
|
|
*/ |
18
|
11 |
|
public function addRecords(DTO\Message $message, SimpleXMLElement $document) |
19
|
|
|
{ |
20
|
11 |
|
$statements = []; |
21
|
|
|
|
22
|
11 |
|
$xmlStatements = $this->getRootElement($document)->Stmt; |
|
|
|
|
23
|
11 |
|
foreach ($xmlStatements as $xmlStatement) { |
24
|
11 |
|
$statement = new Camt053DTO\Statement( |
25
|
11 |
|
(string) $xmlStatement->Id, |
26
|
11 |
|
new DateTimeImmutable((string)$xmlStatement->CreDtTm), |
27
|
11 |
|
$this->getAccount($xmlStatement) |
28
|
11 |
|
); |
29
|
|
|
|
30
|
11 |
|
if (isset($xmlStatement->StmtPgntn)) { |
31
|
6 |
|
$statement->setPagination(new DTO\Pagination( |
32
|
10 |
|
(string) $xmlStatement->StmtPgntn->PgNb, |
33
|
10 |
|
('true' === (string) $xmlStatement->StmtPgntn->LastPgInd) ? true : false |
34
|
10 |
|
)); |
35
|
6 |
|
} |
36
|
|
|
|
37
|
11 |
|
if (isset($xmlStatement->AddtlStmtInf)) { |
38
|
10 |
|
$statement->setAdditionalInformation((string) $xmlStatement->AddtlStmtInf); |
39
|
10 |
|
} |
40
|
|
|
|
41
|
11 |
|
$this->addCommonRecordInformation($statement, $xmlStatement); |
42
|
11 |
|
$this->recordDecoder->addBalances($statement, $xmlStatement); |
43
|
11 |
|
$this->recordDecoder->addEntries($statement, $xmlStatement); |
44
|
|
|
|
45
|
11 |
|
$statements[] = $statement; |
46
|
11 |
|
} |
47
|
|
|
|
48
|
11 |
|
$message->setRecords($statements); |
49
|
11 |
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritdoc} |
53
|
|
|
*/ |
54
|
12 |
|
public function getRootElement(SimpleXMLElement $document) |
55
|
|
|
{ |
56
|
12 |
|
return $document->BkToCstmrStmt; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param SimpleXMLElement $xmlRecord |
61
|
|
|
* |
62
|
|
|
* @return DTO\Account |
63
|
|
|
*/ |
64
|
11 |
|
protected function getAccount(SimpleXMLElement $xmlRecord) |
65
|
10 |
|
{ |
66
|
11 |
|
if (isset($xmlRecord->Acct->Id->IBAN)) { |
67
|
9 |
|
return new DTO\IbanAccount(new Iban((string) $xmlRecord->Acct->Id->IBAN)); |
68
|
10 |
|
} |
69
|
|
|
|
70
|
7 |
|
$xmlOtherIdentification = $xmlRecord->Acct->Id->Othr; |
71
|
9 |
|
$otherAccount = new DTO\OtherAccount((string) $xmlOtherIdentification->Id); |
72
|
|
|
|
73
|
7 |
|
if (isset($xmlOtherIdentification->SchmeNm)) { |
74
|
10 |
|
if (isset($xmlOtherIdentification->SchmeNm->Cd)) { |
75
|
10 |
|
$otherAccount->setSchemeName((string) $xmlOtherIdentification->SchmeNm->Cd); |
76
|
10 |
|
} |
77
|
|
|
|
78
|
10 |
|
if (isset($xmlOtherIdentification->SchmeNm->Prtry)) { |
79
|
|
|
$otherAccount->setSchemeName((string) $xmlOtherIdentification->SchmeNm->Prtry); |
80
|
10 |
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
7 |
|
if (isset($xmlOtherIdentification->Issr)) { |
84
|
|
|
$otherAccount->setIssuer($xmlOtherIdentification->Issr); |
85
|
|
|
} |
86
|
|
|
|
87
|
7 |
|
return $otherAccount; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
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.