Skip to content

Commit 8461bad

Browse files
committed
Support large files upload.
1 parent 9c8cc0f commit 8461bad

File tree

8 files changed

+68
-71
lines changed

8 files changed

+68
-71
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## 3.0
22

3+
* Support large files upload.
34
* Updated custom keyring details.
45
* Dynamic Orders.
56
* Updated EDS logic.

src/EbicsClient.php

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
use EbicsApi\Ebics\Models\Crypt\KeyPair;
3838
use EbicsApi\Ebics\Models\DownloadSegment;
3939
use EbicsApi\Ebics\Models\DownloadTransaction;
40+
use EbicsApi\Ebics\Models\EmptyOrderData;
4041
use EbicsApi\Ebics\Models\Http\Request;
4142
use EbicsApi\Ebics\Models\Http\Response;
4243
use EbicsApi\Ebics\Models\InitializationSegment;
@@ -222,9 +223,16 @@ function (UploadTransaction $transaction) use ($order) {
222223
$order->setTransaction($transaction);
223224
$orderData = $order->getOrderData();
224225
$this->schemaValidator->validate($orderData);
225-
$transaction->setOrderData($orderData->getContent());
226-
$transaction->setNumSegments($orderData->getContent() == ' ' ? 0 : 1);
227-
$transaction->setDigest($this->cryptService->hash($transaction->getOrderData()));
226+
227+
if ($orderData->getContent() === EmptyOrderData::CONTENT) {
228+
$transaction->setOrderData([$orderData->getContent()]);
229+
$transaction->setNumSegments(0);
230+
} else {
231+
$orderDataChunks = str_split($orderData->getContent(), UploadTransaction::CHUNK_SIZE);
232+
$transaction->setOrderData($orderDataChunks);
233+
$transaction->setNumSegments(count($orderDataChunks));
234+
}
235+
$transaction->setDigest($this->cryptService->hash($orderData->getContent()));
228236

229237
return $order->createRequest();
230238
}
@@ -482,21 +490,23 @@ private function uploadTransaction(callable $requestClosure): UploadTransaction
482490
$uploadSegment = $this->responseHandler->extractUploadSegment($request, $response);
483491
$transaction->setInitialization($uploadSegment);
484492

485-
// Segments can be many but requires realization of buffering.
486-
if ($transaction->getNumSegments() === 1) {
487-
$segment = $this->segmentFactory->createTransferSegment();
488-
$segment->setTransactionKey($transaction->getKey());
489-
$segment->setSegmentNumber(1);
490-
$segment->setIsLastSegment(true);
491-
$segment->setNumSegments($transaction->getNumSegments());
492-
$segment->setOrderData($transaction->getOrderData());
493-
$segment->setTransactionId($transaction->getInitialization()->getTransactionId());
494-
495-
if ($segment->getTransactionId()) {
496-
$transaction->addSegment($segment);
497-
$transaction->setKey($segment->getTransactionId());
498-
$this->transferTransfer($transaction);
493+
if ($transaction->getNumSegments() > 0) {
494+
foreach ($transaction->getOrderData() as $orderDataChunkId => $orderDataChunk) {
495+
$segment = $this->segmentFactory->createTransferSegment();
496+
$segment->setTransactionKey($transaction->getKey());
497+
$segment->setSegmentNumber($orderDataChunkId + 1);
498+
$segment->setIsLastSegment($segment->getSegmentNumber() === $transaction->getNumSegments());
499+
$segment->setOrderData($orderDataChunk);
500+
501+
$segment->setNumSegments($transaction->getNumSegments());
502+
$segment->setTransactionId($transaction->getInitialization()->getTransactionId());
503+
504+
if ($segment->getTransactionId()) {
505+
$transaction->addSegment($segment);
506+
}
499507
}
508+
509+
$this->transferTransfer($transaction);
500510
}
501511

502512
return $transaction;

src/Models/EmptyOrderData.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
*/
1313
final class EmptyOrderData extends DOMDocument implements OrderDataInterface
1414
{
15+
public const CONTENT = ' ';
16+
1517
public function getContent(): string
1618
{
17-
return ' ';
19+
return self::CONTENT;
1820
}
1921

2022
public function getFormattedContent(): string
2123
{
22-
return ' ';
24+
return self::CONTENT;
2325
}
2426
}

src/Models/UploadTransaction.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@
1212
*/
1313
final class UploadTransaction extends Transaction implements UploadTransactionInterface
1414
{
15+
public const CHUNK_SIZE = 1048576; // 1MB
16+
1517
private string $key;
1618
private int $numSegments;
1719
private array $segments;
18-
private string $orderData;
20+
/**
21+
* @var string[]
22+
*/
23+
private array $orderData;
1924
private string $digest;
2025
private UploadSegment $initialization;
2126

@@ -61,12 +66,19 @@ public function getLastSegment(): ?TransferSegment
6166
return end($this->segments);
6267
}
6368

64-
public function setOrderData(string $orderData): void
69+
/**
70+
* @param string[] $orderData
71+
* @return void
72+
*/
73+
public function setOrderData(array $orderData): void
6574
{
6675
$this->orderData = $orderData;
6776
}
6877

69-
public function getOrderData(): ?string
78+
/**
79+
* @return string[]
80+
*/
81+
public function getOrderData(): array
7082
{
7183
return $this->orderData;
7284
}

tests/EbicsClientV25Test.php

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -565,34 +565,6 @@ public function testFUL(int $credentialsId, array $codes)
565565
public function serversDataProvider()
566566
{
567567
return [
568-
[
569-
1, // Credentials Id.
570-
[
571-
'HEV' => ['code' => null, 'fake' => false],
572-
'INI' => ['code' => null, 'fake' => false],
573-
'HIA' => ['code' => null, 'fake' => false],
574-
'H3K' => ['code' => null, 'fake' => false],
575-
'HCS' => ['code' => null, 'fake' => false],
576-
'HPB' => ['code' => null, 'fake' => false],
577-
'SPR' => ['code' => null, 'fake' => true],
578-
'HPD' => ['code' => null, 'fake' => false],
579-
'HKD' => ['code' => null, 'fake' => false],
580-
'HTD' => ['code' => null, 'fake' => false],
581-
'HAA' => ['code' => null, 'fake' => false],
582-
'PTK' => ['code' => null, 'fake' => false],
583-
'HAC' => ['code' => null, 'fake' => false],
584-
'FDL' => [
585-
'camt.xxx.cfonb120.stm' => ['code' => '091112', 'fake' => false],
586-
],
587-
'FUL' => [
588-
'pain.001.001.03.sct' => [
589-
'code' => '091112',
590-
'fake' => false,
591-
'document' => '<?xml version="1.0" encoding="UTF-8"?><Root></Root>',
592-
],
593-
],
594-
],
595-
],
596568
[
597569
2, // Credentials Id.
598570
[

tests/EbicsClientV30Test.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public function testHEV(int $credentialsId, array $codes): void
157157
* @dataProvider serversDataProvider
158158
*
159159
* @group INI
160-
* @group INI-V30
160+
* @group INI-V3
161161
*
162162
* @param int $credentialsId
163163
* @param array $codes
@@ -202,7 +202,7 @@ public function testINI(int $credentialsId, array $codes): void
202202
* @dataProvider serversDataProvider
203203
*
204204
* @group HIA
205-
* @group HIA-V30
205+
* @group HIA-V3
206206
*
207207
* @param int $credentialsId
208208
* @param array $codes
@@ -674,24 +674,24 @@ public function serversDataProvider()
674674
'HAC' => ['code' => null, 'fake' => false],
675675
],
676676
],
677-
[
678-
7, // Credentials Id.
679-
[
680-
'HEV' => ['code' => null, 'fake' => false],
681-
'INI' => ['code' => null, 'fake' => false],
682-
'HIA' => ['code' => null, 'fake' => false],
683-
'SPR' => ['code' => null, 'fake' => true],
684-
'HPB' => ['code' => null, 'fake' => false],
685-
'HKD' => ['code' => null, 'fake' => false],
686-
'BTD' => ['code' => '090005', 'fake' => false],
687-
'BTU' => ['code' => null, 'fake' => false],
688-
'CSV' => ['code' => '091005', 'fake' => false],
689-
'HPD' => ['code' => null, 'fake' => false],
690-
'HAA' => ['code' => null, 'fake' => false],
691-
'PTK' => ['code' => null, 'fake' => false],
692-
'HAC' => ['code' => null, 'fake' => false],
693-
],
694-
],
677+
// [
678+
// 7, // Credentials Id.
679+
// [
680+
// 'HEV' => ['code' => null, 'fake' => false],
681+
// 'INI' => ['code' => null, 'fake' => false],
682+
// 'HIA' => ['code' => null, 'fake' => false],
683+
// 'SPR' => ['code' => null, 'fake' => true],
684+
// 'HPB' => ['code' => null, 'fake' => false],
685+
// 'HKD' => ['code' => null, 'fake' => false],
686+
// 'BTD' => ['code' => '090005', 'fake' => false],
687+
// 'BTU' => ['code' => null, 'fake' => false],
688+
// 'CSV' => ['code' => '091005', 'fake' => false],
689+
// 'HPD' => ['code' => null, 'fake' => false],
690+
// 'HAA' => ['code' => null, 'fake' => false],
691+
// 'PTK' => ['code' => null, 'fake' => false],
692+
// 'HAC' => ['code' => null, 'fake' => false],
693+
// ],
694+
// ],
695695
];
696696
}
697697
}

tests/Handlers/AuthSignatureHandlerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class AuthSignatureHandlerTest extends AbstractEbicsTestCase
3535
public function setUp(): void
3636
{
3737
parent::setUp();
38-
$credentialsId = 1;
38+
$credentialsId = 2;
3939
$client = $this->setupClientV25($credentialsId);
4040
$this->setupKeys($client->getKeyring());
4141

tests/_data.zip

132 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)