Skip to content

Commit ca3350e

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

File tree

9 files changed

+57
-57
lines changed

9 files changed

+57
-57
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.

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ebics-api/ebics-client-php",
3-
"version": "3.0.1",
3+
"version": "3.0.2",
44
"type": "library",
55
"description": "PHP library to communicate with bank through EBICS protocol.",
66
"keywords": [
@@ -35,11 +35,11 @@
3535
"require-dev": {
3636
"ebics-api/cfonb-php": "^1.0",
3737
"ebics-api/mt942-php": "^1.0",
38-
"phpseclib/phpseclib": "~2.0.48",
38+
"phpseclib/phpseclib": "~2.0.49",
3939
"phpstan/phpstan": "~1.9.18",
40-
"phpunit/phpunit": "~9.6.24",
40+
"phpunit/phpunit": "~9.6.29",
4141
"psr/http-client": "^1.0",
42-
"psr/http-factory": "^1.0",
42+
"psr/http-factory": "^1.1",
4343
"setasign/fpdf": "^1.8",
4444
"squizlabs/php_codesniffer": "~3.7.2"
4545
},

src/EbicsClient.php

Lines changed: 30 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,19 @@ 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 = [];
232+
for ($i = 0; $i < strlen($orderData->getContent()); $i += UploadTransaction::CHUNK_SIZE) {
233+
$orderDataChunks[] = substr($orderData->getContent(), $i, UploadTransaction::CHUNK_SIZE);
234+
}
235+
$transaction->setOrderData($orderDataChunks);
236+
$transaction->setNumSegments(count($orderDataChunks));
237+
}
238+
$transaction->setDigest($this->cryptService->hash($orderData->getContent()));
228239

229240
return $order->createRequest();
230241
}
@@ -482,21 +493,23 @@ private function uploadTransaction(callable $requestClosure): UploadTransaction
482493
$uploadSegment = $this->responseHandler->extractUploadSegment($request, $response);
483494
$transaction->setInitialization($uploadSegment);
484495

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);
496+
if ($transaction->getNumSegments() > 0) {
497+
foreach ($transaction->getOrderData() as $orderDataChunkId => $orderDataChunk) {
498+
$segment = $this->segmentFactory->createTransferSegment();
499+
$segment->setTransactionKey($transaction->getKey());
500+
$segment->setSegmentNumber($orderDataChunkId + 1);
501+
$segment->setIsLastSegment($segment->getSegmentNumber() === $transaction->getNumSegments());
502+
$segment->setOrderData($orderDataChunk);
503+
504+
$segment->setNumSegments($transaction->getNumSegments());
505+
$segment->setTransactionId($transaction->getInitialization()->getTransactionId());
506+
507+
if ($segment->getTransactionId()) {
508+
$transaction->addSegment($segment);
509+
}
499510
}
511+
512+
$this->transferTransfer($transaction);
500513
}
501514

502515
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: 2 additions & 2 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

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)