Skip to content

Commit da89102

Browse files
authored
Merge pull request #514 from Philipp91/action-serialize
Make sure that all actions properly serialize their request-related fields
2 parents 29a57c9 + 4f82d00 commit da89102

13 files changed

+229
-25
lines changed

lib/Fhp/Action/GetBalance.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525
class GetBalance extends PaginateableAction
2626
{
27-
// Request (not available after serialization, i.e. not available in processResponse()).
27+
// Request (if you add a field here, update __serialize() and __unserialize() as well).
2828
/** @var SEPAAccount */
2929
private $account;
3030
/** @var bool */

lib/Fhp/Action/GetDepotAufstellung.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525
class GetDepotAufstellung extends PaginateableAction
2626
{
27-
// Request (not available after serialization, i.e. not available in processResponse()).
27+
// Request (if you add a field here, update __serialize() and __unserialize() as well).
2828
/** @var SEPAAccount */
2929
private $account;
3030

lib/Fhp/Action/GetSEPADirectDebitParameters.php

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@ class GetSEPADirectDebitParameters extends BaseAction
1616
public const SEQUENCE_TYPES = ['FRST', 'OOFF', 'FNAL', 'RCUR'];
1717
public const DIRECT_DEBIT_TYPES = ['CORE', 'COR1', 'B2B'];
1818

19+
// Request (if you add a field here, update __serialize() and __unserialize() as well).
1920
/** @var string */
2021
private $directDebitType;
21-
2222
/** @var string */
2323
private $seqType;
24-
2524
/** @var bool */
2625
private $singleDirectDebit;
2726

@@ -43,6 +42,45 @@ public static function create(string $seqType, bool $singleDirectDebit, string $
4342
return $result;
4443
}
4544

45+
/**
46+
* @deprecated Beginning from PHP7.4 __unserialize is used for new generated strings, then this method is only used for previously generated strings - remove after May 2023
47+
*/
48+
public function serialize(): string
49+
{
50+
return serialize($this->__serialize());
51+
}
52+
53+
public function __serialize(): array
54+
{
55+
return [
56+
parent::__serialize(),
57+
$this->directDebitType, $this->seqType, $this->singleDirectDebit,
58+
];
59+
}
60+
61+
/**
62+
* @deprecated Beginning from PHP7.4 __unserialize is used for new generated strings, then this method is only used for previously generated strings - remove after May 2023
63+
*
64+
* @param string $serialized
65+
* @return void
66+
*/
67+
public function unserialize($serialized)
68+
{
69+
self::__unserialize(unserialize($serialized));
70+
}
71+
72+
public function __unserialize(array $serialized): void
73+
{
74+
list(
75+
$parentSerialized,
76+
$this->directDebitType, $this->seqType, $this->singleDirectDebit,
77+
) = $serialized;
78+
79+
is_array($parentSerialized) ?
80+
parent::__unserialize($parentSerialized) :
81+
parent::unserialize($parentSerialized);
82+
}
83+
4684
public static function getHixxesSegmentName(string $directDebitType, bool $singleDirectDebit): string
4785
{
4886
switch ($directDebitType) {

lib/Fhp/Action/GetStatementOfAccount.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
*/
3232
class GetStatementOfAccount extends PaginateableAction
3333
{
34-
// Request (not available after serialization, i.e. not available in processResponse()).
34+
// Request (if you add a field here, update __serialize() and __unserialize() as well).
3535
/** @var SEPAAccount */
3636
private $account;
3737
/** @var \DateTime */
@@ -93,7 +93,7 @@ public function __serialize(): array
9393
{
9494
return [
9595
parent::__serialize(),
96-
$this->account, $this->from, $this->to, $this->allAccounts,
96+
$this->account, $this->from, $this->to, $this->allAccounts, $this->includeUnbooked,
9797
$this->bankName,
9898
];
9999
}
@@ -113,7 +113,7 @@ public function __unserialize(array $serialized): void
113113
{
114114
list(
115115
$parentSerialized,
116-
$this->account, $this->from, $this->to, $this->allAccounts,
116+
$this->account, $this->from, $this->to, $this->allAccounts, $this->includeUnbooked,
117117
$this->bankName,
118118
) = $serialized;
119119

lib/Fhp/Action/GetStatementOfAccountXML.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525
class GetStatementOfAccountXML extends PaginateableAction
2626
{
27-
// Request (not available after serialization, i.e. not available in processResponse()).
27+
// Request (if you add a field here, update __serialize() and __unserialize() as well).
2828
/** @var SEPAAccount */
2929
private $account;
3030
/** @var \DateTime */

lib/Fhp/Action/SendInternationalCreditTransfer.php

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@
1313

1414
class SendInternationalCreditTransfer extends BaseAction
1515
{
16+
// Request (if you add a field here, update __serialize() and __unserialize() as well).
1617
/** @var SEPAAccount */
1718
protected $account;
18-
1919
/** @var string */
2020
protected $dtavzData;
21-
2221
/** @var string|null */
2322
protected $dtavzVersion;
2423

@@ -36,6 +35,45 @@ public static function create(SEPAAccount $account, string $dtavzData, ?string $
3635
return $result;
3736
}
3837

38+
/**
39+
* @deprecated Beginning from PHP7.4 __unserialize is used for new generated strings, then this method is only used for previously generated strings - remove after May 2023
40+
*/
41+
public function serialize(): string
42+
{
43+
return serialize($this->__serialize());
44+
}
45+
46+
public function __serialize(): array
47+
{
48+
return [
49+
parent::__serialize(),
50+
$this->account, $this->dtavzData, $this->dtavzVersion,
51+
];
52+
}
53+
54+
/**
55+
* @deprecated Beginning from PHP7.4 __unserialize is used for new generated strings, then this method is only used for previously generated strings - remove after May 2023
56+
*
57+
* @param string $serialized
58+
* @return void
59+
*/
60+
public function unserialize($serialized)
61+
{
62+
self::__unserialize(unserialize($serialized));
63+
}
64+
65+
public function __unserialize(array $serialized): void
66+
{
67+
list(
68+
$parentSerialized,
69+
$this->account, $this->dtavzData, $this->dtavzVersion,
70+
) = $serialized;
71+
72+
is_array($parentSerialized) ?
73+
parent::__unserialize($parentSerialized) :
74+
parent::unserialize($parentSerialized);
75+
}
76+
3977
protected function createRequest(BPD $bpd, ?UPD $upd)
4078
{
4179
/** @var HIAUBSv9 $hiaubs */

lib/Fhp/Action/SendSEPADirectDebit.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,24 @@
2222
*/
2323
class SendSEPADirectDebit extends BaseAction
2424
{
25+
// Request (if you add a field here, update __serialize() and __unserialize() as well).
2526
/** @var SEPAAccount */
2627
protected $account;
27-
2828
/** @var string */
2929
protected $painMessage;
30-
3130
/** @var string */
3231
protected $painNamespace;
33-
3432
/** @var float */
3533
protected $ctrlSum;
36-
3734
/** @var bool */
3835
protected $singleDirectDebit = false;
39-
4036
/** @var bool */
4137
protected $tryToUseControlSumForSingleTransactions = false;
42-
4338
/** @var string */
4439
private $coreType;
4540

41+
// There are no result fields. This action is simply marked as done to indicate that the transfer was executed.
42+
4643
public static function create(SEPAAccount $account, string $painMessage, bool $tryToUseControlSumForSingleTransactions = false): SendSEPADirectDebit
4744
{
4845
if (preg_match('/xmlns="(?<namespace>[^"]+)"/s', $painMessage, $matches) === 1) {

lib/Fhp/Action/SendSEPARealtimeTransfer.php

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,17 @@
2323
*/
2424
class SendSEPARealtimeTransfer extends BaseAction
2525
{
26+
// Request (if you add a field here, update __serialize() and __unserialize() as well).
2627
/** @var SEPAAccount */
2728
private $account;
2829
/** @var string */
2930
private $painMessage;
3031
/** @var string */
3132
private $xmlSchema;
32-
3333
private bool $allowConversionToSEPATransfer = true;
3434

35+
// There are no result fields. This action is simply marked as done to indicate that the transfer was executed.
36+
3537
/**
3638
* @param SEPAAccount $account The account from which the transfer will be sent.
3739
* @param string $painMessage An XML-formatted ISO 20022 message. You may want to use github.com/nemiah/phpSepaXml
@@ -52,6 +54,45 @@ public static function create(SEPAAccount $account, string $painMessage, bool $a
5254
return $result;
5355
}
5456

57+
/**
58+
* @deprecated Beginning from PHP7.4 __unserialize is used for new generated strings, then this method is only used for previously generated strings - remove after May 2023
59+
*/
60+
public function serialize(): string
61+
{
62+
return serialize($this->__serialize());
63+
}
64+
65+
public function __serialize(): array
66+
{
67+
return [
68+
parent::__serialize(),
69+
$this->account, $this->painMessage, $this->xmlSchema, $this->allowConversionToSEPATransfer,
70+
];
71+
}
72+
73+
/**
74+
* @deprecated Beginning from PHP7.4 __unserialize is used for new generated strings, then this method is only used for previously generated strings - remove after May 2023
75+
*
76+
* @param string $serialized
77+
* @return void
78+
*/
79+
public function unserialize($serialized)
80+
{
81+
self::__unserialize(unserialize($serialized));
82+
}
83+
84+
public function __unserialize(array $serialized): void
85+
{
86+
list(
87+
$parentSerialized,
88+
$this->account, $this->painMessage, $this->xmlSchema, $this->allowConversionToSEPATransfer,
89+
) = $serialized;
90+
91+
is_array($parentSerialized) ?
92+
parent::__unserialize($parentSerialized) :
93+
parent::unserialize($parentSerialized);
94+
}
95+
5596
protected function createRequest(BPD $bpd, ?UPD $upd)
5697
{
5798
/** @var HIIPZSv1|HIIPZSv2 $hiipzs */

lib/Fhp/Action/SendSEPATransfer.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@
1919
*/
2020
class SendSEPATransfer extends BaseAction
2121
{
22+
// Request (if you add a field here, update __serialize() and __unserialize() as well).
2223
/** @var SEPAAccount */
2324
private $account;
2425
/** @var string */
2526
private $painMessage;
2627
/** @var string */
2728
private $xmlSchema;
2829

30+
// There are no result fields. This action is simply marked as done to indicate that the transfer was executed.
31+
2932
/**
3033
* @param SEPAAccount $account The account from which the transfer will be sent.
3134
* @param string $painMessage An XML-formatted ISO 20022 message. You may want to use github.com/nemiah/phpSepaXml
@@ -44,6 +47,45 @@ public static function create(SEPAAccount $account, string $painMessage): SendSE
4447
return $result;
4548
}
4649

50+
/**
51+
* @deprecated Beginning from PHP7.4 __unserialize is used for new generated strings, then this method is only used for previously generated strings - remove after May 2023
52+
*/
53+
public function serialize(): string
54+
{
55+
return serialize($this->__serialize());
56+
}
57+
58+
public function __serialize(): array
59+
{
60+
return [
61+
parent::__serialize(),
62+
$this->account, $this->painMessage, $this->xmlSchema,
63+
];
64+
}
65+
66+
/**
67+
* @deprecated Beginning from PHP7.4 __unserialize is used for new generated strings, then this method is only used for previously generated strings - remove after May 2023
68+
*
69+
* @param string $serialized
70+
* @return void
71+
*/
72+
public function unserialize($serialized)
73+
{
74+
self::__unserialize(unserialize($serialized));
75+
}
76+
77+
public function __unserialize(array $serialized): void
78+
{
79+
list(
80+
$parentSerialized,
81+
$this->account, $this->painMessage, $this->xmlSchema,
82+
) = $serialized;
83+
84+
is_array($parentSerialized) ?
85+
parent::__unserialize($parentSerialized) :
86+
parent::unserialize($parentSerialized);
87+
}
88+
4789
protected function createRequest(BPD $bpd, ?UPD $upd)
4890
{
4991
// ANALYSE XML FOR RECEIPTS AND PAYMENT DATE

lib/Fhp/Protocol/Message.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,7 @@ public function findRueckmeldungen(int $code): array
222222
*/
223223
public function serialize(): string
224224
{
225-
$result = '';
226-
foreach ($this->wrapperSegments as $segment) {
227-
$result .= Serializer::serializeSegment($segment);
228-
}
229-
return $result;
225+
return Serializer::serializeSegments($this->wrapperSegments);
230226
}
231227

232228
/**
@@ -353,7 +349,7 @@ public static function parse(string $rawMessage): Message
353349
* @param int $segmentNumber The number for the *first* segment, subsequent segment get the subsequent integers.
354350
* @return BaseSegment[] The same array, for chaining.
355351
*/
356-
private static function setSegmentNumbers(array $segments, int $segmentNumber): array
352+
public static function setSegmentNumbers(array $segments, int $segmentNumber): array
357353
{
358354
foreach ($segments as $segment) {
359355
$segment->segmentkopf->segmentnummer = $segmentNumber;

0 commit comments

Comments
 (0)