22
33namespace EbicsApi \Ebics ;
44
5+ use DateTimeInterface ;
56use EbicsApi \Ebics \Contexts \BTDContext ;
67use EbicsApi \Ebics \Contexts \BTUContext ;
78use EbicsApi \Ebics \Contexts \FDLContext ;
5152use EbicsApi \Ebics \Models \UploadTransaction ;
5253use EbicsApi \Ebics \Models \User ;
5354use EbicsApi \Ebics \Models \X509 \ContentX509Generator ;
55+ use EbicsApi \Ebics \Services \BufferFactory ;
5456use EbicsApi \Ebics \Services \CryptService ;
5557use EbicsApi \Ebics \Services \CurlHttpClient ;
5658use EbicsApi \Ebics \Services \XmlService ;
5759use EbicsApi \Ebics \Services \ZipService ;
58- use DateTimeInterface ;
5960use LogicException ;
6061
6162/**
@@ -81,45 +82,64 @@ final class EbicsClient implements EbicsClientInterface
8182 private HttpClientInterface $ httpClient ;
8283 private TransactionFactory $ transactionFactory ;
8384 private SegmentFactory $ segmentFactory ;
85+ private BufferFactory $ bufferFactory ;
8486
8587 /**
8688 * Constructor.
8789 *
8890 * @param Bank $bank
8991 * @param User $user
9092 * @param Keyring $keyring
93+ * @param array $options
9194 */
92- public function __construct (Bank $ bank , User $ user , Keyring $ keyring )
95+ public function __construct (Bank $ bank , User $ user , Keyring $ keyring, array $ options = [] )
9396 {
9497 $ this ->bank = $ bank ;
9598 $ this ->user = $ user ;
9699 $ this ->keyring = $ keyring ;
97100
101+ $ this ->segmentFactory = new SegmentFactory ();
102+ $ this ->cryptService = new CryptService ();
103+ $ this ->zipService = new ZipService ();
104+ $ this ->bufferFactory = new BufferFactory ($ options ['buffer_filename ' ] ?? 'php://memory ' );
105+
98106 if (Keyring::VERSION_24 === $ keyring ->getVersion ()) {
99107 $ this ->requestFactory = new RequestFactoryV24 ($ bank , $ user , $ keyring );
100108 $ this ->orderDataHandler = new OrderDataHandlerV24 ($ user , $ keyring );
101- $ this ->responseHandler = new ResponseHandlerV24 ();
109+ $ this ->responseHandler = new ResponseHandlerV24 (
110+ $ this ->segmentFactory ,
111+ $ this ->cryptService ,
112+ $ this ->zipService ,
113+ $ this ->bufferFactory
114+ );
102115 } elseif (Keyring::VERSION_25 === $ keyring ->getVersion ()) {
103116 $ this ->requestFactory = new RequestFactoryV25 ($ bank , $ user , $ keyring );
104117 $ this ->orderDataHandler = new OrderDataHandlerV25 ($ user , $ keyring );
105- $ this ->responseHandler = new ResponseHandlerV25 ();
118+ $ this ->responseHandler = new ResponseHandlerV25 (
119+ $ this ->segmentFactory ,
120+ $ this ->cryptService ,
121+ $ this ->zipService ,
122+ $ this ->bufferFactory
123+ );
106124 } elseif (Keyring::VERSION_30 === $ keyring ->getVersion ()) {
107125 $ this ->requestFactory = new RequestFactoryV3 ($ bank , $ user , $ keyring );
108126 $ this ->orderDataHandler = new OrderDataHandlerV3 ($ user , $ keyring );
109- $ this ->responseHandler = new ResponseHandlerV3 ();
127+ $ this ->responseHandler = new ResponseHandlerV3 (
128+ $ this ->segmentFactory ,
129+ $ this ->cryptService ,
130+ $ this ->zipService ,
131+ $ this ->bufferFactory
132+ );
110133 } else {
111134 throw new LogicException (sprintf ('Version "%s" is not implemented ' , $ keyring ->getVersion ()));
112135 }
113136
114- $ this ->cryptService = new CryptService ();
115137 $ this ->xmlService = new XmlService ();
116- $ this ->zipService = new ZipService ();
117138 $ this ->signatureFactory = new SignatureFactory ();
118139 $ this ->documentFactory = new DocumentFactory ();
119140 $ this ->orderResultFactory = new OrderResultFactory ();
120141 $ this ->transactionFactory = new TransactionFactory ();
121- $ this ->segmentFactory = new SegmentFactory ();
122- $ this ->httpClient = new CurlHttpClient ();
142+ $ this ->httpClient = $ options ['http_client ' ] ?? new CurlHttpClient ();
123143 }
124144
125145 /**
@@ -1065,19 +1085,35 @@ private function downloadTransaction(callable $requestClosure, callable $ackClos
10651085
10661086 $ this ->transferReceipt ($ transaction , $ acknowledged );
10671087
1068- $ orderDataEncrypted = '' ;
1088+ $ orderDataEncoded = $ this -> bufferFactory -> create () ;
10691089 foreach ($ transaction ->getSegments () as $ segment ) {
1070- $ orderDataEncrypted .= $ segment ->getOrderData ();
1090+ $ orderDataEncoded ->write ($ segment ->getOrderData ());
1091+ $ segment ->setOrderData ('' );
1092+ }
1093+ $ orderDataEncoded ->rewind ();
1094+
1095+ $ orderDataDecoded = $ this ->bufferFactory ->create ();
1096+ while (!$ orderDataEncoded ->eof ()) {
1097+ $ orderDataDecoded ->write (base64_decode ($ orderDataEncoded ->read ()));
10711098 }
1099+ $ orderDataDecoded ->rewind ();
1100+ unset($ orderDataEncoded );
10721101
1073- $ orderDataCompressed = $ this ->cryptService ->decryptOrderDataCompressed (
1102+ $ orderDataCompressed = $ this ->bufferFactory ->create ();
1103+ $ this ->cryptService ->decryptOrderDataCompressed (
10741104 $ this ->keyring ,
1075- $ orderDataEncrypted ,
1105+ $ orderDataDecoded ,
1106+ $ orderDataCompressed ,
10761107 $ lastSegment ->getTransactionKey ()
10771108 );
1078- $ orderData = $ this -> zipService -> uncompress ( $ orderDataCompressed );
1109+ unset( $ orderDataDecoded );
10791110
1080- $ transaction ->setOrderData ($ orderData );
1111+ $ orderData = $ this ->bufferFactory ->create ();
1112+ $ this ->zipService ->uncompress ($ orderDataCompressed , $ orderData );
1113+ unset($ orderDataCompressed );
1114+
1115+ $ transaction ->setOrderData ($ orderData ->readContent ());
1116+ unset($ orderData );
10811117
10821118 return $ transaction ;
10831119 }
@@ -1271,14 +1307,6 @@ public function getUser(): User
12711307 return $ this ->user ;
12721308 }
12731309
1274- /**
1275- * @inheritDoc
1276- */
1277- public function setHttpClient (HttpClientInterface $ httpClient ): void
1278- {
1279- $ this ->httpClient = $ httpClient ;
1280- }
1281-
12821310 /**
12831311 * Get user signature.
12841312 *
0 commit comments